provider

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package provider adapts model providers to one request/response shape. Adapters run inside the "model" action, never in workflow code.

Index

Constants

View Source
const (
	StopEnd     = "end"
	StopToolUse = "tool_use"
	StopLength  = "max_tokens"
	StopRefusal = "refusal"
)

Stop reasons, in the neutral vocabulary.

View Source
const CompactAsk = "Summarize the conversation so far, as the instructions say. Call no tool."

CompactAsk ends the conversation to be summarized.

View Source
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.

View Source
const DefaultContext = 200_000

DefaultContext is the context, in tokens, of a model ContextOf does not know.

View Source
const DefaultModel = "claude-opus-5-5"

DefaultModel is the model a session uses unless its agent names another.

Variables

View Source
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.

View Source
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

func ContextOf

func ContextOf(model string) int

ContextOf is model's context in tokens: the Claude models' 200,000, or DefaultContext.

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

func (*Anthropic) Complete

func (a *Anthropic) Complete(ctx context.Context, r Request) (Response, error)

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.

func LoadFake

func LoadFake(path string) (*Fake, error)

LoadFake reads a Fake from a JSON file.

func (*Fake) Complete

func (f *Fake) Complete(ctx context.Context, r Request) (Response, error)

func (*Fake) Efforts

func (f *Fake) Efforts() []string

Efforts are the efforts the calls asked for, in order (those that asked for one).

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 Provider

type Provider interface {
	Complete(ctx context.Context, r Request) (Response, 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
}

type Response

type Response struct {
	// Message is the assistant's reply; its tool_use parts are the calls the
	// model asks for.
	Message msg.Message
	Stop    string
	Usage   msg.Usage
}

type ToolSpec

type ToolSpec struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	Schema      json.RawMessage `json:"schema"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL