Agent

Struct Agent 

Source
pub struct Agent<M: Completion> {
Show 13 fields pub model: Ref<M>, pub store_indices: Vec<(usize, Box<dyn Storage>)>, pub tools: Ref<Vec<Box<dyn Tool>>>, pub knowledges: Arc<Vec<Box<dyn Knowledge>>>, pub memory: Option<Ref<dyn Memory>>, pub id: Uuid, pub name: String, pub preamble: String, pub temperature: Option<f32>, pub max_tokens: Option<usize>, pub max_execution_time: Option<usize>, pub respect_context_window: bool, pub allow_code_execution: bool, /* private fields */
}

Fields§

§model: Ref<M>

The model to use.

§store_indices: Vec<(usize, Box<dyn Storage>)>

Indexed storage for the agent.

§tools: Ref<Vec<Box<dyn Tool>>>

The tools to use.

§knowledges: Arc<Vec<Box<dyn Knowledge>>>

Knowledge sources for the agent.

§memory: Option<Ref<dyn Memory>>

Agent memory.

§id: Uuid

The unique ID of the agent.

§name: String

The name of the agent.

§preamble: String

System prompt for the agent.

§temperature: Option<f32>

Temperature of the model.

§max_tokens: Option<usize>

Maximum number of tokens for the completion.

§max_execution_time: Option<usize>

Maximum execution time for the agent to complete a task.

§respect_context_window: bool

Whether to respect the context window.

§allow_code_execution: bool

Whether code execution is allowed.

Implementations§

Source§

impl<M> Agent<M>
where M: Completion,

Source

pub fn new(name: impl ToString, model: M) -> Agent<M>

Creates a new agent.

Source

pub fn new_with_tools<I>(name: impl ToString, model: M, tools: I) -> Agent<M>
where I: IntoIterator<Item = Box<dyn Tool>>,

Creates a new agent with some tools

Source

pub async fn tool(self, tool: impl Tool + 'static) -> Self

Add a tool into the agent

Source

pub async fn tools<I>(self, tools: I) -> Self
where I: IntoIterator<Item = Box<dyn Tool>>,

Add some tools into the agent

Source

pub fn memory(self, memory: impl Memory + 'static) -> Self

Adds a memory to the agent.

Source

pub fn store_index(self, sample: usize, store: impl Storage + 'static) -> Self

Adds a storage index to the agent.

Source

pub fn preamble(self, preamble: impl ToString) -> Self

System prompt for the agent.

Source

pub async fn mcp_client(self, mcp_client: MCPClient) -> Self

Set the MCP client.

Source

pub async fn mcp_config_path<P: AsRef<Path>>( self, path: P, ) -> Result<Self, MCPError>

Set the MCP server config path.

Source

pub async fn mcp_sse_client<S: AsRef<str> + 'static>( self, sse_url: S, env: HashMap<String, String>, ) -> Result<Self>

Set the MCP sse client.

Source

pub async fn mcp_stdio_client<S: AsRef<str> + 'static>( self, command: S, args: Vec<S>, env: HashMap<String, String>, ) -> Result<Self>

Set the MCP sse client.

Source

pub async fn prompt(&self, prompt: &str) -> Result<String, TaskError>

Processes a prompt using the agent.

Source

pub async fn chat( &self, prompt: &str, history: Vec<Message>, ) -> Result<String, TaskError>

Processes a prompt using the agent.

Auto Trait Implementations§

§

impl<M> Freeze for Agent<M>

§

impl<M> !RefUnwindSafe for Agent<M>

§

impl<M> Send for Agent<M>
where M: Send + Sync,

§

impl<M> Sync for Agent<M>
where M: Send + Sync,

§

impl<M> Unpin for Agent<M>

§

impl<M> !UnwindSafe for Agent<M>

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> 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<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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, 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
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T
where T: Send + Sync,