Skip to main content

ClientChatbotTool

Trait ClientChatbotTool 

Source
pub trait ClientChatbotTool: ChatbotToolDeclaration {
    type Arguments;
    type Response;

    // Required methods
    fn call_requirements(
        arguments: &Self::Arguments,
        user_context: &ChatbotTurnContext,
    ) -> Vec<ToolRequirement>;
    fn parse_arguments(arguments: &str) -> ChatbotResult<Self::Arguments>;
    fn parse_response(
        arguments: &Self::Arguments,
        answer: &ClientToolAnswer,
    ) -> ChatbotResult<Self::Response>;
    fn output(arguments: &Self::Arguments, response: &Self::Response) -> String;
    fn output_description_instructions() -> Option<String>;

    // Provided method
    fn get_tool_output(
        arguments: &Self::Arguments,
        response: &Self::Response,
    ) -> String { ... }
}
Expand description

A tool whose output the client produces instead of server code.

The LLM calls it like any other tool, but the turn suspends: the call is recorded without an output, the client answers it through the tool-response endpoint, and that answer becomes the output the resumed turn reads.

Required Associated Types§

Source

type Arguments

The arguments of a call, as Self::parse_arguments has validated them.

Source

type Response

The client’s answer, as Self::parse_response has checked it against the call.

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. Checked before the turn suspends on the call and again when its answer arrives.

Source

fn parse_arguments(arguments: &str) -> 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 client and the rendering rely on has to be rejected here rather than assumed. Fails with ChatbotErrorType::InvalidToolArguments, which is reported to the LLM.

Source

fn parse_response( arguments: &Self::Arguments, answer: &ClientToolAnswer, ) -> ChatbotResult<Self::Response>

Parses the client’s answer to a call made with arguments.

The answer decides what the model is told the user said, so an implementor must check it against what arguments actually offered instead of trusting the client to keep to it. Fails with ChatbotErrorType::InvalidToolAnswer, the one chatbot error the client is told about.

Source

fn output(arguments: &Self::Arguments, response: &Self::Response) -> String

The answer in LLM-readable form.

Source

fn output_description_instructions() -> Option<String>

Just-in-time instructions for the LLM on what to do with the answer.

Provided Methods§

Source

fn get_tool_output( arguments: &Self::Arguments, response: &Self::Response, ) -> String

The tool output the resumed turn reads, with the answer delimited from the instructions about it.

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§