Provider trait defines the interface for all LLM providers in ZeroClaw. Implement this trait to integrate new language model APIs into the framework.
Trait Definition
Required Methods
chat_with_system
One-shot chat with optional system prompt. This is the only required method - all other methods have default implementations.
Option<&str>
Optional system prompt to guide the model’s behavior
&str
required
The user message to send to the model
&str
required
Model identifier (e.g., “claude-3-5-sonnet-20241022”, “gpt-4”)
f64
required
Sampling temperature (typically 0.0-1.0)
anyhow::Result<String>
The model’s response text, or an error
Optional Methods with Defaults
capabilities
Declare what features this provider supports.
ProviderCapabilities
false.
convert_tools
Convert unified tool specifications to provider-native format.
&[ToolSpec]
required
Array of tool specifications in unified format
ToolsPayload
Provider-specific tool payload format:
ToolsPayload::Gemini- Gemini functionDeclarations formatToolsPayload::Anthropic- Anthropic tools formatToolsPayload::OpenAI- OpenAI tools formatToolsPayload::PromptGuided- Text-based fallback (injected into system prompt)
ToolsPayload::PromptGuided with formatted instructions.
simple_chat
Simple one-shot chat without system prompt.
&str
required
User message
&str
required
Model identifier
f64
required
Sampling temperature
chat_with_system with None as system prompt.
chat_with_history
Multi-turn conversation with message history.
&[ChatMessage]
required
Array of chat messages with roles (system, user, assistant, tool)
&str
required
Model identifier
f64
required
Sampling temperature
chat_with_system.
chat
Structured chat API for agent loop callers. Handles tool injection.
ChatRequest<'_>
required
&str
required
Model identifier
f64
required
Sampling temperature
ChatResponse
chat_with_tools
Chat with native tool calling support.
&[ChatMessage]
required
Message history
&[serde_json::Value]
required
Provider-native tool definitions
&str
required
Model identifier
f64
required
Sampling temperature
chat_with_history and returns empty tool_calls vector.
supports_native_tools
Check if provider supports native function calling API.
Default: Returns capabilities().native_tool_calling.
supports_vision
Check if provider supports multimodal vision input.
Default: Returns capabilities().vision.
supports_streaming
Check if provider supports streaming responses.
Default: Returns false.
stream_chat_with_system
Streaming version of chat_with_system.
StreamOptions
stream_chat_with_history
Streaming version of chat_with_history.
Default: Extracts last message and delegates to stream_chat_with_system.
warmup
Warm up HTTP connection pool (TLS handshake, DNS, HTTP/2).
Default: No-op.
Types
ChatMessage
ChatMessage::system(content)- Create system messageChatMessage::user(content)- Create user messageChatMessage::assistant(content)- Create assistant messageChatMessage::tool(content)- Create tool result message
ToolCall
TokenUsage
NormalizedStopReason
NormalizedStopReason::from_openai_finish_reason(raw: &str)NormalizedStopReason::from_anthropic_stop_reason(raw: &str)NormalizedStopReason::from_bedrock_stop_reason(raw: &str)NormalizedStopReason::from_gemini_finish_reason(raw: &str)
Implementation Example
Factory Registration
After implementing the trait, register your provider in the factory:Best Practices
Security: Never log API keys, tokens, or sensitive request/response data. Use the security policy framework for credential handling.
Related
- Tool Trait - Implement tools for providers to call
- Channel Trait - Implement communication channels
- Configuration Reference - Configure providers in config.toml