Overview
The agent module orchestrates the core functionality of IronClaw:- Message routing from channels
- Job scheduling and execution
- Tool invocation with safety guardrails
- Self-repair for stuck jobs
- Proactive heartbeat execution
- Routine-based scheduled and reactive jobs
- Turn-based session management with undo
- Context compaction for long conversations
Core Types
Agent
The main agent orchestrator that processes incoming messages and manages execution.String
User identifier for the agent session
Session
Current session state with threads and turns
Workspace
Persistent memory storage for the agent
ToolRegistry
Available tools for the agent to use
Example
Session
A session contains one or more threads representing conversations with the agent.Uuid
Unique session identifier
String
User who owns this session
Option<Uuid>
Currently active thread ID
HashMap<Uuid, Thread>
All threads in this session
HashSet<String>
Tools that have been auto-approved for this session
Methods
fn(user_id: impl Into<String>) -> Self
Create a new session for a user
fn(&mut self) -> &mut Thread
Create a new thread in this session and make it active
fn(&self) -> Option<&Thread>
Get the currently active thread
fn(&self, tool_name: &str) -> bool
Check if a tool has been auto-approved
fn(&mut self, tool_name: impl Into<String>)
Add a tool to the auto-approved set
Example
Thread
A thread represents a conversation sequence with turns (request/response pairs).Uuid
Unique thread identifier
Uuid
Parent session ID
Vec<Turn>
Conversation history as turns
ThreadState
Current state (Active, Interrupted, Completed)
Turn
A single request/response pair in a conversation.Uuid
Unique turn identifier
String
User’s input message
Option<String>
Agent’s response (None if turn incomplete)
Vec<ToolCall>
Tool invocations made during this turn
TurnState
Current state (Pending, InProgress, Completed, Failed)
Routine
A scheduled or reactive job that runs automatically.Uuid
Unique routine identifier
String
Human-readable routine name
Trigger
When this routine should execute
RoutineAction
What the routine should do
Trigger Types
String
Execute on a cron schedule (e.g., “0 9 * * *”)
Duration
Execute every N seconds/minutes/hours
String
Execute when a specific event occurs
Example
ContextCompactor
Compacts conversation history to save context window space.async fn(thread: &Thread) -> Result<CompactionResult>
Compact a thread’s conversation history by summarizing old turns
fn(thread: &Thread) -> bool
Check if a thread should be compacted based on size
CompactionResult
usize
Number of turns before compaction
usize
Number of turns after compaction
String
Summary of compacted content
u32
Approximate tokens saved by compaction
Example
UndoManager
Manages checkpoints and undo operations for sessions.fn(&mut self, session: &Session) -> Checkpoint
Create a checkpoint of the current session state
fn(&mut self, checkpoint_id: Uuid) -> Result<Session>
Restore session to a previous checkpoint
fn(&self) -> Vec<Checkpoint>
List all available checkpoints
Example
SelfRepair
Detects and repairs stuck jobs and broken tools.async fn() -> Vec<StuckJob>
Find jobs that have been running too long
async fn(task: RepairTask) -> Result<RepairResult>
Attempt to repair a stuck job or broken tool
RepairTask Types
{ job_id: Uuid, reason: String }
A job that needs to be unstuck
{ tool_name: String, error: ToolError }
A tool that failed and needs repair
Example
Related Modules
Workspace Module
Persistent memory storage for agents
Tools Module
Extensible tool system for agent capabilities
LLM Module
Language model integration and providers