Module rig::agent

source ·
Expand description

This module contains the implementation of the Agent struct and its builder.

The Agent struct represents an LLM agent, which combines an LLM model with a preamble (system prompt), a set of context documents, and a set of static tools. The agent can be used to interact with the LLM model by providing prompts and chat history.

The AgentBuilder struct provides a builder pattern for creating instances of the Agent struct. It allows configuring the model, preamble, context documents, static tools, temperature, and additional parameters before building the agent.

Example usage:

use rig::{completion::Prompt, providers::openai};

let openai_client = openai::Client::from_env();

// Configure the agent
let agent = client.agent("gpt-4o")
    .preamble("System prompt")
    .context("Context document 1")
    .context("Context document 2")
    .tool(tool1)
    .tool(tool2)
    .temperature(0.8)
    .additional_params(json!({"foo": "bar"}))
    .build();

// Use the agent for completions and prompts
let completion_req_builder = agent.completion("Prompt", chat_history).await;
let chat_response = agent.chat("Prompt", chat_history).await;

For more information on how to use the Agent struct and its builder, refer to the documentation of the respective structs and methods.

Structs§

  • Struct reprensenting an LLM agent. An agent is an LLM model combined with a preamble (i.e.: system prompt) and a static set of context documents and tools. All context documents and tools are always provided to the agent when prompted.
  • A builder for creating an agent