3a5e4b62d0bef7ac6344deaa804eea44c8d4fbef
2
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
c688211d13 |
gateway: a ChatGPT (Codex) account gets loaded tools where they were loaded, keeping its cache (#4738)
infinitex233 (#4738, Discord): Claude Code -> magpie -> a Codex account, and every ToolSearch load dropped cache_read to 0. loadsInPlace sent the additional_tools item (#2660) only to OpenAI's own API, so for an account the loaded tool went into the top-level tools and the cached prefix broke at the tools. Tried on the real ChatGPT backend first (owner's account, sandbox HOME on mote with a copied auth.json whose refresh_token was replaced, so the live token was never rotated; ~/.codex untouched). A probe client sent Claude Code's shape: ToolSearch with two deferred mcp tools, then the tool_reference result, then the calls, 4 requests per run. - additional_tools item (on, and this commit's default): request 2..4 read 7680-8320 tokens from cache on gpt-5.6-terra, gpt-6-luna and gpt-6-sol; the model called read_a and read_b from the item; no "turned away additional_tools" in the log. - tools top-level (off): request 2 and 3 read 0 from cache (8044 and 8163 tokens in), as the reporter saw. So the backend takes it, and this makes it the default for a ChatGPT account (p.Account.Agent == "codex"). Copilot and other sign-ins stay off: not tried. - loadsInPlace: AdditionalToolsOff wins, then AdditionalTools, then an account is in only if it's Codex's, then OpenAI's API as before. - `magpie provider set <id> additional-tools=on|off|default`: off is new (AdditionalToolsOff, kept through an account's Save by accountSettings and through the GUI editor's save like AdditionalTools). The old "off"/"no" meant default; now they turn it off where the default is on. - The 400/422 fallback that names the item still applies, so a backend that stops taking it costs one retry and then sends tools top-level. - No prompt, instructions or identity line changed. Run (mote, at base |
||
|
|
f5b0157420 |
gateway: a tool Claude Code's tool search loads goes to OpenAI's Responses API where it was loaded (#2660)
Through /v1/messages translated to a Responses provider, every deferred
tool ToolSearch loaded joined the top-level tools on the next request, so
the prompt changed from its first bytes and the cache missed on each load
(maximia's probe: cached tokens dropped on every request after a load).
Now, where Request.LoadedInPlace is set, a deferred tool (defer_loading,
Tool.Deferred) that a tool_result's tool_reference names (toolRefs,
Part.Loads) goes in an {"type":"additional_tools","role":"developer",
"tools":[...]} item right after the run of tool outputs that loaded it,
once, and not in tools (buildResponses). Parallel results and one result
naming several share one item; a tool named again isn't repeated; the
output's text is as before. A history whose loading result is gone
(compaction, edits) puts the tool back in tools: a new prefix, expected.
Scope (loadsInPlace): OpenAI's own API with a key (api.openai.com,
*.api.openai.com), whose tool search guide documents the item and says
its tools load at the end of the context so the cache is kept; and a
provider the user sets with `magpie provider set <id> additional-tools=on`
(Provider.AdditionalTools, kept by the GUI's save like codexAsSent).
Nothing else: xAI answers the item 422 (#350), the ChatGPT backend has
been seen taking it only for Codex's Responses Lite, Azure, plugins and
relays are untried. An upstream that refuses a request holding the item
with a 400/422 naming additional_tools is asked again with every tool in
tools, logged ("turned away additional_tools ... loaded tools go in tools
from now on") and not sent the item again while magpie runs.
Not handled: a tool a tool_addition block in a system message loads (MCP
late tools, the advisor) stays in tools. Not tried against a real
upstream: no OpenAI key or custom Responses relay was used; the item's
shape and position follow OpenAI's docs, and the fixtures follow
maximia's three-request probe (Claude Code 2.1.302) and the
tool_reference shape Claude Code 2.1.306's binary writes.
Tests: TestLoadedToolsKeepThePrefix (top-level tools and instructions
identical across the three requests, each input a prefix of the next),
TestLoadedToolsInOneItem (parallel, batch, repeat), TestLoadedToolsWhereNotTaken
(unsupported upstream unchanged; compacted; non-deferred),
TestLoadsInPlaceScope, TestLoadedToolsThroughTheGateway (off by default on
a relay, on with the flag, refusal retried without the item and not sent
again), TestAdditionalToolsPair (CLI). Broken by hand: with the
buildResponses placement disabled, the first two and the gateway test go
red; with the refusal retry disabled, TestLoadedToolsThroughTheGateway
goes red.
Run at cff7dc67d (this change on
|