A session ID associates multiple agent.run() invocations with one persistent interaction session. Reusing it preserves conversation context; omitting it or changing it starts an independent conversation. section 6.3.4 section 6.1.2
Use session IDs to control how agent state is loaded and retained:
- Provide the same ID on successive calls to retrieve the existing Session and expose prior events through ExecutionContext. section 6.3.4 section 6.3.3
- Use different IDs, or no ID, when each invocation should be independent, such as a one-off benchmark task. section 6.3.4
- Persist sessions beyond process memory for stateless web services; InMemorySessionManager suits testing and single-process applications. section 6.3.4 section 6.1.2
- Keep session continuity separate from persistent knowledge, which shares selected information across different session IDs. section 6.1.2
Continuing a conversation
result1 = await agent.run("My name is Alice", session_id="session_1") result2 = await agent.run("What's my name?", session_id="session_1") The second invocation retrieves the first invocation's session events, allowing the agent to answer that the user's name is Alice. section 6.3
Figure 6.2 Without a session (left), each run() creates a new ExecutionContext that’s discarded after completion. With a session (right), multiple run() calls share the session, maintaining conversation continuity.
Compare independent ExecutionContext instances with multiple run() calls sharing one session and maintaining conversation continuity. section 6.1.2


