Why it matters
Sessions are what makes agents remember within a conversation. Understanding backends and lifecycle shapes production deployments.
Advertisement
The architecture
Session: id + app_name + user_id + state + events.
State: dict for custom data. Written by agents, read by future turns.
Advertisement
How it works end to end
InMemorySessionService: dev only. State lost on restart.
VertexAiSessionService: managed persistence. Scales, survives restarts.
Database backends: DatabaseSessionService for custom SQL backends.
Access: agents read/write state via ToolContext.state.