Crate rigs

Source
Expand description

A framework for building reliable multi-agent applications.

Rigs is an agent orchestration framework. At a high level, it provides a few major components:

§A Tour of Rigs

Rigs consists of a number of modules that provide a range of functionality essential for implementing agent-based applications in Rust. In this section, we will take a brief tour of Rigs, summarizing the major APIs and their uses.

§Working With Agents

At the core of Rigs is the concept of an agent. The agent module provides important tools for working with agents:

  • The Agent trait, which defines the core functionality that all agents must implement.
  • The AgentConfig struct and AgentConfigBuilder, for configuring agent behavior.
  • Error handling with AgentError for managing agent-related failures.

§Example: Creating a Basic Agent

use rigs::agent::{Agent, AgentConfig};
use rigs::rig_agent::RigAgentBuilder;
use rigs::llm_provider::LLMProvider;

// Create a configuration for our agent
let config = AgentConfig::builder()
    .agent_name("MyAssistant")
    .user_name("User")
    .description("A helpful assistant")
    .temperature(0.7)
    .max_tokens(2048)
    .build();

// Create a provider for the model
let provider = LLMProvider::deepseek("deepseek-chat");

// Build the agent with the configuration
let agent = RigAgent::deepseek_builder()
    .provider(provider)?
    .agent_name("MyAssistant")
    .user_name("User")
    .system_prompt("You are a helpful assistant.")
    .build()?;

§Handling Conversations

The conversation module provides tools for managing conversations between users and agents:

§Example: Managing a Conversation

use rigs::conversation::{Conversation, Role, Content};

// Create a new conversation with an agent
let mut conversation = Conversation::new("MyAssistant".to_string());

// Add messages to the conversation
conversation.add(Role::User("User".to_string()), "Hello, how are you?".to_string());
conversation.add(Role::Assistant("MyAssistant".to_string()), "I'm doing well, thank you for asking!".to_string());

// Search for messages containing a keyword
let results = conversation.search("well");

§Orchestrating Workflows

The graph_workflow module provides a powerful system for creating complex agent workflows:

  • DAGWorkflow for defining directed acyclic graphs of agent interactions.
  • Tools for connecting agents and defining the flow of information between them.
  • Execution engines for running workflows with multiple starting agents.

§Example: Creating a Simple Workflow

use std::sync::Arc;
use rigs::graph_workflow::{DAGWorkflow, Flow};
use rigs::agent::Agent;

// Create a new workflow
let mut workflow = DAGWorkflow::new("MyWorkflow", "A simple workflow example");

// Register agents with the workflow
workflow.register_agent(Arc::new(agent1));
workflow.register_agent(Arc::new(agent2));
workflow.register_agent(Arc::new(agent3));

// Connect agents in the workflow
workflow.connect_agents("agent1", "agent2", Flow::default())
    .expect("Failed to connect agents");
workflow.connect_agents("agent1", "agent3", Flow::default())
    .expect("Failed to connect agents");

// Execute the workflow with multiple starting agents
let results = workflow.execute_workflow(&["agent1"], "Initial input")
    .await
    .expect("Failed to execute workflow");

§Data Persistence

The persistence module provides utilities for saving and loading data:

  • Functions for saving data to files and loading from files.
  • Compression and decompression utilities.
  • Error handling with PersistenceError.

§Example: Saving and Loading Data

use rigs::persistence;
use std::path::Path;

async fn example() -> Result<(), persistence::PersistenceError> {
    // Save data to a file
    let data = "Hello, world!";
    persistence::save_to_file(data.as_bytes(), Path::new("hello.txt")).await?;

    // Load data from a file
    let loaded_data = persistence::load_from_file(Path::new("hello.txt")).await?;
     
    // Compress data
    let compressed = persistence::compress(data.as_bytes())?;
     
    // Decompress data
    let decompressed = persistence::decompress(&compressed)?;
     
    Ok(())
}

§Pre-built Agent Implementations

The rig_agent module provides ready-to-use agent implementations:

  • RigAgent for creating agents based on the Rig framework.
  • RigAgentBuilder for configuring and building Rig agents.

§Team Workflows

The team_workflow module provides a higher-level abstraction for creating team-based workflows:

  • TeamWorkflow for defining team-based workflows with a leader agent.
  • Model registry for managing different LLM models.
  • Orchestration tools for dynamically creating and connecting agents.

For more examples, see the examples/ directory in the repository.

Re-exports§

pub use rig;

Modules§

agent
conversation
graph_workflow
Graph workflow implementation
llm_provider
persistence
rig_agent
team_workflow
Team workflow implementation

Traits§

ProviderClient

Attribute Macros§

tool