Examples

A curated catalogue of runnable examples covering providers, tools, sessions, RAG, streaming, and the new composable runtime.

Examples

Each example is a self-contained Rust binary in the examples/ directory of the behest crate. They are designed to be read top-to-bottom; the more interesting ones are organised in layers, building on the primitives from the previous example.

By area

Providers

ExampleWhat it shows
provider_setup.rsRegistering a ChatProvider and an EmbeddingProvider against a ProviderRegistry.
real_request.rsEnd-to-end chat request through ProviderRegistry::complete.
custom_provider.rsImplementing ChatProvider for an internal model endpoint.

Tools

ExampleWhat it shows
tool_registry.rsBuilding a ToolRegistry from FunctionTool and ExternalTool.
tool_execution.rsA full tool-calling turn with validation, timeout, and execution-store recording.
tool_scope.rsLIFO shadow-stack scopes for turn / run / agent / base.

Sessions and storage

ExampleWhat it shows
session_lifecycle.rsCreate, load, append, and list sessions.
message_history.rsPersisting the MessageRecord history through SessionStore.
session_data_store.rsPer-session data store for invocation context.

Runtime and streaming

ExampleWhat it shows
run_streaming.rsStreaming model events from AgentRuntime::run_stream.
invocation_facade.rsThe transport-neutral emit / on facade.
control_basics.rsPause / resume / cancel via the Control handle.

Events and observability

ExampleWhat it shows
event_store_replay.rsReplaying events from RuntimeEventStore after a process restart.
event_subscription.rsLive fan-out via RuntimeSubscriptionHub with replay-then-live semantics.

Context and RAG

ExampleWhat it shows
context_pipeline.rsA ContextPipeline with static, function, and RAG adapters.
rag_basic.rsThe RAG context adapter with Qdrant or Tantivy.

Composable runtime

ExampleWhat it shows
composable_runtime.rsThe Extensions facade, FactoryRegistry, and default_factory_registry().
hot_reload.rsDrain-aware replace: swapping a chat provider at runtime.

Configuration

ExampleWhat it shows
config_from_toml.rsLoading behest.toml with env overrides.
hello_config.rsThe minimum AgentConfig setup.
agent_registry.rsDefining named AgentDefinition entries and routing by name.

Misc

ExampleWhat it shows
snapshot_compaction.rsResuming a run from a snapshot after a process crash.
token_estimation.rsThe token-estimation heuristics.

How to run

git clone https://github.com/lazhenyi/behest
cd behest
cargo run --example provider_setup --features openai

All examples run on the default features unless their Cargo.toml entry shows a --features flag. Examples that touch network APIs (real_request, run_streaming, event_subscription) require the relevant provider or queue feature to be enabled.

Reading order for new users

Related components

Edit this page on GitHub →