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

# Sessions

> Group related traces into sessions for multi-turn conversations and workflows

Set a **Session ID** to group traces together — all turns in a conversation, or all steps in a multi-agent workflow.

<Frame>
  <img src="https://mintcdn.com/tracerootai/4zVNm0JX6EXIYr5i/images/session_v1.png?fit=max&auto=format&n=4zVNm0JX6EXIYr5i&q=85&s=e8656883e85468130a133e97c02575f3" alt="TraceRoot dashboard showing traces grouped by session" width="3456" height="1848" data-path="images/session_v1.png" />
</Frame>

## Using `using_attributes` / `usingAttributes`

Propagate a Session ID to all traces within a block:

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from traceroot import using_attributes

    with using_attributes(session_id="chat-abc-123"):
        response_1 = agent.run("What's the weather in SF?")
        response_2 = agent.run("What about tomorrow?")
    ```

    Combine with a User ID to get full context on every trace:

    ```python theme={null}
    with using_attributes(session_id="chat-abc-123", user_id="user-42"):
        agent.run(query)
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    import { usingAttributes } from '@traceroot-ai/traceroot';

    await usingAttributes({ sessionId: 'chat-abc-123' }, async () => {
      await agent.run("What's the weather in SF?");
      await agent.run('What about tomorrow?');
    });
    ```

    Combine with a User ID to get full context on every trace:

    ```typescript theme={null}
    await usingAttributes({ sessionId: 'chat-abc-123', userId: 'user-42' }, async () => {
      await agent.run(query);
    });
    ```
  </Tab>
</Tabs>

## Using `observe` / inside a function

Call `update_current_trace` / `updateCurrentTrace` from within any observed function:

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from traceroot import observe, update_current_trace

    @observe(name="handle_request", type="agent")
    def handle_request(query: str, session_id: str):
        update_current_trace(session_id=session_id)
        return process(query)
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    import { observe, updateCurrentTrace } from '@traceroot-ai/traceroot';

    async function handleRequest(query: string, sessionId: string) {
      return observe({ name: 'handle_request', type: 'agent' }, async () => {
        updateCurrentTrace({ sessionId });
        return process(query);
      });
    }
    ```
  </Tab>
</Tabs>
