toolprune

package
v0.0.0-...-53bd38a Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 18 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 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. `agentop 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

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 New

func New() *ToolPrune

func (*ToolPrune) Capabilities

func (p *ToolPrune) Capabilities() pipeline.PluginCapabilities

func (*ToolPrune) ConfigSchema

func (p *ToolPrune) ConfigSchema() []pipeline.FieldSchema

ConfigSchema implements pipeline.SchemaProvider.

func (*ToolPrune) Configure

func (p *ToolPrune) Configure(raw json.RawMessage) error

func (*ToolPrune) Metrics

func (p *ToolPrune) Metrics() []pipeline.Metric

Metrics implements pipeline.MetricsProvider.

func (*ToolPrune) Name

func (p *ToolPrune) Name() string

func (*ToolPrune) OnFinish

func (p *ToolPrune) OnFinish(_ context.Context, pctx *pipeline.Context)

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 the bytes of the body actually sent, after every request writer, this one and any that follows it, so the two sides describe the same request. 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

func (p *ToolPrune) OnRequest(_ context.Context, pctx *pipeline.Context) (action pipeline.Action)

OnRequest prunes the manifest. Every failure path returns Continue with the body untouched.

func (*ToolPrune) OnResponse

func (p *ToolPrune) OnResponse(_ context.Context, _ *pipeline.Context) pipeline.Action

func (*ToolPrune) RawConfig

func (p *ToolPrune) RawConfig() json.RawMessage

RawConfig implements pipeline.RawConfigProvider.

Jump to

Keyboard shortcuts

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