#[non_exhaustive]pub struct Agent<M>where
M: CompletionModel,{
pub name: Option<String>,
pub description: Option<String>,
pub model: Arc<M>,
pub preamble: Option<String>,
pub static_context: Vec<Document>,
pub temperature: Option<f64>,
pub max_tokens: Option<u64>,
pub additional_params: Option<Value>,
pub tool_server_handle: ToolServerHandle,
pub dynamic_context: Arc<RwLock<Vec<(usize, Box<dyn VectorStoreIndexDyn>)>>>,
pub tool_choice: Option<ToolChoice>,
}
Expand description
Struct representing 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.
§Example
use rig::{completion::Prompt, providers::openai};
let openai = openai::Client::from_env();
let comedian_agent = openai
.agent("gpt-4o")
.preamble("You are a comedian here to entertain the user using humour and jokes.")
.temperature(0.9)
.build();
let response = comedian_agent.prompt("Entertain me!")
.await
.expect("Failed to prompt the agent");
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.name: Option<String>
Name of the agent used for logging and debugging
description: Option<String>
Agent description. Primarily useful when using sub-agents as part of an agent workflow and converting agents to other formats.
model: Arc<M>
Completion model (e.g.: OpenAI’s gpt-3.5-turbo-1106, Cohere’s command-r)
preamble: Option<String>
System prompt
static_context: Vec<Document>
Context documents always available to the agent
temperature: Option<f64>
Temperature of the model
max_tokens: Option<u64>
Maximum number of tokens for the completion
additional_params: Option<Value>
Additional parameters to be passed to the model
tool_server_handle: ToolServerHandle
§dynamic_context: Arc<RwLock<Vec<(usize, Box<dyn VectorStoreIndexDyn>)>>>
List of vector store, with the sample number
tool_choice: Option<ToolChoice>
Whether or not the underlying LLM should be forced to use a tool before providing a response.
Trait Implementations§
Source§impl<M> Chat for Agent<M>where
M: CompletionModel,
impl<M> Chat for Agent<M>where
M: CompletionModel,
Source§impl<M> Completion<M> for Agent<M>where
M: CompletionModel,
impl<M> Completion<M> for Agent<M>where
M: CompletionModel,
Source§async fn completion(
&self,
prompt: impl Into<Message> + WasmCompatSend,
chat_history: Vec<Message>,
) -> Result<CompletionRequestBuilder<M>, CompletionError>
async fn completion( &self, prompt: impl Into<Message> + WasmCompatSend, chat_history: Vec<Message>, ) -> Result<CompletionRequestBuilder<M>, CompletionError>
prompt
and chat_history
.
This function is meant to be called by the user to further customize the
request at prompt time before sending it. Read moreSource§impl<M> DiscordExt for Agent<M>
Available on crate feature discord-bot
only.
impl<M> DiscordExt for Agent<M>
discord-bot
only.Source§impl<M> Prompt for &Agent<M>where
M: CompletionModel,
impl<M> Prompt for &Agent<M>where
M: CompletionModel,
Source§fn prompt(
&self,
prompt: impl Into<Message> + WasmCompatSend,
) -> PromptRequest<'_, Standard, M, ()>
fn prompt( &self, prompt: impl Into<Message> + WasmCompatSend, ) -> PromptRequest<'_, Standard, M, ()>
Source§impl<M> Prompt for Agent<M>where
M: CompletionModel,
impl<M> Prompt for Agent<M>where
M: CompletionModel,
Source§fn prompt(
&self,
prompt: impl Into<Message> + WasmCompatSend,
) -> PromptRequest<'_, Standard, M, ()>
fn prompt( &self, prompt: impl Into<Message> + WasmCompatSend, ) -> PromptRequest<'_, Standard, M, ()>
Source§impl<M> StreamingChat<M, <M as CompletionModel>::StreamingResponse> for Agent<M>
impl<M> StreamingChat<M, <M as CompletionModel>::StreamingResponse> for Agent<M>
Source§fn stream_chat(
&self,
prompt: impl Into<Message> + WasmCompatSend,
chat_history: Vec<Message>,
) -> StreamingPromptRequest<M, ()>
fn stream_chat( &self, prompt: impl Into<Message> + WasmCompatSend, chat_history: Vec<Message>, ) -> StreamingPromptRequest<M, ()>
Source§impl<M> StreamingCompletion<M> for Agent<M>where
M: CompletionModel,
impl<M> StreamingCompletion<M> for Agent<M>where
M: CompletionModel,
Source§async fn stream_completion(
&self,
prompt: impl Into<Message> + WasmCompatSend,
chat_history: Vec<Message>,
) -> Result<CompletionRequestBuilder<M>, CompletionError>
async fn stream_completion( &self, prompt: impl Into<Message> + WasmCompatSend, chat_history: Vec<Message>, ) -> Result<CompletionRequestBuilder<M>, CompletionError>
Source§impl<M> StreamingPrompt<M, <M as CompletionModel>::StreamingResponse> for Agent<M>
impl<M> StreamingPrompt<M, <M as CompletionModel>::StreamingResponse> for Agent<M>
Source§fn stream_prompt(
&self,
prompt: impl Into<Message> + WasmCompatSend,
) -> StreamingPromptRequest<M, ()>
fn stream_prompt( &self, prompt: impl Into<Message> + WasmCompatSend, ) -> StreamingPromptRequest<M, ()>
Source§impl<M: CompletionModel> Tool for Agent<M>
impl<M: CompletionModel> Tool for Agent<M>
Source§type Error = PromptError
type Error = PromptError
Source§async fn definition(&self, _prompt: String) -> ToolDefinition
async fn definition(&self, _prompt: String) -> ToolDefinition
Auto Trait Implementations§
impl<M> Freeze for Agent<M>
impl<M> !RefUnwindSafe for Agent<M>
impl<M> Send for Agent<M>
impl<M> Sync for Agent<M>
impl<M> Unpin for Agent<M>
impl<M> !UnwindSafe for Agent<M>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CloneableStorage for T
impl<T> CloneableStorage for T
fn clone_storage(&self) -> Box<dyn CloneableStorage>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more