Documentation
¶
Index ¶
- func NormalizeToolArguments(raw json.RawMessage) json.RawMessage
- func ProfileSupports(profile Profile, capability Capability, defaults ...Capability) bool
- type APIError
- type Capability
- type ChatChunk
- type ChatRequest
- type ChatResponse
- type Chatter
- type ChunkKind
- type Embedder
- type Gateway
- type Message
- type Profile
- type Role
- type Streamer
- type StructuredOutputter
- type ThinkingConfig
- type TokenUsage
- type ToolCall
- type ToolCallRequest
- type ToolCallResponse
- type ToolCallStreamer
- type ToolCaller
- type ToolSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NormalizeToolArguments ¶ added in v0.4.0
func NormalizeToolArguments(raw json.RawMessage) json.RawMessage
NormalizeToolArguments returns tool-call arguments that are always valid JSON.
Providers often deliver arguments as a JSON string (possibly empty) or as a raw object. Streaming models may also truncate mid-object. Empty or whitespace-only input becomes {}, matching the OpenAI empty-arguments convention. Malformed/truncated payloads also become {}: json.RawMessage must be valid JSON or json.Marshal fails with "error calling MarshalJSON for type json.RawMessage: unexpected end of JSON input", which aborts HITL checkpoint persistence before the tool can validate input.
func ProfileSupports ¶
func ProfileSupports(profile Profile, capability Capability, defaults ...Capability) bool
Types ¶
type Capability ¶
type Capability int
const ( CapChat Capability = iota CapToolCall CapStructuredOutput CapStream CapEmbed )
func CapabilitiesFromStrings ¶
func CapabilitiesFromStrings(values []string) []Capability
func ParseCapability ¶
func ParseCapability(value string) (Capability, bool)
func (Capability) String ¶
func (c Capability) String() string
type ChatChunk ¶
type ChatChunk struct {
Kind ChunkKind `json:"kind,omitempty"`
Content string `json:"content,omitempty"`
Done bool `json:"done,omitempty"`
Error string `json:"error,omitempty"`
// Err carries the structured provider error behind Error when one exists,
// so retry classification (e.g. APIError.Retryable) survives the streaming
// path instead of being flattened into an opaque string. It is process-local
// only and never serialized.
Err error `json:"-"`
Usage TokenUsage `json:"usage,omitempty"`
Paused bool `json:"paused,omitempty"`
PauseToken string `json:"pause_token,omitempty"`
PauseKind string `json:"pause_kind,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
ToolName string `json:"tool_name,omitempty"`
ToolInput json.RawMessage `json:"tool_input,omitempty"`
ToolOutput json.RawMessage `json:"tool_output,omitempty"`
ToolError string `json:"tool_error,omitempty"`
ToolProgress json.RawMessage `json:"tool_progress,omitempty"`
}
func (ChatChunk) IsAnswerContent ¶ added in v0.3.0
IsAnswerContent reports whether this chunk contributes to the final answer text aggregated by Engine.Stream. Tool progress/result events must not.
type ChatRequest ¶
type ChatRequest struct {
Messages []Message `json:"messages"`
Temperature *float32 `json:"temperature,omitempty"`
TopP *float32 `json:"top_p,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
Thinking ThinkingConfig `json:"thinking,omitempty"`
ReasoningEffort string `json:"reasoning_effort,omitempty"`
ExtraBody map[string]any `json:"extra_body,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
type ChatResponse ¶
type ChatResponse struct {
Message Message `json:"message"`
Usage TokenUsage `json:"usage"`
FinishReason string `json:"finish_reason,omitempty"`
Raw json.RawMessage `json:"raw,omitempty"`
}
type Chatter ¶
type Chatter interface {
Chat(ctx context.Context, profile string, req ChatRequest) (ChatResponse, error)
}
type ChunkKind ¶ added in v0.3.0
type ChunkKind string
ChunkKind discriminates Stream progress events. Empty Kind is treated as answer content for backward compatibility with provider token streams.
type Message ¶
type Message struct {
Role Role `json:"role"`
Content string `json:"content,omitempty"`
ReasoningContent string `json:"reasoning_content,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
Name string `json:"name,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
func NormalizeMessageToolInputs ¶ added in v0.4.0
NormalizeMessageToolInputs returns a shallow copy of messages whose assistant tool-call inputs are normalized for safe JSON marshaling (checkpoints, iteration snapshots). Messages without tool calls are reused as-is.
type Profile ¶
type Profile struct {
Name string `json:"name"`
Provider string `json:"provider"`
Model string `json:"model"`
Endpoint string `json:"endpoint,omitempty"`
APIKeyEnv string `json:"api_key_env,omitempty"`
ContextWindowTokens int `json:"context_window_tokens,omitempty"`
MaxOutputTokens int `json:"max_output_tokens,omitempty"`
Temperature *float32 `json:"temperature,omitempty"`
TopP *float32 `json:"top_p,omitempty"`
Timeout time.Duration `json:"timeout,omitempty"`
Thinking ThinkingConfig `json:"thinking,omitempty"`
ReasoningEffort string `json:"reasoning_effort,omitempty"`
Context contextwindow.Policy `json:"context,omitempty"`
ExtraBody map[string]any `json:"extra_body,omitempty"`
Capabilities []Capability `json:"capabilities,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
type StructuredOutputter ¶
type StructuredOutputter interface {
StructuredChat(ctx context.Context, profile string, schema json.RawMessage, req ChatRequest) (json.RawMessage, error)
}
type ThinkingConfig ¶
type TokenUsage ¶
type ToolCall ¶
type ToolCall struct {
ID string `json:"id"`
Name string `json:"name"`
Input json.RawMessage `json:"input,omitempty"`
}
func NormalizeToolCallInputs ¶ added in v0.4.0
NormalizeToolCallInputs rewrites every ToolCall.Input with NormalizeToolArguments.
type ToolCallRequest ¶
type ToolCallRequest struct {
ChatRequest
Tools []ToolSpec `json:"tools,omitempty"`
}
type ToolCallResponse ¶
type ToolCallResponse struct {
ChatResponse
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
}
type ToolCallStreamer ¶ added in v0.3.0
type ToolCallStreamer interface {
StreamChatWithTools(ctx context.Context, profile string, req ToolCallRequest) (<-chan ChatChunk, error)
}
ToolCallStreamer streams a tool-enabled chat turn. Content can precede ChunkKindToolCall frames, so consumers must classify the completed turn before committing content as a final answer.
type ToolCaller ¶
type ToolCaller interface {
ChatWithTools(ctx context.Context, profile string, req ToolCallRequest) (ToolCallResponse, error)
}