Documentation
¶
Overview ¶
Package toolprune removes unused tool definitions from outbound inference requests.
A Claude Code request carries the full tool manifest on every turn — tens of thousands of tokens of JSON schema, billed each time and largely for tools the agent will never call in a given deployment. The manifest is assembled by the client, so the only place to trim it without touching every client is in the proxy.
The verdict is entirely configuration: `remove` names the tools to drop. There is no learning, no state and no storage dependency. `abctl tools scan` produces a candidate list from local transcripts, but the plugin itself only ever does what it was told.
Safety is one-directional. Removing a tool the model needs is the harmful failure; carrying a few extra definitions is not. So every error path fails open, forwarding the original bytes untouched, and a tool named by a forced tool_choice is never removed — the manifest and tool_choice have to agree or the request is invalid.
That is a promise about this plugin's own failure modes, not a claim that pruning is always safe: whether a provider or gateway accepts a validly pruned manifest is outside what the plugin can observe. on_error: observe exists to establish that empirically before any request changes.
Index ¶
- type ToolPrune
- func (p *ToolPrune) Capabilities() pipeline.PluginCapabilities
- func (p *ToolPrune) ConfigSchema() []pipeline.FieldSchema
- func (p *ToolPrune) Configure(raw json.RawMessage) error
- func (p *ToolPrune) Metrics() []pipeline.Metric
- func (p *ToolPrune) Name() string
- func (p *ToolPrune) OnFinish(_ context.Context, pctx *pipeline.Context)
- func (p *ToolPrune) OnRequest(_ context.Context, pctx *pipeline.Context) (action pipeline.Action)
- func (p *ToolPrune) OnResponse(_ context.Context, _ *pipeline.Context) pipeline.Action
- func (p *ToolPrune) RawConfig() json.RawMessage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ToolPrune ¶
type ToolPrune struct {
// contains filtered or unexported fields
}
ToolPrune is the plugin. Counters live in metrics, guarded by its own mutex; everything else is read-only after Configure.
func (*ToolPrune) Capabilities ¶
func (p *ToolPrune) Capabilities() pipeline.PluginCapabilities
func (*ToolPrune) ConfigSchema ¶
func (p *ToolPrune) ConfigSchema() []pipeline.FieldSchema
ConfigSchema implements pipeline.SchemaProvider.
func (*ToolPrune) OnFinish ¶
OnFinish converts the request's byte saving into tokens and attributes it to the token tier it actually came out of.
Two things make a single "tokens saved" number wrong, which is why this is per-tier. First, the ratio: rather than bundling a tokenizer or assuming bytes-per-token, it is calibrated on this request — prompt tokens over request bytes, both post-pruning, so the two sides are consistent. Second, and larger: providers price prompt tiers very differently. Anthropic charges 1.25x the input rate for a cache write and 0.1x for a cache read, so identical saved bytes are worth more than 12x more on a cache miss than on a hit. Reporting one blended figure would hide a factor of twelve.
The tool manifest sits inside the cached prefix — Claude Code puts cache_control on the tool block — so on a cache-miss request the saving comes out of cache writes, and on a hit out of cache reads. That is the assumption this attribution rests on; it is stated here because it is the one thing that would need revisiting for a client that lays out its prompt differently.
func (*ToolPrune) OnRequest ¶
OnRequest prunes the manifest. Every failure path returns Continue with the body untouched.
func (*ToolPrune) OnResponse ¶
func (*ToolPrune) RawConfig ¶
func (p *ToolPrune) RawConfig() json.RawMessage
RawConfig implements pipeline.RawConfigProvider.