Documentation
¶
Overview ¶
Package talk defines the protocol types for LLM communication and provides provider adapters in sub-packages. Each sub-package implements talk.LLMClient for a specific backend, translating provider-agnostic types into native API calls.
Class: primitive UseWhen: Always required with axon-loop. For CLI agents, use axon-hand instead which provides axon-talk automatically.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ImageContent ¶ added in v0.13.0
ImageContent is an image attached to a user message for vision models. Data is the raw image bytes, base64-encoded; MediaType is the MIME type (e.g. "image/jpeg"). Adapters that do not support images ignore these.
type LLMClient ¶
LLMClient abstracts communication with an LLM backend. Implementations translate to/from provider-specific APIs (e.g. Ollama, OpenAI, Anthropic).
type Message ¶
type Message struct {
Role Role
Content string
Images []ImageContent // Inline images for a vision request; only meaningful on a user message.
Thinking string
ToolCalls []ToolCall
ToolCallID string // Correlates a tool result with its originating ToolCall.
}
Message represents a single message in a conversation.
Example ¶
package main
import (
"fmt"
talk "github.com/benaskins/axon-talk"
)
func main() {
user := talk.Message{
Role: talk.RoleUser,
Content: "Explain goroutines in one sentence.",
}
assistant := talk.Message{
Role: talk.RoleAssistant,
Content: "Goroutines are lightweight, cooperatively scheduled threads managed by the Go runtime.",
}
fmt.Println(user.Role)
fmt.Println(assistant.Role)
}
Output: user assistant
type Request ¶
type Request struct {
Model string
Messages []Message
Tools []tool.ToolDef
Stream bool
Think *bool
Options map[string]any
MaxIterations int // Maximum tool-call loop iterations. Defaults to 20 if 0.
MaxTokens int // Maximum estimated token budget for messages. 0 means no limit.
}
Request is a provider-agnostic request to an LLM.
func NewRequest ¶
func NewRequest(model string, messages []Message, opts ...RequestOption) *Request
NewRequest creates a Request with the given model, messages, and options.
Example ¶
package main
import (
"fmt"
talk "github.com/benaskins/axon-talk"
)
func main() {
req := talk.NewRequest("claude-sonnet-4-20250514", []talk.Message{
{Role: talk.RoleSystem, Content: "You are a helpful assistant."},
{Role: talk.RoleUser, Content: "What is the capital of France?"},
})
fmt.Println(req.Model)
fmt.Println(len(req.Messages), "messages")
}
Output: claude-sonnet-4-20250514 2 messages
type RequestOption ¶
type RequestOption func(*Request)
RequestOption configures a Request.
func WithStructuredOutput ¶ added in v0.6.0
func WithStructuredOutput(schema map[string]any) RequestOption
WithStructuredOutput returns a RequestOption that requests the LLM to respond with JSON conforming to the given schema. Each adapter translates this to its provider-specific wire format.
type Response ¶
type Response struct {
Content string
Thinking string
Done bool
ToolCalls []ToolCall
Usage *Usage // non-nil on the final chunk (Done=true) when the provider reports it
}
Response is a provider-agnostic streamed response chunk from an LLM.
type StatusError ¶ added in v0.5.1
StatusError is returned by adapters when the provider API responds with a non-OK HTTP status. It carries the status code so callers (e.g. retry middleware) can make decisions based on it.
func (*StatusError) Error ¶ added in v0.5.1
func (e *StatusError) Error() string
type ToolCall ¶
type ToolCall struct {
ID string // Provider-assigned correlation ID (e.g. OpenAI tool_call_id).
Name string
Arguments map[string]any
}
ToolCall represents an LLM's decision to invoke a tool.
type Usage ¶ added in v0.10.0
type Usage struct {
InputTokens int
OutputTokens int
// Cache stats (zero when the provider does not support caching).
CacheCreationInputTokens int
CacheReadInputTokens int
}
Usage reports token consumption for a single LLM call.
func (Usage) TotalTokens ¶ added in v0.10.0
TotalTokens returns InputTokens + OutputTokens.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package anthropic provides a talk.LLMClient implementation for the Anthropic Messages API.
|
Package anthropic provides a talk.LLMClient implementation for the Anthropic Messages API. |
|
Package bedrock provides a talk.LLMClient implementation for Anthropic Claude models served through Amazon Bedrock's InvokeModel API.
|
Package bedrock provides a talk.LLMClient implementation for Anthropic Claude models served through Amazon Bedrock's InvokeModel API. |
|
Package openai provides a talk.LLMClient implementation for any OpenAI-compatible chat completions API.
|
Package openai provides a talk.LLMClient implementation for any OpenAI-compatible chat completions API. |