> ## Documentation Index
> Fetch the complete documentation index at: https://docs.braintrust.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Log AI-to-human handoffs with conversation_id

> Configure traces, Topics, and scorers to log AI-to-human handoffs and separate AI performance from end-to-end outcomes.

> [!NOTE]
>
> **Applies to:**
>
> * Plan - Any
> * Deployment - Any
> *
> * Use case - How to log and evaluate conversations that escalate from AI to human support and how to scope Topics and scorers to distinguish AI performance from overall conversation outcomes

## Summary

Recommend a single session root trace and attach each message as a child span. Tag spans with `metadata.sender` and `metadata.conversation_id`. Use the SDK’s span timing so `metrics.start` and `metrics.end` capture AI execution (separate from human wait time).

## What is happening

Keeping human turns as child spans under a session root gives a single UI view, simpler querying, and faster scoring because the system reads one trace. The platform also logs span creation times. Built-in duration, timeline, and latency derive from span `metrics.start` and `metrics.end`; arbitrary timestamps in `metadata.*` are ignored by those features.

## Fix or suggestion

### Recommended: Single session trace with child spans (preferred)

* Create one root trace per conversation (session). For each message turn (AI, human agent, customer, automation) create a child span on that root and set span attributes and metadata consistently.
* Tag each span with at least:
  * `metadata.conversation_id`: the shared grouping key used by Topics and group-scoped scorers.
  * `metadata.sender`: one of `ai`, `human_agent`, `customer`, `automation`, or `agent_assistant`.
  * Accurate timing via the SDK so span `metrics.start` and `metrics.end` reflect AI execution windows. If you also store extra timestamps in `metadata`, they are only used if a custom scorer reads them.
* Scope scorers:
  * AI-only evaluation: span- or trace-scoped scorers that filter spans where `metadata.sender == "ai"`; use span `metrics.start`/`metrics.end` for latency.
  * Overall outcome: group-scoped scorers on `metadata.conversation_id` to evaluate resolution, sentiment shift, and handoff behavior across the whole session.

Example root trace + spans (illustrative JSON):

```json theme={null}
{
  "trace_id": "root-abc-123",
  "metadata": {
    "conversation_id": "ticket-12345",
    "session_started_at": "2026-11-06T19:54:36Z"
  },
  "spans": [
    {
      "span_id": "span-1",
      "parent_id": "root-abc-123",
      "metadata": { "sender": "ai" },
      "metrics": {
        "start": "2026-11-06T19:54:36.120Z",
        "end":   "2026-11-06T19:54:36.420Z"
      },
      "body": "Assistant reply text..."
    },
    {
      "span_id": "span-2",
      "parent_id": "root-abc-123",
      "metadata": { "sender": "human_agent" },
      "metrics": {
        "start": "2026-11-06T20:01:15.000Z",
        "end":   "2026-11-06T20:02:10.000Z"
      },
      "body": "Agent reply text..."
    }
  ]
}
```

Notes on timing: built-in duration, timeline, and latency use span `metrics.start` and `metrics.end`. Fields like `metadata.start_time`, `metadata.end_time`, or `metadata.duration_ms` do not affect those features. Only custom scorers will use them if you explicitly read those fields.

### When to keep per-turn traces (alternative)

* Keep one trace per turn if you need very small, independent trace objects (e.g., external tracing constraints) or you prefer separating spans at ingestion time. Link those traces with `metadata.conversation_id` and use Topics group scope and trace-scoped filters for AI-only evaluation.

Tradeoffs

* Single-root-with-spans: cleaner UI, easier single-trace reads, and often faster scoring because the scorer reads one trace. It also makes it explicit which timestamps represent AI execution via span `metrics.start`/`metrics.end`.
* Per-turn traces: simpler to avoid long-lived root traces and sometimes simpler for streaming ingestion pipelines. Requires group-scoped aggregation and more reads for scorers that need many turns.

## How to confirm it worked

* The session trace shows the full conversation as a thread in the UI.
* AI-only scorers return results only for spans where `metadata.sender == "ai"` and use span `metrics.start`/`metrics.end` for latency metrics.
* Topics configured with the grouping key `metadata.conversation_id` summarize Task, Sentiment, and Issues across the grouped conversation.

## Notes

* If agents use an AI assistant, log assistant messages with a distinct `metadata.sender` (e.g., `agent_assistant`) so AI-only evaluations don’t double-count assistance provided during human replies.
* For near-real-time Topic updates, choose "Every trace in group". For a single summary after a session completes, choose "First trace in group" and configure its Idle time as needed.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.