Context / Client / put_trace
put_trace¶
- Context.Client.put_trace(**kwargs)¶
Submits an agent’s execution traces so that AWS Context can extract reusable knowledge and skills from them. Call it when an agent finishes a task or session that is worth learning from. In
agentContextArns, name the agent contexts that the traces are about. AWS Context analyzes the traces for each of them.Each
traceDocumentsentry is one raw trace document in the trace schema thatformatselects. You can send 1–100 documents per call. Each document can be up to 5 MiB before encoding. If you use an AWS SDK, pass each document’s raw bytes. If you call PutTrace through the agent context’s MCP server or another JSON client, send each document as a base64-encoded string. To send a larger trace, split it across calls that share asessionId.sessionIdgroups related calls into one session. If you omit it, AWS Context generates one and returns it in the response so that you can reuse it.Each agent context can hold up to 100,000 trace documents. If a request would exceed this quota, it fails with
ServiceQuotaExceededException, and AWS Context stores no documents. If a request fails for any other reason, AWS Context might have stored some of its documents. To store the rest without duplicates, retry with the sameclientToken.See also: AWS API Documentation
Request Syntax
response = client.put_trace( sessionId='string', clientToken='string', format='OTEL'|'ANTHROPIC'|'BEDROCK_CONVERSE'|'KIRO', traceDocuments=[ b'bytes', ], agentContextArns=[ 'string', ], traceMetadata={ 'string': 'string' }, accessControlConfig={ 'accessControlList': [ { 'access': 'ALLOW'|'DENY', 'principalId': 'string', 'principalType': 'USER'|'GROUP' }, ] } )
- Parameters:
sessionId (string) – The agent session this trace belongs to and the grouping key: multiple PutTrace calls with the same
sessionIdare one session. Optional. If you omit it, the service generates one and returns it in the response. It is not thetraceId: an OTLP batch carries many trace_ids under one session.clientToken (string) –
Makes the call idempotent. A retry with the same token and the same request returns the same
sessionIdand does not write the traces again. Reusing the token fails withValidationExceptionif the request is different, or if another caller reuses it whenaccessControlConfignames no entries. A token is honored for 8 hours after its first use. WhenaccessControlConfignames no entries and the caller’s end user cannot be resolved at the time of the retry, the retry fails withValidationExceptioneven if the first attempt stored traces. To complete them, resend with explicit entries under a new token.This field is autopopulated if not provided.
format (string) –
[REQUIRED]
The format of the documents in
traceDocuments. Valid values:OTEL- OpenTelemetry traces in OTLP/JSON.ANTHROPIC- Claude Code session logs, one log line per document.BEDROCK_CONVERSE- Amazon Bedrock Converse messages, one message (roleandcontent) per document, in conversation order.KIRO- Kiro IDE or Kiro CLI session logs.
traceDocuments (list) –
[REQUIRED]
The raw trace documents, in the trace schema that
formatselects. You can send 1–100 documents per call, and each document can be up to 5 MiB (5,242,880 bytes) before encoding. If you use an AWS SDK, pass each document’s raw bytes. If you call PutTrace through the agent context’s MCP server or another JSON client, send each document as a base64-encoded string.(bytes) –
One raw trace document, up to 5 MiB (5,242,880 bytes) before encoding. Through the MCP server or another JSON client, send it as a base64-encoded string. If you use OpenTelemetry, split a large trace into multiple spans across
traceDocumentsand link them with your span metadata, instead of sending one oversized document.
agentContextArns (list) –
[REQUIRED]
The ARNs of the agent contexts that the traces are about: 1–10
agent-context/ARNs that name at most 5 distinct agent contexts, in this Region and partition, all in your account. If you name more, the request fails withValidationException. AWS Context authorizescontext:PutTraceonce for each agent context. If any authorization is denied, the whole call fails withAccessDeniedException, and nothing is stored. After authorization, if trace analysis is disabled for an agent context, the call fails withValidationException, and nothing is stored.(string) –
The Amazon Resource Name (ARN) of an agent context. The ARN has the following parts:
A partition:
aws,aws-cn, oraws-us-gov.A Region of up to 32 characters.
An account of exactly 12 digits.
The resource path
agent-context/.An ID of lowercase letters and digits in single-hyphen-separated runs.
This matches the public agent context ID format.
traceMetadata (dict) –
Client-supplied key-value pairs, stored with the traces as-is. The key
analysisModeis reserved. A request that sets it fails withAccessDeniedException.(string) –
(string) –
accessControlConfig (dict) –
The principals who can see the insights that AWS Context generates from the traces. If you provide entries, the caller is not included unless an entry names it.
If you provide no entries (
accessControlConfigabsent, oraccessControlListabsent or empty), only the end user that the caller’s trusted identity propagation session names can see the insights. If the session names no end user, or there is no session, the call fails withValidationExceptionand stores nothing. In that case, name the principals, or sendALLOWfor*so that every reader of the agent contexts can see the insights.An entry other than
*withoutprincipalType, aprincipalIdthat is not valid Unicode, or entries that total more than 65,536 bytes of UTF-8 are rejected withValidationException. AWS Context stores principal IDs as given and does not verify them against a directory. A session’s access control is the union of its traces’ entries. A call that would take that union over 100 entries, or over 65,536 bytes of UTF-8, fails withValidationExceptionand stores nothing.accessControlList (list) –
Entries, each allowing or denying one principal.
(dict) –
Allows or denies one end user or group, or every reader (
*).access (string) – [REQUIRED]
Specifies whether the principal can see the information.
Valid values:
ALLOW- Access is allowed.DENY- Access is denied.
principalId (string) – [REQUIRED]
The principal’s opaque user or group ID, or
*for every reader authorized on the resource.principalType (string) –
Specifies whether
principalIdnames a user or a group. Required unlessprincipalIdis*, where it is ignored.Valid values:
USER- An end user.GROUP- A group of end users.
- Return type:
dict
- Returns:
Response Syntax
{ 'sessionId': 'string' }
Response Structure
(dict) –
sessionId (string) –
The session ID for the traces: the
sessionIdthat you specified, or one that AWS Context generated if you omitted it. A successful response means that AWS Context stored every document. A failed call might leave some documents stored. To store the rest without duplicates, retry with the sameclientToken.
Exceptions