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 (v0.3.0 - Unified)
- Unified event model - Consistent
Scope × Type × Statuspattern across all components - Complete lifecycle tracking - Started → Progress → Completed/Failed for workflows, agents, LLM requests, tools
- Real-time streaming - Live LLM token streaming via Progress events
- Multi-subscriber - Multiple event listeners per workflow
- Type-safe component IDs - Enforced formats with validation
⚙️ 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
- 97 comprehensive tests - All core functionality tested
- Tool loop prevention - Prevents LLM from calling same tool repeatedly with System::Progress events
- Microsecond timing - Precise performance metrics via event data
- Async event emission - Non-blocking event streaming with tokio::spawn
- Error handling - Detailed error types with context and human-readable messages
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 (v0.3.0)
use ;
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 System (v0.3.0)
Unified Scope × Type × Status Pattern:
- Scopes: Workflow, WorkflowStep, Agent, LlmRequest, Tool, System
- Types: Started, Progress, Completed, Failed, Canceled
- Status: Pending, Running, Completed, Failed, Canceled
Key Events:
Workflow::Started/Completed/Failed- Overall workflow executionWorkflowStep::Started/Completed/Failed- Individual step trackingAgent::Started/Completed/Failed- Agent processing lifecycleLlmRequest::Started/Progress/Completed/Failed- Real-time LLM streamingTool::Started/Progress/Completed/Failed- Tool execution trackingSystem::Progress- Runtime behaviors (e.g., tool loop detection)
Component ID Formats:
- Workflow:
workflow_name - WorkflowStep:
workflow:step:N - Agent:
agent_name - LlmRequest:
agent:llm:N - Tool:
tool_nameortool_name:N - System:
system:subsystem
Tool Loop Prevention
Prevents LLMs from calling the same tool with identical arguments repeatedly:
- Automatic detection - Tracks tool calls and arguments using MD5 hashing
- System events - Emits
System::Progressevent withsystem:tool_loop_detectioncomponent ID - Configurable messages - Custom messages with
{tool_name}and{previous_result}placeholders - Enabled by default - Can be disabled per-agent if needed
Examples
Run any demo:
# Event System
# Workflows
# Agents & Tools
# LLM Clients
# Configuration
# Visualization
Documentation
- Event Streaming Guide - Complete event system documentation (v0.3.0)
- Migration Guide - Upgrading from v0.2.x to v0.3.0
- Changelog - Release notes for v0.3.0
- Specification - Complete system design
- Tool Calling - Native tool usage
- MCP Integration - External MCP tools
- LLM Module - LLM provider integration
- Workflow Composition - Building workflows
- Testing - Test suite documentation
Testing
What's New in v0.3.0
🎉 Unified Event System - Complete rewrite for consistency and extensibility
- Breaking Changes: New event structure with
EventScope,ComponentStatus, unifiedEventType - Helper Methods: 19 ergonomic helper methods for common event patterns
- Component IDs: Enforced formats with validation for type safety
- Async Events: Non-blocking event emission via
tokio::spawn() - Migration Guide: See docs/MIGRATION_0.2_TO_0.3.md
Upgrading from v0.2.x?
// Old (v0.2.x)
match event.event_type
// New (v0.3.0)
match
See CHANGELOG.md for complete details.
License
Dual-licensed under MIT or Apache-2.0 at your option.