Module tools

Module tools 

Source
Expand description

Tool helpers for ergonomic tool use with the ModelRelay API.

Structs§

RetryOptions
Options for the execute_with_retry function.
ToolArgsError
Error returned when tool argument parsing or validation fails. Contains a descriptive message suitable for sending back to the model.
ToolCallAccumulator
Accumulates streaming tool call deltas into complete tool calls.
ToolExecutionResult
Result of executing a tool call.
ToolRegistry
Registry for mapping tool names to handler functions with automatic dispatch.
UnknownToolError
Error returned when a tool is not found in the registry.

Traits§

ProxyResponseExt
Extension trait for ProxyResponse with tool-related convenience methods.
ToolSchema
Trait extension for types that implement JsonSchema to easily convert to a Tool.
ValidateArgs
Trait for types that can validate themselves after parsing.

Functions§

assistant_message_with_tool_calls
Creates an assistant message that includes tool calls.
create_retry_messages
Creates tool result messages for retryable errors, suitable for sending back to the model to prompt a retry.
execute_with_retry
Executes tool calls with automatic retry for malformed arguments.
format_tool_error_for_model
Formats a tool execution error for sending back to the model.
function_tool_from_type
Creates a function tool from a type that implements schemars::JsonSchema.
get_retryable_errors
Filters the results to only those with retryable errors.
has_retryable_errors
Returns true if any of the results have a retryable error.
parse_and_validate_tool_args
Parses, deserializes, and validates tool call arguments.
parse_tool_args
Parses and deserializes tool call arguments into the specified type.
respond_to_tool_call
Creates a tool result message from a ToolCall.
respond_to_tool_call_json
Creates a tool result message from a ToolCall with JSON serialization.
sync_handler
Creates a tool handler from a synchronous function. The function receives parsed JSON arguments and returns a JSON-serializable result.
tool_result_message
Creates a message containing the result of a tool call.
tool_result_message_json
Creates a tool result message with JSON serialization.

Type Aliases§

BoxFuture
A boxed future type for async tool handlers.
ParseResult
Result type for try_parse_tool_args.
ToolHandler
Handler function type for tool execution. Receives parsed JSON arguments and the original tool call. Returns a JSON-serializable result or an error message.