Documentation
¶
Overview ¶
Package provider adapts model providers to one request/response shape. Adapters run inside the "model" action, never in workflow code.
Index ¶
Constants ¶
const ( StopEnd = "end" StopToolUse = "tool_use" StopLength = "max_tokens" StopRefusal = "refusal" )
Stop reasons, in the neutral vocabulary.
const CompactAsk = "Summarize the conversation so far, as the instructions say. Call no tool."
CompactAsk ends the conversation to be summarized.
const CompactSystem = `` /* 563-byte string literal not displayed */
CompactSystem is the instruction a conversation is summarized with (ADR 0020). Changing it changes the record's inputs.
const DefaultContext = 200_000
DefaultContext is the context, in tokens, of a model ContextOf does not know.
const DefaultModel = "claude-opus-5-5"
DefaultModel is the model a session uses unless its agent names another.
Variables ¶
var ErrContextTooLong = errors.New("the conversation is longer than the model's context")
ErrNoCredentials: the Claude API has no key to call it with. ErrContextTooLong: the request is longer than the model's context (ADR 0020). It is a PermanentError's: the conversation must be compacted first.
var ErrNoCredentials = errors.New("the Claude API has no credentials: set ANTHROPIC_API_KEY (or run `ant auth login`), " +
"or switch with /provider to one that signs in on its own (claude-code, codex, copilot)")
Functions ¶
Types ¶
type Anthropic ¶
type Anthropic struct {
// Effort is output_config.effort. Claude Opus 5.5 defaults to "medium";
// a coding agent asks for "high".
Effort string
// MaxTokens per reply. Requests stream, so the SDK's HTTP timeouts for
// long non-streaming requests do not apply; it stays at 16000 for now.
MaxTokens int64
// contains filtered or unexported fields
}
Anthropic talks to the Claude API. Credentials are resolved by the SDK (ANTHROPIC_API_KEY, or a profile from `ant auth login`) inside this process only; they never enter a request KairoCode records (AGENTS.md, invariant 6).
func NewAnthropic ¶
func NewAnthropic(opts ...option.RequestOption) *Anthropic
type Fake ¶
type Fake struct {
Script []FakeReply `json:"script"`
// CallLog, if set, gets one line per call ("<index>\n"), appended, so a
// test can count calls across processes.
CallLog string `json:"call_log,omitempty"`
// PromptLog, if set, gets one line per call: the request's first user
// text on one line, so a test can tell whose calls were made (the
// subagent given a prompt).
PromptLog string `json:"prompt_log,omitempty"`
// ImageLog, if set, gets one line per call: the images the request
// carries, "<media type>:<bytes>" each, "-" for none (ADR 0026).
ImageLog string `json:"image_log,omitempty"`
// HoldAt is the reply index at which the fake writes HoldFile and then
// waits until its context ends, so a test can kill the process mid-call.
// It applies only when HoldFile is set.
HoldAt int `json:"hold_at"`
HoldFile string `json:"hold_file,omitempty"`
// HoldOn, if set, holds instead the calls whose last user message has
// it in its text (one of agents run at once).
HoldOn string `json:"hold_on,omitempty"`
// Replies answers, in place of the script, a request whose first user
// message has the key in its text (a subagent given that prompt).
Replies map[string]FakeReply `json:"replies,omitempty"`
// Summary is what it answers a request to summarize the conversation
// (ADR 0020); CallLog has "summary" for it.
Summary string `json:"summary,omitempty"`
// Decide, if set, answers a request that forces a tool (Request.Force):
// it calls that tool with this input, whatever the script says.
Decide json.RawMessage `json:"decide,omitempty"`
// ReleaseFile, if set, ends the hold when it appears: the call then
// answers from the script, so a test can let a held call finish.
ReleaseFile string `json:"release_file,omitempty"`
// contains filtered or unexported fields
}
Fake answers from a script, so tests never call a real model (AGENTS.md, invariant 9). The reply is chosen by how many assistant messages the request already holds, so it depends only on the conversation: a call repeated after a crash gets the same reply.
type FakeReply ¶
type FakeReply struct {
Text string `json:"text,omitempty"`
Tools []FakeTool `json:"tools,omitempty"`
// Stop overrides the stop reason (e.g. StopRefusal, StopLength).
Stop string `json:"stop,omitempty"`
// Input, if set, is the reply's input tokens (a long conversation).
Input int64 `json:"input,omitempty"`
// TooLong: the call fails as one longer than the model's context.
TooLong bool `json:"too_long,omitempty"`
}
type FakeTool ¶
type FakeTool struct {
Name string `json:"name"`
Input json.RawMessage `json:"input"`
}
type PermanentError ¶
type PermanentError struct{ Err error }
PermanentError is a provider error that repeating the request will not change (a malformed request, bad credentials): the model action fails at once instead of being tried again.
func (*PermanentError) Error ¶
func (e *PermanentError) Error() string
func (*PermanentError) Unwrap ¶
func (e *PermanentError) Unwrap() error
type Request ¶
type Request struct {
Model string
System string
Tools []ToolSpec
Messages []msg.Message
// OnText, if set, is given the reply's text as it comes, piece by piece
// (to stream it to the user). The Response still holds all of it.
OnText func(text string)
// Force, if set, names the tool the model must call (a typed answer);
// NoTools: it must call none (the tools are given for the calls the
// conversation holds, ADR 0020).
Force string
NoTools bool
// Effort, if set, is the model's effort for this call, in place of
// the provider's own (ADR 0014, 追記).
Effort string
}