Iteratio

What is Iteratio?

Iteratio is a lightweight, DI-driven agent execution loop library. It provides the conversational loop that powers every channel in armament: add a message, call the LLM, execute tools, store results, repeat — in a configurable step pipeline.

It is not a monolithic orchestration engine. Features like provider routing, session persistence, budget tracking, channel management, and the TUI are handled by armament’s app layer — iteratio focuses on the inner agent loop.

npm install iteratio

(Requires reflect-metadata and inversify — peer dependency on flight-controller is optional.)

Architecture

Iteratio uses InversifyJS for dependency injection, with a fluent builder pattern for configuration:

AgentLoopBuilder

  ├── withLLM(provider)       ← required: implements ILLMProvider
  ├── withTools([...])        ← register tools
  ├── withPlugin(plugin)      ← add lifecycle hooks
  ├── withPlugins([...])      ← add multiple
  ├── withSystemPrompt(text)  ← system prompt
  ├── withLogLevel(level)     ← verbosity
  ├── onToolEvents({...})     ← observe tool calls
  ├── onUsage(fn)             ← track token usage
  └── build()                 → AgentLoop

Core Classes

ClassResponsibility
AgentLoopMain loop — orchestrates turn execution, manages plugins
StepPipelineOrdered pipeline of steps run per turn
TurnExecutorCoordinates a single LLM+tool call round
MessageManagerConversation history with context window management
StateManagerKey-value state store with persistence hooks
ToolExecutorRegisters and invokes tools, manages tool definitions
EventBusTyped pub/sub for loop events
InterruptionControllerPause/resume loop execution

Default Pipeline Steps

Each turn runs through these steps in order:

  1. AddUserMessageStep — Injects user input into conversation
  2. CallLLMStep — Sends messages to the LLM, gets response
  3. ExecuteToolsStep — Runs any tool calls the LLM made
  4. AddToolResultsStep — Injects tool results back into conversation
  5. AddAssistantResponseStep — Records the final assistant response

Steps can be reordered, removed, or custom steps injected via loop.registerStep().

Usage

import { AgentLoopBuilder } from 'iteratio';
import { OpenAIProvider } from 'llm-flight-controller';

// Create an LLM provider (from flight-controller)
const provider = new OpenAIProvider({ apiKey: '...' });

// Build the loop
const loop = AgentLoopBuilder.create()
  .name('helper')
  .withLLM(provider)
  .withSystemPrompt('You are a helpful assistant.')
  .withTools([myTool])
  .onUsage((usage) => console.log(`Tokens: ${usage.total_tokens}`))
  .build();

// Run a turn
const response = await loop.runTurn('Hello!');
console.log(response);

Plugin System

Plugins hook into turn lifecycle events via the IPlugin interface:

interface IPlugin {
  name: string;
  beforeTurn?(ctx: TurnContext): Promise<void>;
  afterTurn?(ctx: TurnContext): Promise<void>;
  shutdown?(): Promise<void>;
}

14 official plugin packages are available:

PackagePurpose
iteratio-plugin-a2aAgent-to-agent communication
iteratio-plugin-constraintsConstraint-based step routing
iteratio-plugin-federationCross-instance agent federation
iteratio-plugin-graphDependency graph execution
iteratio-plugin-humanHuman-in-the-loop approval
iteratio-plugin-mcpMCP tool server integration
iteratio-plugin-memoryPersistent memory backends
iteratio-plugin-metricsTelemetry and metrics
iteratio-plugin-parallelParallel tool execution
iteratio-plugin-retryRetry with backoff
iteratio-plugin-sessionsSession checkpoint/restore
iteratio-plugin-stateState persistence adapters
iteratio-plugin-toolsTool lifecycle management
iteratio-plugin-tracingDistributed tracing
iteratio-plugin-workflowMulti-step workflow orchestration

Cross-Cutting Concerns

  • WorkerPool — Managed pool of child agents with scaling and backpressure
  • CircuitBreaker — Failure isolation for external dependencies
  • RateLimiter — Per-provider/minute rate limits
  • RBAC — Role-based access control for tool execution
  • Sandbox — Isolated tool execution environment
  • SessionCheckpoint — Snapshot/restore loop state
  • DistributedLock — Leader election via Redis/NATS

Integration with Armament

Armament wraps iteratio’s AgentLoop inside ChannelAgent, which adds:

  • Provider resolution via flight-controller (routing, fallback, cost tracking)
  • Channel-scoped tool registration via BuiltinTools + CatalogAdapter
  • Session persistence and resumption
  • Budget enforcement via BudgetManager
  • Streaming output to the TUI via ChannelAgentStreaming

Repository

Source: github.com/rjtruitt/iteratio