Skip to main content

Module tool_format

Module tool_format 

Source
Expand description

Provider tool formatters.

Each provider (or family) shapes ToolDefinition into the JSON it expects on the wire. Historically, this logic was scattered across the request builders of each provider crate, making it hard to verify cross-provider invariants (e.g. that defer_loading, strict, input_examples, allowed_callers are preserved when they apply). This module introduces a single trait that all providers can implement, plus ready-made implementations for the most common cases.

The trait is intentionally additive: existing callers can keep using the per-provider helpers (e.g. serialize_tools_openai_format, anthropic::request_builder::tools::build_tools). New callers should reach for formatter_for(provider_id, model) instead.

See The Hitchhiker’s Guide to Agentic AI §18.4.1 for the underlying model (separate OpenAI / Anthropic / Gemini / MCP wire shapes) and §18.4.2 for the selection / routing concerns that sit above this layer.

Structs§

AnthropicFormatter
Anthropic formatter — extracts logic from crates/codegen/vtcode-llm/src/providers/anthropic/request_builder/tools.rs::build_tools.
GeminiFormatter
Gemini formatter — uses function_declarations plus native hosted tool shapes.
OpenAIChatFormatter
OpenAI Chat Completions formatter — extracts logic from crates/codegen/vtcode-llm/src/providers/common.rs::serialize_tools_openai_format.
OpenAICompatibleFormatter
Generic OpenAI-compatible formatter. Unlike OpenAIChatFormatter, this one is intentionally conservative: it only emits function-shaped tools and silently drops hosted / native tool types because most compatible providers don’t support them.
OpenAIResponsesFormatter
OpenAI Responses API formatter — model-aware, preserves defer_loading.

Enums§

ProviderFamily
Identifies a provider family for the purpose of tool formatting.
ProviderFormatter
Static-dispatch formatter covering every provider family.

Traits§

ProviderToolFormatter
Trait implemented by every provider tool formatter.

Functions§

formatter
Build a formatter for a given provider family without heap allocation or dynamic dispatch.
formatter_for
Convenience: resolve a formatter using the explicit ProviderFamily. Useful in tests or when the runloop already knows the family without parsing the provider string.