Expand description
behest runtime kernel (facade re-exports). temporarily allow during migration Building blocks for Rust-native AI agent runtimes.
§Architecture
behest has two complementary surfaces:
The invocation surface — a Socket.IO-inspired emit / on model
for interacting with an agent. Emit a user message, receive streaming
events back through typed handlers. This is the caller-facing API,
built on RuntimeInvocation.
The assembly surface — pluggable components (providers, tools,
stores, transports) wired together via ComponentRegistry
and driven by a coordinated lifecycle. This is the operator-facing API
for composing a runtime from parts, built on ManagedRuntime.
emit("question") on(TextDelta, handler)
Caller ──────────► RuntimeInvocation ──────────► Caller
│
▼
AgentRuntime ◄── ComponentRegistry
│ │
▼ ▼
run_loop (FSM) provider / tool / store / transportThe two surfaces are independent: you can use RuntimeInvocation with
a hand-assembled AgentRuntime, or drive the ManagedRuntime lifecycle
from your own invocation layer. They meet at AgentRuntime — the shared
kernel that both paths produce.
§Quick start
use behest::prelude::*;
use behest::runtime::RuntimeInvocation;
// 1. Build config & runtime
let config = AgentConfigBuilder::default()
.with_env("BEHEST")?
.with_provider(ProviderId::new("openai"), ProviderConfig::new("https://api.openai.com/v1")
.with_provider_type(ProviderType::OpenAi)
.with_api_key("env:OPENAI_API_KEY")
.with_model("gpt-4o"))
.build()?;
let runtime = Arc::new(config.into_runtime().await?);
// 2. Wrap in the invocation facade
let inv = RuntimeInvocation::new(runtime);
// 3. Subscribe to text deltas
let handle = inv.on(EventKind::TextDelta, |envelope, _session, _control| async move {
if let AgentEvent::TextDelta(td) = &envelope.event {
print!("{}", td.delta);
}
}).await?;
// 4. Emit a request
let output = inv.emit(|_session, _control| async move {
EmitRequest::new(provider_id, model, "Hello, world!")
}).await?;
drop(handle);§Modules
runtime: Runtime kernel, invocation facade, component system, policyprovider: Provider traits, request/response types, and registrytool: Tool trait, registry, scopingcontext: Multi-adapter context factory for composing chat requestsstore: Persistence traits and backends for sessions, embeddings, artifactsconfig: Centralized configuration with file, env, and builder supportadapt: Concrete provider adapters (OpenAI, Anthropic)error: Error types and result aliasesrag: Retrieval-Augmented Generation context adapter (feature =rag)queue: External event publishing to message brokers (feature =queue)
Re-exports§
pub use crate::runtime::CompactionResult;pub use crate::runtime::CompactionService;
Modules§
- adapt
- Concrete provider adapters.
- agent
- Agent definition and registry.
- config
- Centralized agent configuration.
- context
- Re-export of the high-level context factory API, which now lives
in
behest_context. This module is preserved for facade compatibility; preferuse behest_context::*directly in new code. - error
- Error types shared across the public API.
- health
- Health status primitives shared by every component.
- prelude
- Convenient imports for application and integration code.
- provider
- Provider-neutral contracts for chat, tools, streaming, and embeddings.
- queue
- External event publishing for agent observability.
- rag
- Retrieval-Augmented Generation (RAG) context adapter.
- runtime
- Runtime facade re-exports.
- store
- Persistence traits and storage backends.
- token
- Token estimation using character-based heuristics.
- tool
- Re-export of the tool system from
behest_tool. This module is preserved for facade compatibility. - tool_
output - Tool output configuration (re-exported from behest_runtime).
- tool_
scope - Tool scope helpers re-exported from
behest_runtime.
Structs§
- Agent
Runtime - Streaming-first agent runtime kernel.
- Anthropic
Chat Component - Component wrapper for
AnthropicChatAdapter. - Cache
Stats - Aggregated prompt-cache statistics over a window of events.
- Component
Context - Context handed to
Component::initand propagated through dependent components. - Component
Descriptor - Static descriptor of a component kind, used by the registry to plan initialization order without holding the actual factory.
- Component
Registry - The central component registry.
- Context
Pipeline Component - Component wrapper for
ContextPipeline. - Context
Pipeline Config - JSON configuration for
ContextPipelineComponent. - Control
- Cooperative lifecycle handle shared across an invocation.
- Emit
Request - Transport-neutral request for a single runtime invocation.
- Extension
Point - Typed, name-indexed collection of
Arc<T>. - Extensions
- The composable, hot-pluggable facade over every pluggable runtime element.
- Factory
Registry - A registry that maps
kindstrings (e.g."provider.openai") toFactoryInvokerinstances. - File
Session Data Store - File-system
SessionDataStorebacked by JSON files. - File
Snapshot Store - Filesystem-based
SnapshotStorewith atomic write semantics. - Invocation
Handle - Handle to a background listener task started by
RuntimeInvocation::on. - Invocation
Session - Invocation-time session context with temporary KV storage.
- Managed
Runtime - Unified container orchestrating
AgentRuntime,ComponentRegistry, and a rootShutdownToken. - Memory
Artifact Store Component - Component wrapper for
MemoryArtifactStore. - Memory
Embedding Store Component - Component wrapper for
MemoryEmbeddingStore. - Memory
Execution Store Component - Component wrapper for
MemoryExecutionStore. - Memory
RunStore Component - Component wrapper for
MemoryRunStore. - Memory
Session Data Store - In-memory
SessionDataStorebacked by aHashMap. - Memory
Session Store Component - Component wrapper for
MemorySessionStore. - Model
Router - Routes model requests (chat and embedding) across providers with capability checking, exponential-backoff retry, and fallback chains.
- Open
AiChat Component - Component wrapper for
OpenAiChatAdapter. - Open
AiEmbedding Component - Component wrapper for
OpenAiEmbeddingAdapter. - Prompt
Cache Config - Prompt caching configuration.
- Provider
Http Component Config - JSON-deserializable configuration for HTTP-backed providers like OpenAI
and Anthropic. Uses plain
Stringfor the API key (instead ofSecretString) so that it can be deserialised from JSON/YAML/TOML. - Redis
Session Data Store - Redis-backed implementation of
SessionDataStore. - RunId
- Unique identifier for a single agent run invocation.
- RunOutput
- Output of a completed agent run.
- RunRequest
- Request to start a new agent run.
- Runtime
Event Bridge - Drains
AgentRuntime::subscribeinto the event store and stream adapter. - Runtime
Event Bridge Handle - Handle to a running
RuntimeEventBridgetask. - Runtime
Event Envelope - Envelope wrapping an
AgentEventwith cross-instance routing metadata. - Runtime
Event Id - Globally unique identifier for a single runtime event.
- Runtime
Invocation - Transport-neutral invocation facade over
AgentRuntime. - Runtime
Policy - Runtime policy for agent execution.
- Runtime
Subscription - Replay page plus a live stream for a single subscription.
- Runtime
Subscription Hub - Combines replay and live fanout for runtime event streams.
- Shutdown
Token - Hierarchical, cooperative shutdown token.
- Snapshot
- A serialized execution snapshot of an active agent run.
- Tool
Output Config - Configuration for tool output truncation.
- Truncation
Result - Result of tool output truncation.
- Typed
AnyComponent - Adapter from a typed
Componentto the type-erasedAnyComponenttrait. Created byTypedFactory::build. - Typed
Factory - Convenience wrapper that adapts a concrete
Componentinto aComponentFactory.
Enums§
- Agent
Event - Event emitted during agent runtime execution.
- AnyComponent
Error - Type-erased error from a boxed
AnyComponent. The original typed error is preserved as a string for log purposes; if callers need the typed error they should downcast viaAnyComponent::as_any_arc. - Component
Error - Error type for components constructed from configuration.
- Component
State - Initialization state of a registered component.
- Context
Error - Errors produced during context construction.
- Error
- Top-level crate error.
- Event
Kind - Kind of event a caller can subscribe to via
RuntimeInvocation::on. - Extension
Error - Errors raised by
ExtensionPointoperations. - Factory
Error - Errors from factory creation or registry operations.
- Health
Status - Tri-state health classification of a component.
- Invocation
Error - Errors raised by the invocation facade.
- Invocation
Event - Unified event envelope wrapping runtime and chat-stream events.
- Managed
Error - Errors from
ManagedRuntimeoperations. - Provider
Error - Errors produced by provider implementations.
- Registry
Error - Errors raised by
ComponentRegistryoperations. - RunStatus
- Status of an agent run.
- Runtime
Error - Errors that can occur during runtime execution.
- Runtime
Event Bridge Error - Errors surfaced by a
RuntimeEventBridgehandle. - Runtime
Event Store Error - Errors raised by a
RuntimeEventStore. - Runtime
Room - Fanout routing key, inspired by a Socket.IO room but transport-neutral.
- Runtime
Stream Error - Errors raised by a
RuntimeStreamAdapter. - Runtime
Subscription Error - Errors raised while assembling a
RuntimeSubscription. - Session
Data Error - Errors returned by
SessionDataStoreimplementations. - Storage
Error - Errors produced by storage backends.
- Tool
Error - Errors produced during tool execution.
Traits§
- AnyComponent
- Object-safe view of a
Componentinstance, used by the registry to store and drive components of heterogeneous types uniformly. - Component
- The core contract every pluggable runtime element implements.
- Component
Factory - Type-erased factory for a concrete
Componenttype. The registry holds factories asBox<dyn ComponentFactory>so it can drive heterogeneous types uniformly. - Runtime
Event Store - Authoritative replay source for runtime events.
- Runtime
Stream Adapter - Transport-neutral live fanout for runtime event envelopes.
- Session
Data Store - Pluggable backend for per-session temporary key-value data.
- Snapshot
Store - Trait for snapshot persistence backends.
Functions§
- default_
factory_ registry - Returns a
FactoryRegistrypre-populated with all built-in component factory invokers: - register_
context_ pipeline - Registers the context-pipeline factory invoker into a
FactoryRegistry. - register_
memory_ stores - Registers all memory-store factory invokers into a
FactoryRegistry. - register_
providers - Registers all provider factory invokers into a
FactoryRegistry.