Expand description
Universal LLM provider abstraction with API-specific role handling
This module provides a unified interface for different LLM providers (OpenAI, Anthropic, Gemini) while properly handling their specific requirements for message roles and tool calling.
§Message Role Mapping
Different LLM providers have varying support for message roles, especially for tool calling:
§OpenAI API
- Full Support:
system,user,assistant,tool - Tool Messages: Must include
tool_call_idto reference the original tool call - Tool Calls: Only
assistantmessages can containtool_calls
§Anthropic API
- Standard Roles:
user,assistant - System Messages: Can be hoisted to system parameter or treated as user messages
- Tool Responses: Converted to
usermessages (no separate tool role) - Tool Choice: Supports
auto,any,tool,nonemodes
§Gemini API
- Conversation Roles: Only
userandmodel(notassistant) - System Messages: Handled separately as
systemInstructionparameter - Tool Responses: Converted to
usermessages withfunctionResponseformat - Function Calls: Uses
functionCallinmodelmessages
§Best Practices
- Always use
MessageRole::tool_response()constructor for tool responses - Validate messages using
validate_for_provider()before sending - Use appropriate role mapping methods for each provider
- Handle provider-specific constraints (e.g., Gemini’s system instruction requirement)
§Example Usage
use vtcode_core::llm::provider::{Message, MessageRole};
// Create a proper tool response message
let tool_response = Message::tool_response(
"call_123".to_string(),
"Tool execution completed successfully".to_string()
);
// Validate for specific provider
tool_response.validate_for_provider("openai").unwrap();Structs§
- Anthropic
Request Overrides - Coding
Agent Settings - Settings to refine model behavior for coding agent tasks
- Function
Call - Function call within a tool call
- Function
Definition - Function definition within a tool
- Grammar
Definition - Grammar definition for GPT-5 context-free grammar (CFG) constraints
- LLMError
Metadata - LLMRequest
- Universal LLM request structure
- LLMResponse
- Universal LLM response structure
- Message
- Universal message structure supporting both text and image content
- Parallel
Tool Config - Configuration for parallel tool use behavior Based on Anthropic’s parallel tool use guidelines
- Prepared
Responses Request - Provider
Capabilities - Cached provider capabilities to reduce repeated trait method calls
- Responses
Compaction Options - Optional overrides for standalone Responses compaction requests.
- Responses
Continuation State - Shell
Tool Definition - Shell tool definition for GPT-5.1 shell tool type Allows controlled command-line interface interactions
- Specific
Function Choice - Specific function choice details
- Specific
Tool Choice - Specific tool choice for forcing a particular function call
- Tool
Call - Universal tool call that matches OpenAI/Anthropic/Gemini specifications
- Tool
Definition - Universal tool definition that matches OpenAI/Anthropic/Gemini specifications Based on official API documentation from Context7
- Usage
Enums§
- Anthropic
Optional String Override - Anthropic
Optional U32Override - Anthropic
Thinking Display Override - Anthropic
Thinking Mode Override - Assistant
Phase - Phase metadata for assistant messages in multi-step Responses-style workflows.
- Content
Part - Content type for messages that can include both text and images
- Finish
Reason - LLMError
- LLM error types with optional provider metadata
- LLMStream
Event - Message
Content - Message
Role - Normalized
Stream Event - Prompt
Cache Profile - Tool
Choice - Tool choice configuration that works across different providers Based on OpenAI, Anthropic, and Gemini API specifications Follows Anthropic’s tool use best practices for optimal performance
- Tool
Search Algorithm - Tool search algorithm for Anthropic’s advanced-tool-use beta
Traits§
- LLMProvider
- Universal LLM provider trait
Functions§
- get_
cached_ capabilities - Extract and cache provider capabilities for a given provider and model
- prepare_
openai_ responses_ request - prepare_
responses_ continuation_ request - responses_
continuation_ key - supports_
responses_ chaining - uses_
incremental_ responses_ history