Skip to main content

Module agent

Module agent 

Source
Expand description

§agent

LOC Complexity

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

ModuleContents
configAgentConfig — loop control parameters
tool_typesToolDefinition, ToolCall, ToolResult
messagesAgentMessage — closed conversation-turn enum
messages_serdeCustom Serialize/Deserialize impls for AssistantContent
eventsAgentEvent (SSE units), LlmStreamEvent (stream protocol)
loop_detectionLoopDetector — repeated tool-call-batch guard (FNV-1a batch signatures)
stagnationStagnationDetector — repeated assistant-text guard
fnv1afnv1a::fnv1a_64 — the hash backing both detectors

§Design Principles

  • AgentMessage is a closed enum so the type system prevents invalid states (e.g. a User message carrying tool_calls).
  • ToolDefinition is a dedicated type — adapter layers convert McpTool → ToolDefinition; the agent domain must not depend on MCP domain types.
  • ToolResult with success: false is 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.
  • AgentEvent is the unit of SSE emission; every observable state change in the loop corresponds to exactly one variant.

Modules

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 🔒
AgentEvent and LlmStreamEvent — 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 / Deserialize implementations 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§

AssistantContent
Content carried by an AgentMessage::Assistant turn.
BatchRecord
Names the batch LoopDetector::check just counted.
LoopDetector
Stateful guard that detects when the same tool-call batch repeats back to back and gets the same answer back.
StagnationDetector
Stateful guard that detects when the assistant repeats the same text.
ToolCall
A tool invocation requested by the LLM.
ToolDefinition
A tool that the LLM may invoke, expressed as a name + JSON Schema.
ToolResult
The outcome of executing a ToolCall.

Enums§

AgentEvent
An observable event emitted by the agentic loop.
AgentMessage
A single message in the agent conversation.
LlmStreamEvent
A single event produced by a streaming LLM response.
RepeatOutcome
What one occurrence turned out to be, once its answers were known.

Constants§

AGENT_EVENT_CHANNEL_CAPACITY
[tokio::sync::mpsc] channel capacity for streaming AgentEvents produced by a single crate::ports::AgentLoopPort::run call.

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 true if every call in calls is an observation-only tool.