Sessions
A session is a context manager that records everything an agent does during one run. Every tool call, every LLM response, every result — captured as a structured trace.
Session parameters
Lifecycle
- Enter —
with reagent_flow.session(...) as s: sets the session as the active context
- Record — tool calls and results are logged via
log_llm_call and log_tool_result
- Exit — the session finalizes the trace and saves it to disk
- Assert — after exiting, call assertion methods on the closed session
Assertions must be called after the with block exits — the trace is finalized at exit time. Calling assertions inside the block works but may miss the final turn.
Traces
A trace is the structured record of a session. It contains a list of turns, each with an LLM call and its resulting tool executions.
Storage
Traces are saved as JSON files:
- Regular traces:
{trace_dir}/{name}.trace.json
- Golden baselines:
{trace_dir}/golden/{name}.trace.json
Manual logging
When using framework adapters (OpenAI, LangChain, etc.), logging happens automatically. For manual instrumentation or testing:
Thread safety
Sessions use Python’s contextvars for thread-safe tracking. Each thread or async task sees its own active session — no global mutable state.