Skip to main content
Runner is the main entry point for session-managed execution. It wires an agent, a session service, and the invocation context together.
from langchain_adk import Runner, InMemorySessionService

runner = Runner(
    agent=agent,
    app_name="my-app",
    session_service=InMemorySessionService(),
)

# Streaming is always on — partial events arrive as text is generated
async for event in runner.astream(
    user_id="user-1",
    session_id="session-abc",
    new_message="Hello!",
):
    if event.type == EventType.AGENT_MESSAGE and event.partial:
        print(event.text, end="", flush=True)
    elif event.is_final_response():
        print(f"\n{event.text}")
Runner automatically:
  1. Fetches or creates the session
  2. Persists the user’s message as a USER_MESSAGE event
  3. Builds an Context with the session reference
  4. Persists every agent event to the session via append_event()
  5. Applies EventActions.state_delta to the session state
Multi-turn conversations work automatically — LlmAgent rebuilds LangChain message history from session.events on each turn, so the LLM sees the full conversation context.

Using sessions directly

from langchain_adk import InMemorySessionService

svc = InMemorySessionService()
session = await svc.create_session(app_name="demo", user_id="user-1")

# All sessions for a user
sessions = await svc.list_sessions(app_name="demo", user_id="user-1")

# Delete
await svc.delete_session(session.id)
Implement BaseSessionService to back sessions with any database. See Architecture for an example.