Skip to main content

ChatbotTool

Trait ChatbotTool 

Source
pub trait ChatbotTool: ChatbotToolDeclaration {
    type Arguments: DeserializeOwned;

    // Required methods
    fn call_requirements(
        arguments: &Self::Arguments,
        user_context: &ChatbotTurnContext,
    ) -> Vec<ToolRequirement>;
    fn from_db_and_arguments(
        conn: &mut PgConnection,
        app_config: &ApplicationConfiguration,
        arguments: Self::Arguments,
        user_context: &ChatbotTurnContext,
    ) -> impl Future<Output = ChatbotResult<Self>> + Send
       where Self: Sized;
    fn output(&self) -> String;
    fn output_description_instructions(&self) -> Option<String>;

    // Provided methods
    fn parse_arguments(args_string: String) -> ChatbotResult<Self::Arguments> { ... }
    fn citations(&self) -> Vec<ToolCitation> { ... }
    fn get_tool_output(&self) -> String { ... }
}

Required Associated Types§

Required Methods§

Source

fn call_requirements( arguments: &Self::Arguments, user_context: &ChatbotTurnContext, ) -> Vec<ToolRequirement>

What the caller must be allowed to do against what this call actually targets.

The model picks the target, so this is the check that binds; the tool must name every resource the call touches, since all of them are required. user_context is here for the tools whose arguments name a target only by omission, leaving it to default to the chatbot’s own course.

Source

fn from_db_and_arguments( conn: &mut PgConnection, app_config: &ApplicationConfiguration, arguments: Self::Arguments, user_context: &ChatbotTurnContext, ) -> impl Future<Output = ChatbotResult<Self>> + Send
where Self: Sized,

Create a new instance after parsing arguments

Source

fn output(&self) -> String

Output the result of the tool call in LLM-readable form

Source

fn output_description_instructions(&self) -> Option<String>

Additional instructions for the LLM on how to describe and communicate the tool output. Just-in-time prompt.

Provided Methods§

Source

fn parse_arguments(args_string: String) -> ChatbotResult<Self::Arguments>

Parses and validates the arguments the LLM called the tool with.

The LLM is free to emit values the schema forbids, so every constraint the tool body relies on has to be rejected here rather than assumed; the derived deserialization the default body does is only as strict as the argument type. Fails with ChatbotErrorType::InvalidToolArguments, which is reported to the LLM.

Source

fn citations(&self) -> Vec<ToolCitation>

Page references this call’s output cites, numbered as the tool told the model to cite them. Empty for a tool whose output is not quotable material.

Source

fn get_tool_output(&self) -> String

Get and format tool output and instructions for LLM

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§