LLMGraph - Multi-Agent AI System Framework
A Rust library for building conversational AI applications with function calling capabilities. LLMGraph allows you to create directed graphs of AI agents that can communicate with each other, use tools, and process tasks in a coordinated manner.
Features
- Agent-based Architecture: Create custom agents that can process inputs and communicate with other agents
- Tool/Function Calling: Register tools that agents can use during execution
- Graph-based Workflow: Build complex workflows by connecting agents in a directed graph
- Flexible Tool Registry: Support for both global and node-specific tools
- Async/Await Support: Fully asynchronous execution for optimal performance
- OpenRouter Integration: Built-in support for LLM APIs through OpenRouter
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Quick Start
Creating a Simple Agent
use ;
use ToolRegistryTrait;
use async_trait;
;
Building an Agent Graph
async
Working with Tools
use ;
use HashMap;
// Define a weather tool
// Register the tool with the graph
let weather_tool = create_weather_tool;
graph.register_tool;
Creating an LLM-Powered Agent
use generate_full_response;
use Message;
Advanced Usage
Node-Specific Tools
You can register tools for specific nodes only:
// Register a tool only for node 0
graph.register_tool_for_node.unwrap;
Complex Agent Chains
;
Debugging and Visualization
// Print the graph structure
graph.print;
// Output:
// Adjacency list for the Graph:
// 0 (Agent: Manager) -> 1 2
// 1 (Agent: Developer) -> 0
// 2 (Agent: Reviewer) -> 0
API Reference
Graph Methods
new()- Create a new empty graphadd_node(id, agent)- Add an agent node to the graphadd_edge(from, to)- Connect two nodesregister_tool(tool, function)- Register a global toolregister_tool_for_node(node_id, tool, function)- Register a node-specific toolrun(start_id, input)- Execute the graph starting from a specific nodeprint()- Display the graph structure
Agent Trait
Implement the Agent trait to create custom agents:
run(&mut self, input, tool_registry)- Process input and return output with optional next nodeget_name(&self)- Return the agent's name for identification
Tool Registry
The tool registry provides:
get_tools()- Get all available toolsexecute_tool(name, arguments)- Execute a tool by name
Examples
Check the src/lib.rs file for complete test examples including:
- Basic agent chains
- LLM integration with OpenRouter
- Tool calling with weather and calculator functions
- Multi-agent workflows
Architecture
┌─────────────┐
│ Graph │
├─────────────┤
│ ┌─────────┐ │ ┌──────────┐
│ │ Node 0 │─┼────▶│ Agent │
│ └─────────┘ │ └──────────┘
│ ┌─────────┐ │ ┌──────────┐
│ │ Node 1 │─┼────▶│ Agent │
│ └─────────┘ │ └──────────┘
│ │
│ Tool Registry│
└─────────────┘
Requirements
- Rust 1.70+
- Tokio runtime for async execution
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License.