neuron-runtime
Production runtime layer for the neuron agent blocks ecosystem. Provides session management, sub-agent orchestration, input/output guardrails, durable execution contexts, and tool sandboxing.
Key Types
Session-- a conversation session with messages, state, and timestamps. Created withSession::new(id, cwd).SessionState-- mutable runtime state within a session (working directory, token usage, event count, custom metadata).SessionStoragetrait -- async trait for persisting and loading sessions.InMemorySessionStorage--Arc<RwLock<HashMap>>storage for testing.FileSessionStorage-- one JSON file per session on disk.InputGuardrail/OutputGuardrail-- traits for safety checks that run before input reaches the LLM or before output reaches the user.GuardrailResult--Pass,Tripwire(reason), orWarn(reason). A tripwire halts execution immediately.GuardrailHook-- anObservabilityHookthat runs input/output guardrails during the agent loop. Tripwires terminate; warnings log and continue.SubAgentConfig-- configuration for spawning sub-agents (system prompt, tool filter, max depth, max turns).SubAgentManager-- registers and spawns sub-agents.LocalDurableContext-- passthroughDurableContextfor local development (no journaling or replay).Sandboxtrait /NoOpSandbox-- tool execution isolation boundary.
Usage
use PathBuf;
use ;
// Create a session and persist it to disk
async
// Define an input guardrail that blocks secrets
;
GuardrailHook
GuardrailHook wraps input and output guardrails as an ObservabilityHook,
so they integrate directly into the agent loop via the hook system.
use ;
;
;
let hook = new
.input_guardrail
.output_guardrail;
// Pass `hook` as the ObservabilityHook when building the agent loop.
- On
PreLlmCall, the hook extracts the last user message text and runs all input guardrails. ATripwirereturnsHookAction::Terminate; aWarnlogs viatracing::warn!and continues. - On
PostLlmCall, the hook extracts the assistant response text and runs all output guardrails with the same mapping.
Part of neuron
This crate is one block in the neuron
composable agent toolkit. It depends on neuron-types, neuron-tool, and
neuron-loop.
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.