You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sessions and context providers are the core building blocks for agent memory in the Agent Framework. Sessions hold conversation state across turns, while context providers add, retrieve, and persist context before and after each agent invocation.
Core Concepts
AgentSession: Lightweight state container holding a session_id and a mutable state dict. Pass to agent.run() to maintain conversation across turns.
BaseContextProvider: Hook that runs before_run / after_run around each invocation. Use for injecting instructions, RAG context, or metadata.
BaseHistoryProvider: Subclass of BaseContextProvider for conversation history storage. Implements get_messages() / save_messages() and handles load/store automatically.
InMemoryHistoryProvider: Built-in provider storing messages in session.state. Auto-injected when no providers are configured.
Build a custom BaseContextProvider that extracts and stores user information using structured output, then provides dynamic instructions based on stored context.