Agent

Struct Agent 

Source
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: bool

Whether 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

Source

pub fn builder() -> AgentBuilder

Creates a new agent builder.

Source

pub fn name(&self) -> Option<&String>

Returns the agent name.

Source

pub fn set_name(&mut self, name: impl Into<String>)

Sets the agent name.

Source

pub fn system_prompt(&self) -> Option<&str>

Returns the system prompt.

Source

pub fn set_system_prompt(&mut self, prompt: impl Into<String>)

Sets the system prompt.

Source

pub fn messages(&self) -> &Messages

Returns the current messages.

Source

pub fn add_message(&mut self, message: Message)

Adds a message to the conversation.

Source

pub fn clear_messages(&mut self)

Clears all messages.

Source

pub fn tool_registry(&self) -> &ToolRegistry

Returns the tool registry.

Source

pub fn tool_registry_mut(&mut self) -> &mut ToolRegistry

Returns a mutable reference to the tool registry.

Source

pub fn tool_names(&self) -> Vec<&str>

Returns the names of all registered tools.

Source

pub fn agent_id(&self) -> Option<&str>

Returns the agent ID.

Source

pub fn hooks(&self) -> &HookRegistry

Returns the hooks registry.

Source

pub fn hooks_mut(&mut self) -> &mut HookRegistry

Returns a mutable reference to the hooks registry.

Source

pub fn conversation_manager(&self) -> &dyn ConversationManager

Returns the conversation manager.

Source

pub fn conversation_manager_mut(&mut self) -> &mut dyn ConversationManager

Returns a mutable reference to the conversation manager.

Source

pub fn state(&self) -> &AgentState

Returns a reference to the agent state.

Source

pub fn state_mut(&mut self) -> &mut AgentState

Returns a mutable reference to the agent state.

Source

pub fn interrupt_state(&self) -> &InterruptState

Returns a reference to the interrupt state.

Source

pub fn interrupt_state_mut(&mut self) -> &mut InterruptState

Returns a mutable reference to the interrupt state.

Source

pub fn set_interrupt_state(&mut self, state: InterruptState)

Sets the interrupt state.

Source

pub fn is_interrupted(&self) -> bool

Returns whether the agent is currently in an interrupt state.

Source

pub fn set_messages(&mut self, messages: Messages)

Sets the messages directly.

Source

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

Source

pub fn trace_attributes(&self) -> &HashMap<String, String>

Returns the trace attributes.

Source

pub fn set_trace_attribute( &mut self, key: impl Into<String>, value: impl Into<String>, )

Sets a trace attribute.

Source

pub fn max_tool_calls(&self) -> Option<usize>

Returns the max tool calls setting.

Source

pub fn set_max_tool_calls(&mut self, max: Option<usize>)

Sets the max tool calls.

Source

pub fn call(&mut self, prompt: impl Into<AgentInput>) -> Result<AgentResult>

Invokes the agent synchronously (blocking).

Source

pub async fn invoke_async( &mut self, prompt: impl Into<AgentInput>, ) -> Result<AgentResult>

Invokes the agent asynchronously.

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more