adjudicate

package
v0.3.2-test-update1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 4 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 adjudicate declares the context-maintenance tool the cold-sweep adjudication asks with, and the wire helpers that keep it byte-stable in the prompt-cache prefix.

WHY A TOOL AT ALL, rather than only asking for a JSON array in the reply text. The ask carries the AGENT's tools, because `tools` are in the cache key and stripping them costs the read — so the only question is what the model does with that freedom. Three arms, same transcript and ask model, three benchmark passes each, run sequentially:

tool_choice          verdict tool   asks replied   unusable       answered via tool_use
{"type":"none"}      no             20             6  (30.0%)     0
(omitted)            NO             24             14 (58.3%)     0
(omitted)            yes            77             7  (9.1%)      43 (55.8%)

Fisher two-tailed: row 1 vs row 3 p = 0.0245, row 2 vs row 3 p = 0.0000.

The MIDDLE row is why this package exists, and it is the arm nobody had run: removing tool_choice:none on its own is WORSE than leaving it in. Freed to call a tool and offered only the agent's own plus context_guru_expand, the model calls one of those; logging every reply's content blocks caught it as `thinking,tool_use:context_guru_expand` with no text block at all, which the text-only extraction reads as "" and files as unusable. That arm also lost 5 asks to the 90 s llmCallTimeout against 0 and 1 in the others.

So the two halves are one change. Suppressing the call trades a lost answer for prose (row 1's failures); allowing it with nothing worth calling loses the answer outright (row 2); allowing it and declaring the right tool gets 55.8% of replies back schema-shaped at cache-read price, with the rest still read by the unchanged prose parser (row 3).

FORCING the tool by name is separately not free: it produced a second cache entry (8,378 written against the 8,268 already cached), so tool_choice DOES participate in the key when it names a tool, even though `none` does not.

WHERE IT IS INJECTED. On every request of an Anthropic route whose pipeline contains extract_llm_sweep, and nowhere else. Every-request matters because `tools` hashes before system and messages, so a tool that appears when the sweep fires and vanishes on the next turn invalidates the prefix from position zero -- the flap expand's `always` mode exists to prevent. But that argument only forbids gating on something that varies PER TURN: pipeline membership is fixed per config DOCUMENT and the provider by the route, so both conditions are byte-stable for every request under a given config. Not "fixed at config load", which is what this used to claim: proxy/tenancy.go rebuilds a tenant's *Pipeline when the config document changes, mid-session. That rebuild is a prefix-invalidating event in its own right, so the byte-stability argument holds where it matters. Injecting without them cost a measured 946 bytes at the head of the cacheable prefix of every preset including `off`, the control arm of every published comparison here, and including presets with no sweep at all.

This does not replace the text path. extract.ParseVerdicts and extract.BuildFallbackAsk are still the fallback, and a model that answers in prose anyway is still read exactly as before; the tool only changes which reply shape is PREFERRED.

Index

Constants

View Source
const StrayAnswer = "Context maintenance runs automatically in the background. No action is required " +
	"from you, and you do not need to call this tool. Continue with the task."

StrayAnswer is what a stray call from the AGENT gets. The model does call an advertised tool it was told to leave alone -- directly observed with context_guru_expand, which a run called at step 2 -- and the client cannot execute a tool the proxy injected, so it answers something like "Tool 'context_guru_adjudicate' not found" and the agent loses a turn to a dead end. This gives it a definite, uninteresting answer instead.

View Source
const ToolName = "context_guru_adjudicate"

ToolName is the wire name. Prefixed like the expand tool so an operator reading a transcript can tell at a glance which tools the proxy injected and which the client owns.

Variables

This section is empty.

Functions

func AnswerStrayCalls

func AnswerStrayCalls(provider string, body []byte) (out []byte, answered int)

AnswerStrayCalls replaces the client's tool_result for any call the AGENT made to this tool with a definite answer, and reports how many it replaced.

Same request-path shape as expand.RepairToolResults, and for the same reason: the client executes the real tools itself, finds no tool by this name because the PROXY injected it, and answers something like "Tool 'context_guru_adjudicate' not found". Left alone, the model reads a failure it cannot act on and may retry. Rewriting it on the next request works WITH the client's loop instead of against it, needs nothing implemented client-side, and is deterministic — the same substitution every turn, so the prefix does not flap.

Reading the tool_use out of the transcript rather than trusting the tool_result is what makes this safe: a client's tool_result is rewritten only when the assistant turn it answers called OUR tool. A body with no such call comes back byte-identical, because this runs on every request and a gratuitous rewrite would change the prefix and cost a cache write for nothing.

The response loop answers most strays before this ever runs, but NOT all of them: an assistant turn that calls this tool alongside a CLIENT tool is handed to the client whole, so for that turn this repair is the only defence rather than a second one. See the co-call note in the response loop.

func HasTool

func HasTool(provider string, body []byte) bool

HasTool reports whether body already declares the tool. This is the ADVERTISE test, and a host must answer stray calls exactly when it is true.

func Inject

func Inject(provider string, body []byte) (out []byte, injected bool)

Inject appends the tool to body's tools array, byte-stably and idempotently.

Appended LAST so the client's own tools keep their exact order, and skipped when a forcing tool_choice is present so tool selection is never perturbed. Also skipped when the request declares no tools at all: handing the model its first tool changes what it believes it can do, and that is the riskiest case for a model that penalizes an unexpected tool. Fail-open — any trouble returns the original body.

func NoteAnsweredInBand

func NoteAnsweredInBand(n int)

NoteAnsweredInBand counts stray calls answered on the RESPONSE path, before the client saw them. The same counter as the request-path repair on purpose: /stats publishes "the agent called a tool it was told not to call, n times", and which of the two defences caught it does not change that number — it is the rate that says whether the description is still working. Which path caught it is in the cg.adjudicate_stray log line, where it belongs.

func ResponseCallIDs

func ResponseCallIDs(provider string, resp []byte) (ids []string)

ResponseCallIDs returns the ids of calls the AGENT made to this tool in an upstream RESPONSE.

The request-path repair (AnswerStrayCalls) is a backstop and cannot be the primary defence: by the time it runs, the client has already SEEN the call, already failed to execute a tool it never declared, and already spent a turn answering "not found". Answering the call in-band on the response path -- before the client is written to -- is what makes the repair a backstop, and these ids are what the response loop needs to build that answer.

"Backstop" is not "unreachable", and this comment used to imply it was. The response loop declines the in-band answer, deliberately, when the assistant turn ALSO calls a client tool: it cannot continue a turn whose other tool_use only the client can execute, so it hands the round over and leaves the next request's repair to fix it. On that path the repair is the ONLY defence and the agent does pay one turn.

func StrayAnswered

func StrayAnswered() int64

StrayAnswered returns how many stray calls have been answered, on either path.

func ToolDefRaw

func ToolDefRaw(provider string) []byte

ToolDefRaw returns the provider-shaped tool definition.

Types

This section is empty.

Jump to

Keyboard shortcuts

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