Skip to main content

FunctionCallingAgent

Struct FunctionCallingAgent 

Source
pub struct FunctionCallingAgent { /* private fields */ }
Expand description

Function Calling Agent

An agent that uses the LLM’s native Function Calling. Does not rely on text parsing; handles tool_calls directly. Supports any LLM provider that implements BaseChatModel.

Implementations§

Source§

impl FunctionCallingAgent

Source

pub fn new<L>( llm: L, tools: Vec<Arc<dyn BaseTool>>, system_prompt: Option<String>, ) -> Self
where L: BaseChatModel + Send + Sync + 'static, L::Error: Into<ProviderError>,

Creates a new Function Calling Agent

§Parameters
  • llm - LLM client (any type implementing BaseChatModel)
  • tools - available tools
  • system_prompt - custom system prompt (optional)
§Backward compatibility

Legacy code FunctionCallingAgent::new(openai_chat, tools, None) still works, because OpenAIChat: BaseChatModel and OpenAIError: Into<Error>.

Source

pub fn from_arc( llm: Arc<dyn BaseChatModel<Error = ProviderError> + Send + Sync>, tools: Vec<Arc<dyn BaseTool>>, system_prompt: Option<String>, ) -> Self

Creates an agent from an already-wrapped Arc<dyn BaseChatModel>

For LLM instances already created via wrap_chat_model() or LLMClient.

Source

pub fn tools_count(&self) -> usize

Returns the number of tools

Source

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

Returns the system prompt

Trait Implementations§

Source§

impl BaseAgent for FunctionCallingAgent

Source§

fn plan_stream<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, intermediate_steps: &'life1 [AgentStep], inputs: &'life2 HashMap<String, String>, on_token: &'life3 mut (dyn FnMut(String) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send), config: Option<&'life4 RunnableConfig>, ) -> Pin<Box<dyn Future<Output = Result<AgentOutput, AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

Streaming plan (S2 + 0.20.0 S3.2): goes through stream_chat, forwarding model text token by token and accumulating usage and tool calls.

The function-calling agent’s final answer streams out as text token by token (typewriter effect). Tool-call steps now stream natively too: providers that support streaming tool_calls (OpenAI / Azure and their delegates) attach the complete tool calls to the terminal StreamChunk (StreamChunk.tool_calls), which plan_stream accumulates and converts into AgentOutput::Action/AgentOutput::Actions — no non-streaming fallback needed, so the agent loop does not emit a fake “empty Finish”. Mixed steps (text + tool calls) keep both: the text already streamed via on_token, the tool calls preserved here.

The non-streaming BaseAgent::plan fallback remains only as a safety net for: stream_chat failing immediately, or a provider that yields neither text nor tool_calls on the stream (e.g. one without streaming tool-call support when the model makes a tool call).

Source§

fn last_token_usage(&self) -> Option<TokenUsage>

Reports the token usage from the most recent plan() call (P1-5).

Source§

fn plan<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, intermediate_steps: &'life1 [AgentStep], inputs: &'life2 HashMap<String, String>, config: Option<&'life3 RunnableConfig>, ) -> Pin<Box<dyn Future<Output = Result<AgentOutput, AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Plans the next action. Read more
Source§

fn get_allowed_tools(&self) -> Option<Vec<&str>>

Returns allowed tools list.
Source§

fn input_keys(&self) -> Vec<&str>

Returns input keys.
Source§

fn return_stopped_response( &self, _intermediate_steps: &[AgentStep], ) -> AgentFinish

Returns stopped response when max iterations reached.
Source§

impl Debug for FunctionCallingAgent

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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: Sized + 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 = !

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

fn try_from(value: U) -> Result<T, !>

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