Expand description
§agent
Agent loop domain types.
These types define the core abstractions for the backend agentic loop. They are pure domain primitives: no LLM backend references, no MCP types, no infrastructure concerns.
§Modules
| Module | Contents |
|---|---|
config | AgentConfig — loop control parameters |
tool_types | ToolDefinition, ToolCall, ToolResult |
messages | AgentMessage — closed conversation-turn enum |
messages_serde | Custom Serialize/Deserialize impls for AssistantContent |
events | AgentEvent (SSE units), LlmStreamEvent (stream protocol) |
loop_detection | LoopDetector — repeated tool-call-batch guard (FNV-1a batch signatures) |
stagnation | StagnationDetector — repeated assistant-text guard |
fnv1a | fnv1a::fnv1a_64 — the hash backing both detectors |
§Design Principles
AgentMessageis a closed enum so the type system prevents invalid states (e.g. aUsermessage carryingtool_calls).ToolDefinitionis a dedicated type — adapter layers convertMcpTool → ToolDefinition; the agent domain must not depend on MCP domain types.ToolResultwithsuccess: falseis context for the LLM, not an error; tool failures are fed back into the conversation so the model can reason about them and retry or adjust its approach.AgentEventis the unit of SSE emission; every observable state change in the loop corresponds to exactly one variant.
Modules
| Module | LOC | Complexity | Coverage |
|---|---|---|---|
config.rs | |||
events.rs | |||
fnv1a.rs | |||
messages.rs | |||
messages_serde.rs | |||
tool_display.rs | |||
tool_types.rs | |||
loop_detection/ | |||
stagnation/ |
Re-exports§
pub use config::AgentConfig;pub use config::AgentConfigError;pub use config::DEFAULT_MAX_ITERATIONS;pub use config::DEFAULT_MAX_PARALLEL_TOOLS;pub use config::DEFAULT_MAX_STAGNATION_STEPS;pub use config::MAX_ITERATIONS_CEILING;pub use config::MAX_PARALLEL_TOOLS_CEILING;pub use config::MAX_STAGNATION_STEPS_CEILING;pub use config::MAX_TOOL_TIMEOUT_MS_CEILING;pub use config::MIN_CONTEXT_BUDGET_CHARS;pub use config::MIN_TOOL_TIMEOUT_MS;
Modules§
- config
AgentConfig— configuration for a single agentic loop run.- events 🔒
AgentEventandLlmStreamEvent— observable events in the agentic loop.- fnv1a 🔒
- FNV-1a 64-bit hash utility backing the loop and stagnation detectors.
- loop_
detection 🔒 - Loop Detection
- messages 🔒
AgentMessage— A single message in the agent conversation.- messages_
serde 🔒 - Custom
Serialize/Deserializeimplementations for agent message types. - stagnation 🔒
- stagnation
- tool_
display - Shared tool display formatting — single source of truth for all surfaces.
- tool_
types 🔒 - Tool-schema and tool-call/result types.
Structs§
- Assistant
Content - Content carried by an
AgentMessage::Assistantturn. - Batch
Record - Names the batch
LoopDetector::checkjust counted. - Loop
Detector - Stateful guard that detects when the same tool-call batch repeats back to back and gets the same answer back.
- Stagnation
Detector - Stateful guard that detects when the assistant repeats the same text.
- Tool
Call - A tool invocation requested by the LLM.
- Tool
Definition - A tool that the LLM may invoke, expressed as a name + JSON Schema.
- Tool
Result - The outcome of executing a
ToolCall.
Enums§
- Agent
Event - An observable event emitted by the agentic loop.
- Agent
Message - A single message in the agent conversation.
- LlmStream
Event - A single event produced by a streaming LLM response.
- Repeat
Outcome - What one occurrence turned out to be, once its answers were known.
Constants§
- AGENT_
EVENT_ CHANNEL_ CAPACITY - [
tokio::sync::mpsc] channel capacity for streamingAgentEvents produced by a singlecrate::ports::AgentLoopPort::runcall.
Functions§
- batch_
results_ hash - Hash the answers to one batch of tool calls.
- batch_
signature - Compute the batch signature for a slice of
ToolCalls. - hash_
result_ content - Hash one answer’s content, whatever shape it arrived in.
- hash_
result_ text - Hash one answer’s text.
- is_
observation_ batch - Return
trueif every call incallsis an observation-only tool.