agent-runtime
A production-ready Rust framework for building AI agent workflows with native and external tool support, streaming LLM interactions, comprehensive event tracking, and intelligent loop prevention.
Features
🤖 Agent System
- LLM-backed agents with configurable system prompts and context
- Multi-provider LLM support - OpenAI and llama.cpp (LM Studio) included
- Streaming responses - Real-time token-by-token LLM output
- Tool loop prevention - Automatic detection and prevention of redundant tool calls
- Execution history - Complete conversation and tool call tracking per agent
🔧 Tool System
- Native tools - In-memory async functions with zero overhead
- MCP tool integration - Connect to external MCP servers (filesystem, databases, web, etc.)
- Tool registry - Organize and manage tools per agent
- Automatic discovery - MCP tools auto-discovered from servers
- Rich metadata - Full argument schemas and descriptions
🔄 Workflow Engine
- Sequential workflows - Chain multiple agents with state passing
- Transform steps - Data manipulation between agents
- Conditional branching - Dynamic workflow paths
- Nested workflows - SubWorkflows for complex orchestration
- Mermaid export - Visualize workflows as diagrams
📡 Event System
- Real-time events - Complete visibility into execution
- Fine-grained tracking - Workflow, agent, LLM, and tool events
- Streaming chunks - Live LLM token streaming via events
- Multi-subscriber - Multiple event listeners per workflow
- Event bubbling - Events propagate from tools → agents → workflows
⚙️ Configuration
- YAML and TOML support - Human-readable config files
- Builder pattern - Type-safe programmatic configuration
- Environment variables - Runtime configuration override
- Per-agent settings - System prompts, tools, LLM clients, loop prevention
🔒 Production Ready
- 61 comprehensive tests - All core functionality tested
- Tool loop prevention - Prevents LLM from calling same tool repeatedly
- Microsecond timing - Precise performance metrics
- Structured logging - FileLogger with timestamped output
- Error handling - Detailed error types with context
Quick Start
Installation
[]
= { = "." }
= { = "1", = ["full"] }
Basic Agent
use *;
async
MCP External Tools
use ;
// Connect to MCP server
let mcp = new_stdio.await?;
// Discover tools
let tools = mcp.list_tools.await?;
println!;
// Use in agent
let agent = new
.with_mcp_tools
.build;
Workflow
let workflow = new
.add_step
.add_step
.add_step
.build;
let result = workflow.execute.await?;
Event Streaming
let = channel;
// Subscribe to events
spawn;
agent.execute_with_events.await?;
Configuration Files
# agent-runtime.yaml
agents:
- name: researcher
system_prompt: "You are a research assistant."
max_iterations: 10
tool_loop_detection:
enabled: true
custom_message: "Previous {tool_name} call returned: {previous_result}"
- name: analyzer
system_prompt: "You analyze data."
tool_loop_detection:
enabled: false # Disable if needed
let config = from_file?;
Architecture
Core Modules
runtime- Workflow execution engine with event emissionworkflow- Builder pattern for composing stepsagent- LLM-backed agents with tool execution loopstep- Trait for workflow steps (Agent, Transform, Conditional, SubWorkflow)llm- Provider-agnostic chat client (OpenAI, llama.cpp)tool- Native tool trait and registrytools/mcp_client- MCP protocol client for external toolsevent- Event types and streaming systemconfig- YAML/TOML configuration loadingtool_loop_detection- Intelligent duplicate tool call prevention
Event Types
- Workflow: Started, StepStarted, StepCompleted, StepFailed, Completed, Failed
- Agent: Started, Completed, Failed, LlmStreamChunk
- LLM: RequestSent, ResponseReceived, StreamChunkReceived
- Tool: ToolCallStarted, ToolCallCompleted, ToolCallFailed, AgentToolLoopDetected
Tool Loop Prevention
Prevents LLMs from calling the same tool with identical arguments repeatedly:
- Automatic detection - Tracks tool calls and arguments using MD5 hashing
- Configurable messages - Custom messages with
{tool_name}and{previous_result}placeholders - Event emission -
AgentToolLoopDetectedevent for observability - Enabled by default - Can be disabled per-agent if needed
Examples
Run any demo:
# Workflows
# Agents & Tools
# LLM Clients
# Configuration
# Visualization
Documentation
- Specification - Complete system design
- Tool Calling - Native tool usage
- MCP Integration - External MCP tools
- Event Streaming - Event system guide
- LLM Module - LLM provider integration
- Workflow Composition - Building workflows
- Testing - Test suite documentation
Testing
License
Dual-licensed under MIT or Apache-2.0 at your option.