Expand description
Layered context traits for the behest agent runtime.
Inspired by ADK-Rust’s ReadonlyContext → CallbackContext → InvocationContext
hierarchy, this module defines progressively richer context interfaces that
give agents, tools, hooks, and memory operations access to exactly the
capabilities they need — no more, no less.
§Hierarchy
ReadonlyContext (identity: invocation_id, session_id, user_id, app_name)
├── SessionContext (+ session state, session store)
│ ├── RunContext (+ run_id, cancellation, deadline, event sink, budget)
│ │ └── ToolContext (+ tool_call, emit_progress, search_memory)
│ └── MemoryContext (+ active_window, demote, compact)
└── HookContext (+ current_state, snapshot)§Design constraints
- Each layer adds specific, well-defined capabilities.
- Context does not become a “global service locator” — each trait is narrowly scoped to what the consumer needs.
- Tool can access session info and stream progress, but cannot access internal runtime state.
- Every trait has clear ownership and lifetime semantics.
Structs§
- AppContext
- Application-level context: global configuration and identity.
- Context
Factory - Multi-adapter context factory.
- Context
Input - Input provided to context adapters.
- Context
Output - Output produced by context construction.
- Event
Sink - A sink for emitting events during a run.
- Function
Adapter - Function-based context adapter.
- Hook
Context Impl - Hook context implementation for observing run state.
- Memory
Context Impl - Memory context implementation with active window management.
- Memory
Entry - An entry retrieved from long-term memory.
- RunBudget
- Tracks the token budget for a single run.
- RunContext
Impl - Run-level context with cancellation, deadline, event sink, and budget.
- RunSnapshot
- A snapshot of the current run state for audit and replay.
- Session
Context Impl - Session-level context with mutable state.
- Session
State - A key-value state store scoped to a single session.
- Static
Adapter - Static context adapter that returns fixed messages.
- Tool
Context Impl - Tool execution context.
Traits§
- Context
Adapter - Pluggable context source that produces message fragments.
- Hook
Context - Context available to hooks observing the system.
- Memory
Context - Context for memory operations (demotion, compaction).
- Readonly
Context - The minimum context available to any participant in the system.
- RunContext
- Context available during a single run invocation.
- Session
Context - Context available during a session’s lifetime.
- Tool
Context - Context for tool execution.
Type Aliases§
- Context
Result - Result type for context operations.