RUST / AGENT RUNTIME
TOTEM
A Rust agent runtime built around an async PipelineStage contract, CAPSEM capability evaluation, MCP/A2A tool adapters and a BLAKE3-linked execution log.

Typed execution across policy, protocol and audit boundaries.
Totem executes structured AgentTask values through a shared, ordered runtime. Axum HTTP and Tonic gRPC servers share the same RuntimeContext, registry and audit logger. Pipeline stages mutate an ExecutionContext while preserving typed task/action identities. This separates transport, context reduction, permission checks, tool invocation and execution evidence into independently inspectable Rust crates.
Pipeline stages
Ordered stages implementing the shared async trait.
Context-token budget
Default approximate window used by ContextStage.
Scheduler benchmark fixture
Simulated branch-latency comparison, separate from tool dispatch.
02 / THROUGH THE SYSTEM
INPUT → OUTPUT- 01
Accept
Axum HTTP and Tonic gRPC share a RuntimeContext and the same execution pipeline.
- 02
Prepare
Scheduler components model dependencies; the context stage applies a bounded window with salience scoring.
- 03
Check
CAPSEM evaluates capabilities and explicit revocations before tools are dispatched.
- 04
Dispatch
MCP filesystem calls and registry-backed tools route through their protocol-specific adapters.
- 05
Record
Tool outputs, latency and audit events feed the execution result and BLAKE3-linked history.
Async stage composition and error propagation
PipelineStage is an async trait bounded by Send + Sync. ExecutionPipeline invokes each stage with an immutable AgentTask and mutable ExecutionContext; errors propagate with ? and terminate the remaining sequence. The composition root wires Scheduler → Context → CAPSEM → MCP → ToolManager → A2A → Audit → Evaluation → Recovery. Both API transports dispatch through this same instance.
Policy precedence and context salience
CAPSEM resolves resource/action grants and explicit revocations before dispatch. Denial takes precedence over a wildcard grant; the configured restricted tool exercises that path. The context layer scores messages and tool results by role, recency and content signals, then evicts lower-salience entries to satisfy its approximate token budget. The default window is 8,000 tokens.
03 / SELECTED EVIDENCE
03 FRAMES
HTTP and gRPC composition root
The startup trace shows the Sentinel binary binding its HTTP and gRPC endpoints. /execute enters the shared pipeline, /tools exposes registered transports, and /audit exposes complete event history.

Typed tool invocation and returned metrics
The execute response contains tool_results with a tool name, JSON output and latency_ms. The request passes context filtering and capability checks before dispatch, feeding validated output to audit and evaluation stages.

BLAKE3 chain verification
The audit response lists event records and chain_valid. Verification checks previous-hash linkage and recomputes cryptographic hashes across the log, detecting any mutation to the execution sequence.
Protocol dispatch and shared registry state
An Arc-backed DashMap registry holds tool definitions, schemas and transport descriptors. ToolManager dispatches local, HTTP, GraphQL and A2A calls; MCP filesystem actions go through their own JSON-RPC stage. Optional attestations are checked during registration and invocation. The running service exposes registry discovery and an A2A Agent Card. Generic gRPC tool descriptors use an HTTP JSON gateway adapter, distinct from the Tonic server API.
Hash-linked audit and scheduler instrumentation
BLAKE3 binds each audit event to the preceding hash; verification recomputes the chain. Tool results retain action IDs, output and latency, while Evaluation writes execution metrics into context metadata. The DAG subsystem implements topological levels, cycle detection and branch pruning. Its timing test compares three 100 ms simulated branches sequentially and concurrently to benchmark scheduler concurrency and branch dispatch latency. Non-MCP ToolManager actions currently execute in sequence.
04 / BUILT WITH
TOOLS & THEIR PLACE- 01Tokio / RustAsync execution & ownership
- 02async-traitPipelineStage interface
- 03CAPSEMCapability policies
- 04MCP / JSON-RPCFilesystem tool transport
- 05Tonic / ProstTyped gRPC service
- 06DashMap / ArcShared tool registry
- 07BLAKE3Hash-linked audit
- 08A2A / GraphQLRemote dispatch adapters

