Module agent

Module agent 

Source
Expand description

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)

§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.

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::MAX_ITERATIONS_CEILING;
pub use config::MAX_PARALLEL_TOOLS_CEILING;
pub use config::MAX_TOOL_TIMEOUT_MS_CEILING;
pub use config::MIN_CONTEXT_BUDGET_CHARS;
pub use config::MIN_TOOL_TIMEOUT_MS;
pub use events::AGENT_EVENT_CHANNEL_CAPACITY;
pub use events::AgentEvent;
pub use events::LlmStreamEvent;
pub use messages::AgentMessage;
pub use messages::AssistantContent;
pub use tool_types::ToolCall;
pub use tool_types::ToolDefinition;
pub use tool_types::ToolResult;

Modules§

config
AgentConfig — configuration for a single agentic loop run.
events
AgentEvent and LlmStreamEvent — observable events in the agentic loop.
messages
AgentMessage — A single message in the agent conversation.
messages_serde 🔒
Custom Serialize / Deserialize implementations for agent message types.
tool_types
Tool-schema and tool-call/result types.