Skip to main content

Crate behest_context

Crate behest_context 

Source
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.
ContextFactory
Multi-adapter context factory.
ContextInput
Input provided to context adapters.
ContextOutput
Output produced by context construction.
EventSink
A sink for emitting events during a run.
FunctionAdapter
Function-based context adapter.
HookContextImpl
Hook context implementation for observing run state.
MemoryContextImpl
Memory context implementation with active window management.
MemoryEntry
An entry retrieved from long-term memory.
RunBudget
Tracks the token budget for a single run.
RunContextImpl
Run-level context with cancellation, deadline, event sink, and budget.
RunSnapshot
A snapshot of the current run state for audit and replay.
SessionContextImpl
Session-level context with mutable state.
SessionState
A key-value state store scoped to a single session.
StaticAdapter
Static context adapter that returns fixed messages.
ToolContextImpl
Tool execution context.

Traits§

ContextAdapter
Pluggable context source that produces message fragments.
HookContext
Context available to hooks observing the system.
MemoryContext
Context for memory operations (demotion, compaction).
ReadonlyContext
The minimum context available to any participant in the system.
RunContext
Context available during a single run invocation.
SessionContext
Context available during a session’s lifetime.
ToolContext
Context for tool execution.

Type Aliases§

ContextResult
Result type for context operations.