neuron-loop
The agentic while-loop for the neuron ecosystem. Composes a Provider, a
ToolRegistry, and a ContextStrategy into a loop that sends messages to an
LLM, executes tool calls, manages context compaction, and repeats until the
model produces a final response or a turn limit is reached.
Key Types
AgentLoop<P, C>-- the core loop, generic overProviderandContextStrategyAgentLoopBuilder<P, C>-- builder for constructing anAgentLoopwith optional configurationLoopConfig-- system prompt, max turns, parallel tool execution flagAgentResult-- final output: response text, all messages, cumulative token usage, turn countTurnResult-- per-turn result enum for step-by-step iterationBoxedHook-- type-erasedObservabilityHookfor dyn-compatible hook storageBoxedDurable-- type-erasedDurableContextfor dyn-compatible durability
Usage
Build an AgentLoop using the builder pattern. Only provider and context
are required; tools, config, hooks, and durability are optional with sensible
defaults.
use ;
use ToolRegistry;
use SlidingWindowStrategy;
use ToolContext;
// Set up components
let provider = new;
let context = new;
let mut tools = new;
tools.register;
// Build and run
let mut agent = builder
.tools
.system_prompt
.max_turns
.parallel_tool_execution
.build;
let tool_ctx = ToolContext ;
let result = agent.run_text.await?;
println!;
println!;
println!;
For step-by-step iteration (useful for streaming UIs or custom control flow):
let mut agent = builder.build;
// Use agent.run_step() to drive one turn at a time
Add observability hooks to log, meter, or control loop execution:
let agent = builder
.hook
.durability
.build;
Architecture
AgentLoop depends on neuron-types (traits) and neuron-tool
(ToolRegistry). RPITIT traits (Provider, ObservabilityHook,
DurableContext) are type-erased internally via boxed wrappers for
dyn-compatibility. The ContextStrategy is used as a generic parameter.
Part of neuron
This crate is part of neuron, a composable building-blocks library for AI agents in Rust.
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.