pub struct Agent {
pub agent_id: String,
pub description: Option<String>,
pub state: AgentState,
pub record_direct_tool_call: bool,
pub trace_attributes: HashMap<String, String>,
pub max_tool_calls: Option<usize>,
/* private fields */
}Expand description
The main agent struct for conversational AI.
Fields§
§agent_id: String§description: Option<String>§state: AgentState§record_direct_tool_call: boolWhether to record direct tool calls in message history.
trace_attributes: HashMap<String, String>Custom trace attributes for OpenTelemetry.
max_tool_calls: Option<usize>Maximum number of tool calls per cycle (None = unlimited).
Implementations§
Source§impl Agent
impl Agent
Sourcepub fn builder() -> AgentBuilder
pub fn builder() -> AgentBuilder
Creates a new agent builder.
Sourcepub fn system_prompt(&self) -> Option<&str>
pub fn system_prompt(&self) -> Option<&str>
Returns the system prompt.
Sourcepub fn set_system_prompt(&mut self, prompt: impl Into<String>)
pub fn set_system_prompt(&mut self, prompt: impl Into<String>)
Sets the system prompt.
Sourcepub fn add_message(&mut self, message: Message)
pub fn add_message(&mut self, message: Message)
Adds a message to the conversation.
Sourcepub fn clear_messages(&mut self)
pub fn clear_messages(&mut self)
Clears all messages.
Sourcepub fn tool_registry(&self) -> &ToolRegistry
pub fn tool_registry(&self) -> &ToolRegistry
Returns the tool registry.
Sourcepub fn tool_registry_mut(&mut self) -> &mut ToolRegistry
pub fn tool_registry_mut(&mut self) -> &mut ToolRegistry
Returns a mutable reference to the tool registry.
Sourcepub fn tool_names(&self) -> Vec<&str>
pub fn tool_names(&self) -> Vec<&str>
Returns the names of all registered tools.
Sourcepub fn hooks(&self) -> &HookRegistry
pub fn hooks(&self) -> &HookRegistry
Returns the hooks registry.
Sourcepub fn hooks_mut(&mut self) -> &mut HookRegistry
pub fn hooks_mut(&mut self) -> &mut HookRegistry
Returns a mutable reference to the hooks registry.
Sourcepub fn conversation_manager(&self) -> &dyn ConversationManager
pub fn conversation_manager(&self) -> &dyn ConversationManager
Returns the conversation manager.
Sourcepub fn conversation_manager_mut(&mut self) -> &mut dyn ConversationManager
pub fn conversation_manager_mut(&mut self) -> &mut dyn ConversationManager
Returns a mutable reference to the conversation manager.
Sourcepub fn state(&self) -> &AgentState
pub fn state(&self) -> &AgentState
Returns a reference to the agent state.
Sourcepub fn state_mut(&mut self) -> &mut AgentState
pub fn state_mut(&mut self) -> &mut AgentState
Returns a mutable reference to the agent state.
Sourcepub fn interrupt_state(&self) -> &InterruptState
pub fn interrupt_state(&self) -> &InterruptState
Returns a reference to the interrupt state.
Sourcepub fn interrupt_state_mut(&mut self) -> &mut InterruptState
pub fn interrupt_state_mut(&mut self) -> &mut InterruptState
Returns a mutable reference to the interrupt state.
Sourcepub fn set_interrupt_state(&mut self, state: InterruptState)
pub fn set_interrupt_state(&mut self, state: InterruptState)
Sets the interrupt state.
Sourcepub fn is_interrupted(&self) -> bool
pub fn is_interrupted(&self) -> bool
Returns whether the agent is currently in an interrupt state.
Sourcepub fn set_messages(&mut self, messages: Messages)
pub fn set_messages(&mut self, messages: Messages)
Sets the messages directly.
Sourcepub fn tool(&mut self) -> ToolCaller<'_>
pub fn tool(&mut self) -> ToolCaller<'_>
Returns a tool caller for direct tool invocation.
This enables the pattern: agent.tool().invoke("tool_name", input).await
Sourcepub fn trace_attributes(&self) -> &HashMap<String, String>
pub fn trace_attributes(&self) -> &HashMap<String, String>
Returns the trace attributes.
Sourcepub fn set_trace_attribute(
&mut self,
key: impl Into<String>,
value: impl Into<String>,
)
pub fn set_trace_attribute( &mut self, key: impl Into<String>, value: impl Into<String>, )
Sets a trace attribute.
Sourcepub fn max_tool_calls(&self) -> Option<usize>
pub fn max_tool_calls(&self) -> Option<usize>
Returns the max tool calls setting.
Sourcepub fn set_max_tool_calls(&mut self, max: Option<usize>)
pub fn set_max_tool_calls(&mut self, max: Option<usize>)
Sets the max tool calls.
Sourcepub fn call(&mut self, prompt: impl Into<AgentInput>) -> Result<AgentResult>
pub fn call(&mut self, prompt: impl Into<AgentInput>) -> Result<AgentResult>
Invokes the agent synchronously (blocking).
Sourcepub async fn invoke_async(
&mut self,
prompt: impl Into<AgentInput>,
) -> Result<AgentResult>
pub async fn invoke_async( &mut self, prompt: impl Into<AgentInput>, ) -> Result<AgentResult>
Invokes the agent asynchronously.
Sourcepub async fn stream_async(
&mut self,
prompt: impl Into<AgentInput>,
) -> impl Stream<Item = Result<TypedEvent>> + '_
pub async fn stream_async( &mut self, prompt: impl Into<AgentInput>, ) -> impl Stream<Item = Result<TypedEvent>> + '_
Returns a stream of events from the agent.
Auto Trait Implementations§
impl Freeze for Agent
impl !RefUnwindSafe for Agent
impl Send for Agent
impl Sync for Agent
impl Unpin for Agent
impl !UnwindSafe for Agent
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<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