Skip to content

create_agentic_context async

create_agentic_context(
    name: AgenticContextName,
    context_type: AgenticContextType,
    target_file_path: AgenticContextTargetFilePath,
    *,
    config_overrides: Optional[AsyncWorkSpacesClientConfig] = None,
    client_token: Optional[IdempotencyToken] = None,
    description: Optional[AgenticContextDescription] = None,
    context_body: Optional[AgenticContextBody] = None,
    tags: Optional[TagList] = None,
) -> CreateAgenticContextResult

Creates an agentic context, which is Markdown content that the service writes to a file on the WorkSpace for the agent to use. The name must be unique among the contexts in your account. If it isn't, the operation returns ConflictException, and its ResourceId identifies the existing context. If the tags would exceed the limit of 50 tags per resource, the operation returns ServiceQuotaExceededException.

Parameters:

  • client_token (Optional[IdempotencyToken], default: None ) –

    A unique, case-sensitive identifier that you provide to ensure that the operation completes no more than one time. If this token matches a previous request with the same parameters, the service returns the result of that request and doesn't create another context.

    If you reuse the token with different parameters, the operation returns ValidationException. If you deleted the context created with this token, the operation returns ResourceNotFoundException.

  • name (AgenticContextName) –

    The name of the context.

  • description (Optional[AgenticContextDescription], default: None ) –

    The description of the context.

  • context_type (AgenticContextType) –

    The type of the context. Valid values:

    • STEERING – Guidance that shapes how the agent behaves.

    • SKILL – A reusable capability that the agent can use.

    • WORKFLOW – A multi-step procedure that the agent follows.

  • target_file_path (AgenticContextTargetFilePath) –

    The name of the Markdown file that the context is written to on the WorkSpace, for example code-review.md. This is a file name, not a path. It can contain letters, digits, periods (.), underscores (_), and hyphens (-), can be 1–255 characters long, and can't be . or ...

  • context_body (Optional[AgenticContextBody], default: None ) –

    The Markdown content of the context, up to 1 MiB of UTF-8 text. Currently, you must specify this field.

  • tags (Optional[TagList], default: None ) –

    The tags to add to the context. Each tag key can appear only once.

Raises:

  • AccessDeniedException –

    The user is not authorized to access a resource.

  • ConflictException –

    The request conflicts with the current state of a resource, for example because a name is already in use or the resource is still in use. Resolve the conflict, and then retry your request.

  • ResourceNotFoundException –

    The resource could not be found.

  • ServiceQuotaExceededException –

    The request would exceed a service quota. Request a quota increase or reduce the number of resources in your request.

  • ThrottlingException –

    The request was throttled. Retry the request with exponential backoff.

  • ValidationException –

    Your request failed validation. Check the error message for the parameter that isn't valid.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

Example – Creating a steering context The following example creates a steering context that agents read from the file coding-standards.md.

>>> await client.create_agentic_context(client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLE11111', name='coding-standards', description='Team coding standards for agents.', context_type='STEERING', target_file_path='coding-standards.md', context_body='# Coding standards\n\nWrite unit tests for every change.', tags=[{'Key': 'team', 'Value': 'platform'}])
Source code in docs_src/capo_workspaces/_services/async_work_spaces.py
async def create_agentic_context(
    self,
    name: "capo_workspaces.types.agentic_context_name.AgenticContextName",
    context_type: "capo_workspaces.types.agentic_context_type.AgenticContextType",
    target_file_path: "capo_workspaces.types.agentic_context_target_file_path.AgenticContextTargetFilePath",
    *,
    config_overrides: Optional[AsyncWorkSpacesClientConfig] = None,
    client_token: Optional[
        "capo_workspaces.types.idempotency_token.IdempotencyToken"
    ] = None,
    description: Optional[
        "capo_workspaces.types.agentic_context_description.AgenticContextDescription"
    ] = None,
    context_body: Optional[
        "capo_workspaces.types.agentic_context_body.AgenticContextBody"
    ] = None,
    tags: Optional["capo_workspaces.types.tag_list.TagList"] = None,
) -> (
    "capo_workspaces.types.create_agentic_context_result.CreateAgenticContextResult"
):
    r"""<p>Creates an agentic context, which is Markdown content that the service writes to a file on the WorkSpace for the agent to use. The name must be unique among the contexts in your account. If it isn't, the operation returns <code>ConflictException</code>, and its <code>ResourceId</code> identifies the existing context. If the tags would exceed the limit of 50 tags per resource, the operation returns <code>ServiceQuotaExceededException</code>.</p>

    Args:
        client_token: <p>A unique, case-sensitive identifier that you provide to ensure that the operation completes no more than one time. If this token matches a previous request with the same parameters, the service returns the result of that request and doesn't create another context.</p> <p>If you reuse the token with different parameters, the operation returns <code>ValidationException</code>. If you deleted the context created with this token, the operation returns <code>ResourceNotFoundException</code>.</p>
        name: <p>The name of the context.</p>
        description: <p>The description of the context.</p>
        context_type: <p>The type of the context. Valid values:</p> <ul> <li> <p> <code>STEERING</code> – Guidance that shapes how the agent behaves.</p> </li> <li> <p> <code>SKILL</code> – A reusable capability that the agent can use.</p> </li> <li> <p> <code>WORKFLOW</code> – A multi-step procedure that the agent follows.</p> </li> </ul>
        target_file_path: <p>The name of the Markdown file that the context is written to on the WorkSpace, for example <code>code-review.md</code>. This is a file name, not a path. It can contain letters, digits, periods (.), underscores (_), and hyphens (-), can be 1–255 characters long, and can't be <code>.</code> or <code>..</code>.</p>
        context_body: <p>The Markdown content of the context, up to 1 MiB of UTF-8 text. Currently, you must specify this field.</p>
        tags: <p>The tags to add to the context. Each tag key can appear only once.</p>

    Raises:
        capo_workspaces.errors.access_denied_exception.AccessDeniedException: <p>The user is not authorized to access a resource.</p>
        capo_workspaces.errors.conflict_exception.ConflictException: <p>The request conflicts with the current state of a resource, for example because a name is already in use or the resource is still in use. Resolve the conflict, and then retry your request.</p>
        capo_workspaces.errors.resource_not_found_exception.ResourceNotFoundException: <p>The resource could not be found.</p>
        capo_workspaces.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The request would exceed a service quota. Request a quota increase or reduce the number of resources in your request.</p>
        capo_workspaces.errors.throttling_exception.ThrottlingException: <p>The request was throttled. Retry the request with exponential backoff.</p>
        capo_workspaces.errors.validation_exception.ValidationException: <p>Your request failed validation. Check the error message for the parameter that isn't valid.</p>
        capo_workspaces.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        Example – Creating a steering context
        The following example creates a steering context that agents read from the file coding-standards.md.

        >>> await client.create_agentic_context(client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLE11111', name='coding-standards', description='Team coding standards for agents.', context_type='STEERING', target_file_path='coding-standards.md', context_body='# Coding standards\n\nWrite unit tests for every change.', tags=[{'Key': 'team', 'Value': 'platform'}])
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_workspaces.types.create_agentic_context_request.CreateAgenticContextRequest]",
    ) -> AsyncOperationResponse[
        "capo_workspaces.types.create_agentic_context_result.CreateAgenticContextResult"
    ]:
        if req.options.protocol == "awsJson1_1":
            import capo_workspaces._operations.workspaces_service.aws_json1_1.create_agentic_context

            (
                output,
                http_response,
            ) = await capo_workspaces._operations.workspaces_service.aws_json1_1.create_agentic_context.async_create_agentic_context(
                req.options, req.input
            )
        elif req.options.protocol == "rpcv2Cbor":
            import capo_workspaces._operations.workspaces_service.rpcv2_cbor.create_agentic_context

            (
                output,
                http_response,
            ) = await capo_workspaces._operations.workspaces_service.rpcv2_cbor.create_agentic_context.async_create_agentic_context(
                req.options, req.input
            )
        else:
            raise ValueError(f"unknown protocol {req.options.protocol!r}")
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_workspaces.types.create_agentic_context_request.CreateAgenticContextRequest",
    ) -> dict[str, Any]:
        import capo_workspaces.types.create_agentic_context_request

        return (
            capo_workspaces.types.create_agentic_context_request.redact_sensitive(
                input_
            )
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("CreateAgenticContext", redact_input=_redact_input),
    )
    input_: capo_workspaces.types.create_agentic_context_request.CreateAgenticContextRequest = {
        "name": name,
        "context_type": context_type,
        "target_file_path": target_file_path,
    }
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if description is not None:
        input_["description"] = description
    if context_body is not None:
        input_["context_body"] = context_body
    if tags is not None:
        input_["tags"] = tags

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output