

# How trace analysis works

Trace analysis groups traces into sessions, analyzes sessions together, and evaluates what it learns before it proposes it.

## Sessions
<a name="feedback-sessions"></a>

A *session* is the set of traces that share a session ID, usually the traces of one conversation or task. Trace analysis reads the traces of a session together.

Grouping  
To put traces in one session, set the same `sessionId` on each request. Trace documents that share a session ID are analyzed together, even when you submit them in separate `PutTrace` requests. If you omit `sessionId` on a `PutTrace` request, AWS Context generates one and returns it in the response. On `AgenticRetrieve` requests, `sessionId` groups AWS Context agent traces in the same way (see [Continue a conversation](continue-a-conversation.md)).

Readers  
The requests of one session share one list of readers: the readers of every request in the session, combined. A learning carries the readers of the session that it came from (see [Who can see learnings from your traces](feedback-visibility.md)).

Ownership  
If you call through trusted identity propagation, a session belongs to the end user who makes the first call for its session ID. A later call for that session ID from another identity fails with `AccessDeniedException` and stores no traces.

A session can combine your agent’s own traces with the AWS Context agent traces of your agent’s `AgenticRetrieve` calls, when AWS Context records them (see [AWS Context agent traces](feedback-trace-sources.md#feedback-agentic-traces)). Set the same `sessionId` on those calls. Trace analysis then sees the full picture: what the user asked your agent, how the Context retrieval agent found the context, and what your agent did with the result.

Both calls must be made for the same end user (a trusted identity propagation session; see [End-user identity propagation](identity-propagation.md)). An AWS Context agent trace always belongs to an end user, so your `PutTrace` request must be made for that same user. If your agent calls without a user identity, the two sets of traces don’t join one session. AWS Context records no agent trace for such a call.

**Example: One session for your agent’s traces and its `AgenticRetrieve` calls**  
Suppose that your team built an inventory assistant. A sales analyst asks it, "How many units can we still sell from the Atlanta distribution center?" The assistant gives the conversation the session ID `inv-7f3a`. Every call is made for the analyst, through a trusted identity propagation session. Trace analysis is on for the Agent Context, and **Include AWS Context agent traces** is selected.

1. The assistant calls `AgenticRetrieve` on your Agent Context and sets `sessionId` to `inv-7f3a`. AWS Context records the retrieval agent’s trace in that session: the searches it ran, the tables it chose, and the query it wrote.

1. The assistant answers with the units on hand. The analyst corrects it: units that are reserved for open orders can’t be sold. The assistant calls `AgenticRetrieve` again with the same `sessionId`, subtracts the reserved units, and gives the right answer.

1. When the conversation ends, the assistant calls `PutTrace` with its own session log and the same `sessionId`, `inv-7f3a`.

Trace analysis reads both sets of traces as one session. The assistant’s trace shows that the first answer was wrong and how the analyst corrected it. The AWS Context agent traces show which retrieval steps led to each answer. Together, they support a learning that neither supports alone: a skill that defines units available to sell as units on hand minus reserved units.

## When an analysis runs
<a name="feedback-analysis-timing"></a>

Trace analysis learns from several sessions at a time, because knowledge that comes from only a few sessions might not generalize. Analysis starts after submitted traces come from at least 5 sessions.

Each analysis covers a batch of up to 100 sessions of an Agent Context. When a batch has traces from at least 5 sessions, its analysis can start one hour after the batch’s first trace arrived, or right away if that hour has already passed. When a batch reaches 100 sessions, its analysis can start right away, and later sessions go into the next batch.

If the analysis of a session fails, AWS Context doesn’t retry it, but a new trace in the session queues the session for analysis again.

## How trace analysis evaluates learnings
<a name="feedback-evaluation"></a>

 AWS Context evaluates the learnings that it extracts from your traces before it proposes them. To evaluate a learning, it runs retrieval on your Agent Context as the trace analysis role (see [Trace analysis role](trace-analysis-role.md)). Each skill that trace analysis proposes has a `verificationStatus` property that records the outcome:
+  **Evaluated and passed** – AWS Context proposes the learning, and its `verificationStatus` is `VERIFIED`.
+  **Couldn’t evaluate** – When AWS Context can’t evaluate a learning, it still proposes the learning, and the learning’s `verificationStatus` is `UNVERIFIED`. This happens, for example, when AWS Context can’t assume the trace analysis role, when the role can’t read a source that the evaluation needs, or when your traces don’t make the right answer clear.
+  **Evaluated and failed** – AWS Context doesn’t propose the learning. A learning fails when the evidence doesn’t support it: with the learning applied, retrieval gets a question from your traces wrong.