blob: fd1022dad994fd87a947c2e8882e9e691436feac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Package provider defines a provider-neutral chat/tool-use interface. It is
// independent of any one wire format (OpenAI-compatible, Anthropic Messages,
// Gemini, etc.) so that internal/agentloop's tool-use control flow can drive
// any backend that implements Provider.
//
// Phase 1 ships exactly one implementation, internal/provider/openaicompat,
// which adapts the existing internal/llm.Client. Later phases add native
// Anthropic/OpenAI/Google/Groq/OpenRouter adapters without touching agentloop.
package provider
import "context"
// Message is one turn in a chat conversation, in provider-neutral shape.
type Message struct {
Role string // "system" | "user" | "assistant" | "tool"
Text string
ToolCalls []ToolCall // set on assistant turns that invoke tools
ToolResults []ToolResult // set on tool-result turns
}
// ToolCall is a single tool invocation requested by the model.
type ToolCall struct {
ID string
Name string
ArgsJSON string
}
// ToolResult is the outcome of executing a ToolCall, fed back to the model.
type ToolResult struct {
ToolCallID string
Name string
Content string
IsError bool
}
// ToolSpec declares a tool the model may call.
type ToolSpec struct {
Name string
Description string
ParametersJSONSchema map[string]any
}
// ChatRequest captures the parameters of a single chat completion call.
type ChatRequest struct {
Model string
System string
Messages []Message
Tools []ToolSpec
Temperature *float64
MaxTokens int
}
// Usage reports token accounting and (when known) cost for a single call.
type Usage struct {
InputTokens int
OutputTokens int
CostUSD float64
}
// ChatResponse is the aggregated result of a chat completion.
type ChatResponse struct {
Text string
ToolCalls []ToolCall
StopReason string
Usage Usage
}
// Provider is a chat/tool-use backend: one per LLM vendor/wire-format.
type Provider interface {
Name() string
Chat(ctx context.Context, req ChatRequest) (*ChatResponse, error)
}
|