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
impl FunctionCallingAgent
Sourcepub fn new<L>(
llm: L,
tools: Vec<Arc<dyn BaseTool>>,
system_prompt: Option<String>,
) -> Self
pub fn new<L>( llm: L, tools: Vec<Arc<dyn BaseTool>>, system_prompt: Option<String>, ) -> Self
Creates a new Function Calling Agent
§Parameters
llm- LLM client (any type implementingBaseChatModel)tools- available toolssystem_prompt- custom system prompt (optional)
§Backward compatibility
Legacy code FunctionCallingAgent::new(openai_chat, tools, None) still works,
because OpenAIChat: BaseChatModel and OpenAIError: Into<Error>.
Sourcepub fn from_arc(
llm: Arc<dyn BaseChatModel<Error = ProviderError> + Send + Sync>,
tools: Vec<Arc<dyn BaseTool>>,
system_prompt: Option<String>,
) -> Self
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.
Sourcepub fn tools_count(&self) -> usize
pub fn tools_count(&self) -> usize
Returns the number of tools
Sourcepub fn system_prompt(&self) -> Option<&str>
pub fn system_prompt(&self) -> Option<&str>
Returns the system prompt
Trait Implementations§
Source§impl BaseAgent for FunctionCallingAgent
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,
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>
fn last_token_usage(&self) -> Option<TokenUsage>
Reports the token usage from the most recent plan() call (P1-5).