Documentation
¶
Overview ¶
Package adapter holds what every agent adapter hands the wrapper.
Index ¶
Constants ¶
const ( GradeGatewayPrecheck = "gateway-precheck" GradeAgentFlag = "agent-flag" GradeWrapperWatchdog = "wrapper-watchdog" GradeNone = "none" )
Enforcement grades.
const UnitAICredits = "AIC"
UnitAICredits is the unit of gh-aw's AI credits.
Variables ¶
var ErrClaimed = errors.New("another costroid run holds the agent's state directory")
ErrClaimed means another run holds the directory an agent keeps its state in.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent interface {
// Name is the costroid/agent tag.
Name() string
// Plan rewrites a command to run under the budget, or refuses it.
Plan(argv []string, budget decimal.Decimal) (Plan, error)
// NewSession starts reading a run of the planned command.
NewSession(plan Plan) Session
}
Agent is one supported agent.
type AgentError ¶
type AgentError string
AgentError is the class of error a run's agent ended in. The class is read from the agent's own fields, never from its text. The values are a closed list; a class the agent states that is not on it reads as unknown.
const ( AgentErrorAuthentication AgentError = "authentication_failed" AgentErrorBilling AgentError = "billing_error" AgentErrorRateLimit AgentError = "rate_limit" AgentErrorInvalidRequest AgentError = "invalid_request" AgentErrorServer AgentError = "server_error" AgentErrorUnknown AgentError = "unknown" )
The classes an agent's run can end in. Empty means it ended in none.
func ParseAgentError ¶
func ParseAgentError(stated string) AgentError
ParseAgentError maps the class an agent states onto the closed list.
type Count ¶
type Count struct {
Class focus.TokenClass
Tokens int64
}
Count is one class and its tokens.
type Enforcement ¶
Enforcement is the grade a run was held at. Note states the limit of the grade in words and travels on every row.
type Exclusive ¶
type Exclusive interface {
// Claim holds the directory for one run, and release ends the hold. It
// fails with ErrClaimed while another run holds it.
Claim() (release func(), err error)
}
Exclusive is an Agent whose runs cannot share one state directory, because a run reads the directory and would count another run's spend as its own.
type GatewayBilled ¶
type GatewayBilled interface {
BilledThroughGateway()
}
GatewayBilled is a session that reads its cost basis from the credential its agent starts with. A run through a gateway starts the agent on the run's key, which the gateway bills per token upstream, and says so.
type Gatewayed ¶
type Gatewayed interface {
// GatewayEnv is the environment, as NAME=value entries, that points the
// agent at the gateway's base URL with the key as its credential. An entry
// with no value names a credential the agent must not hold beside the
// key, and the run removes it.
GatewayEnv(base, key string) []string
// GatewayArgs is what the agent's command line needs to reach the gateway
// at base. The run places it after every option the command already
// holds, so it overrides any value the command or a configuration file
// sets.
GatewayArgs(base string) []string
}
Gatewayed is an agent that can send every request through a gateway on a key the run holds. A run refuses a gateway key for an agent that is not.
type Plan ¶
type Plan struct {
Argv []string
Enforcement Enforcement
}
Plan is how one agent command runs under a budget.
type Report ¶
type Report struct {
SessionID string
AgentVersion string
CostBasis focus.CostBasis
CostSource string
Requests []Request
Warnings []string
// AgentError is the class of error the agent ended the run in. Empty means
// the run did not end in one.
AgentError AgentError
// Enforcement is the grade the run earned, when it differs from what the
// plan could promise. Empty means the plan's grade held.
Enforcement Enforcement
// Nested holds the sessions of other agent processes that started and
// ended inside the run, each under its own session id. Their requests are
// never in Requests.
Nested []Report
// Unrecorded counts the model requests the run sent whose usage no source
// reported, so no row holds them. A warning says which.
Unrecorded int
// AgentStated is the agent's own figure for the run, in the agent's own
// unit, nil when it states none. No row holds it, and it is never
// converted or added to an amount.
AgentStated *Stated
// Subscription is true when the run proves it was signed in on a plan
// subscription, which bills no tokens: its figure is list-equivalent, and
// no provider usage report can reconcile it. False means not proven, never
// that the run bills a key. Each nested session states its own.
Subscription bool
}
Report is what a run's usage came to.
type Request ¶
type Request struct {
// ID is the provider's request id, or the adapter's stated stand-in when
// the source has none.
ID string
Provider string
Model string
Start, End time.Time
ServiceTier string
Region string
// ContextInputTokens is the request's whole input. At a coarser grain it
// is the whole input of every request the entry sums, which no request in
// it can pass, or zero when the adapter states none.
ContextInputTokens int64
Grain Grain
Tokens Tokens
// AssumedWrite is the cache write class that took tokens whose lifetime the
// source did not report, by the adapter's rule. Empty when it reported all.
AssumedWrite focus.TokenClass
// CostSource names where this entry came from when it differs from the
// report's. Empty means the report's.
CostSource string
// Note says in words how this entry was read, when the report's own
// source does not.
Note string
// TierEvidence is what an entry coarser than a request offers about its
// context tier beyond its summed input. Nil when it offers nothing.
TierEvidence *TierEvidence
}
Request is one unit of usage at the finest grain the source reports.
type Session ¶
type Session interface {
// Feed reads one line of the agent's stdout, seen at the given time.
Feed(line []byte, at time.Time) error
// Finish reads whatever the agent left behind and returns the run's usage.
Finish() (Report, error)
}
Session reads one run.
type Stated ¶
type Stated struct {
// Unit is the agent's own unit, such as UnitAICredits.
Unit string
// Quantity is a non-negative decimal string, never a JSON number.
Quantity string
// Source names the agent that stated it.
Source string
}
Stated is a figure an agent states about its own run, as it states it.
type Tailer ¶
type Tailer interface {
// Tail follows the file until ctx ends. It calls settled with the run's
// requests so far each time a new one settles while the agent is working.
Tail(ctx context.Context, settled func([]Request))
}
Tailer is a Session that watches a file the agent writes during a run.
type TierEvidence ¶
type TierEvidence struct {
// Agent names the agent in words, as a row's note names it.
Agent string
// USD is the agent's figure at list price, nil when it states none.
USD *decimal.Decimal
}
TierEvidence is an agent's own figure for one entry's billed tokens. The entry's input is a sum over its requests, and past the lowest context tier a sum says nothing about any one request. The agent's figure says which tier the requests were billed in: the rows take the tier whose prices give it.
type Tokens ¶
type Tokens struct {
InputUncached int64
CacheRead int64
CacheWrite5m int64
CacheWrite1h int64
CacheWrite30m int64
Output int64
ReasoningOutput int64
CachedInputReported int64
}
Tokens holds the canonical classes. Billed classes are disjoint; the two informational classes repeat tokens a billed class already counts.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package claudecode reads Claude Code runs.
|
Package claudecode reads Claude Code runs. |
|
Package codex reads `codex exec --json` runs.
|
Package codex reads `codex exec --json` runs. |
|
Package copilot reads `copilot -p --output-format json` runs of GitHub Copilot CLI.
|
Package copilot reads `copilot -p --output-format json` runs of GitHub Copilot CLI. |
|
Package ghaw reads what a GitHub Agentic Workflows (gh-aw) run spent, from the usage artifact its conclusion job uploads.
|
Package ghaw reads what a GitHub Agentic Workflows (gh-aw) run spent, from the usage artifact its conclusion job uploads. |
|
Package opencode reads `opencode run --format json` runs.
|
Package opencode reads `opencode run --format json` runs. |