Agent

Struct Agent 

Source
pub struct Agent {
Show 30 fields pub name: String, pub model: String, pub history: Vec<Message>, pub local_tools: Option<Vec<Tool>>, pub mcp_servers: Option<Vec<McpServerType>>, pub tools: Option<Vec<Tool>>, pub response_format: Option<Value>, pub system_prompt: String, pub stop_prompt: Option<String>, pub stopword: Option<String>, pub strip_thinking: bool, pub temperature: Option<f32>, pub top_p: Option<f32>, pub presence_penalty: Option<f32>, pub frequency_penalty: Option<f32>, pub num_ctx: Option<u32>, pub repeat_last_n: Option<i32>, pub repeat_penalty: Option<f32>, pub seed: Option<i32>, pub stop: Option<String>, pub num_predict: Option<i32>, pub top_k: Option<u32>, pub min_p: Option<f32>, pub keep_alive: Option<String>, pub stream: bool, pub notification_channel: Option<Sender<Notification>>, pub template: Option<Arc<Mutex<Template>>>, pub max_iterations: Option<usize>, pub clear_history_on_invoke: bool, pub state: HashMap<String, Value>, /* private fields */
}

Fields§

§name: String

Human-readable name of the agent.

§model: String

Underlying model identifier.

§history: Vec<Message>

Conversation history with the model.

§local_tools: Option<Vec<Tool>>

Locally registered tools (before MCP merge).

§mcp_servers: Option<Vec<McpServerType>>

Configured MCP server endpoints.

§tools: Option<Vec<Tool>>

Fully compiled tool set (local + MCP).

§response_format: Option<Value>

JSON schema format for responses, if any.

§system_prompt: String

System prompt injected at the start of the conversation.

§stop_prompt: Option<String>

Optional stop prompt inserted on tool branches.

§stopword: Option<String>

Stopword to detect end of generation.

§strip_thinking: bool

Whether <think> blocks should be stripped from outputs.

§temperature: Option<f32>

Sampling temperature.

§top_p: Option<f32>

Nucleus sampling top-p parameter.

§presence_penalty: Option<f32>

Presence penalty parameter.

§frequency_penalty: Option<f32>

Frequency penalty parameter.

§num_ctx: Option<u32>

Maximum context window size.

§repeat_last_n: Option<i32>

Last-N window for repetition penalty.

§repeat_penalty: Option<f32>

Repetition penalty multiplier.

§seed: Option<i32>

RNG seed for reproducibility.

§stop: Option<String>

Hard stop sequence.

§num_predict: Option<i32>

Maximum tokens to predict.

§top_k: Option<u32>

Top-K sampling cutoff.

§min_p: Option<f32>

Minimum probability threshold.

§keep_alive: Option<String>

Keep alive - keep model in memory

§stream: bool

Whether to stream token notifications.

§notification_channel: Option<Sender<Notification>>

Notification channel for emitting agent events.

§template: Option<Arc<Mutex<Template>>>

Optional reusable template for prompt building.

§max_iterations: Option<usize>

Maximum allowed iterations during a conversation.

§clear_history_on_invoke: bool

If true, clears history on every invocation.

§state: HashMap<String, Value>

State for custom data

Implementations§

Source§

impl Agent

Source

pub async fn invoke_flow<T>(&mut self, prompt: T) -> Result<Message, AgentError>
where T: Into<String>,

Invoke the agent with a raw string prompt.

This is the most direct way to ask the agent something: the given prompt string it is conveterd to a user message and appended to history. It is passed through the configured Flow (either Default or Custom).

Returns the raw Message produced by the flow.

Source

pub async fn invoke_flow_structured_output<T, O>( &mut self, prompt: T, ) -> Result<O, AgentError>

Invoke the agent expecting structured JSON output.

Works like [invoke_flow], but attempts to deserialize the model’s response into type O which must be deserializable.

Use this when you constrain the response with a JSON schema (response_format) and want the result to be typed.

Source

pub async fn invoke_flow_with_template<K, V>( &mut self, template_data: HashMap<K, V>, ) -> Result<Message, AgentError>
where K: Into<String>, V: Into<String>,

Invoke the agent using a prompt compiled from a template.

The provided template_data is substituted into the configured Template before invoking the flow. This allows building prompts from reusable templates instead of raw strings.

Returns the raw Message produced by the flow.

Source

pub async fn invoke_flow_with_template_structured_output<K, V, O>( &mut self, template_data: HashMap<K, V>, ) -> Result<O, AgentError>
where K: Into<String>, V: Into<String>, O: DeserializeOwned,

Invoke the agent with a template and parse structured output.

Combines [invoke_flow_with_template] with [invoke_flow_structured_output]: first compiles the prompt from the agent’s Template and template_data, then invokes the flow and tries to deserialize the result into type O.

Use this when you constrain the response with a JSON schema (response_format) and want the result to be typed.

Source

pub fn clear_history(&mut self)

Reset conversation history to contain only the system prompt.

Source

pub fn save_history<P: AsRef<Path>>( &self, path: P, ) -> Result<(), Box<dyn Error>>

Persist the conversation history to disk in pretty-printed JSON.

Source

pub async fn new_notification_channel( &mut self, ) -> Result<Receiver<Notification>, AgentError>

Create a new notification channel for this agent.

This re-initializes MCP tool connections so they bind to the new channel.

Source

pub async fn get_compiled_tools( &self, ) -> Result<Option<Vec<Tool>>, AgentBuildError>

Build and return the tool set (local tools + MCP tools).

Source

pub async fn get_compiled_mcp_tools( &self, ) -> Result<Option<Vec<Tool>>, AgentBuildError>

Build tool definitions from configured MCP servers.

Source

pub fn get_tool_ref_by_name<T>(&self, name: T) -> Option<&Tool>
where T: Into<String>,

Find a tool reference by name, if it exists.

Source

pub fn export_client_config(&self) -> ClientConfig

Export current client configuration (provider, base URL, keys, etc.).

Source

pub fn export_model_config(&self) -> ModelConfig

Export current model configuration (temperature, top_p, penalties, etc.).

Source

pub async fn export_prompt_config(&self) -> Result<PromptConfig, Error>

Export prompt-level configuration (system prompt, tools, template, etc.).

Trait Implementations§

Source§

impl Clone for Agent

Source§

fn clone(&self) -> Agent

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Agent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&Agent> for ChatRequest

Source§

fn from(val: &Agent) -> Self

Converts to this type from the input type.
Source§

impl NotificationHandler for Agent

Source§

fn get_outgoing_channel(&self) -> &Option<Sender<Notification>>

Source§

fn get_channel_name(&self) -> &String

Source§

async fn notify(&self, content: NotificationContent) -> bool

Send a notification with the given content. Read more
Source§

fn forward_notifications(&self, from_channel: Receiver<Notification>)

Forward notifications from an external receiver into this agent’s notification output channel.
Source§

fn forward_multiple_notifications<I>(&self, channels: I)

Merge any number of Receiver<Notification> streams into one, and forward all messages into this agent’s notification output channel.
Source§

async fn notify_done(&self, success: Success, resp: Response) -> bool

Source§

async fn notify_prompt_request(&self, req: ChatRequest) -> bool

Source§

async fn notify_poompt_success(&self, resp: ChatResponse) -> bool

Source§

async fn notify_prompt_error(&self, error_message: String) -> bool

Source§

async fn notify_tool_request(&self, tool_call: ToolCall) -> bool

Source§

async fn notify_tool_success(&self, tool_result: String) -> bool

Source§

async fn notify_tool_error(&self, error_message: String) -> bool

Source§

async fn notify_token(&self, token: Token) -> bool

Source§

async fn notify_mcp_tool_notification(&self, notification: String) -> bool

Source§

async fn notify_custom(&self, custom_val: Value) -> bool

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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<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,