Files
yetone d7e7eaf5f8 trae 0.2.8: a tool call's arguments wrapped once more by the model reach the agent bare (bee2an on X)
Asked to write each call as {"name":…,"arguments":{…}}, a model on Trae
sometimes wrote the arguments wrapped again, {"arguments":{…}}, and the
plugin passed that on: bee2an's agent got
{"arguments":{"content":"P\n\n","path":"…/trail2.txt"}} for its write and
wrote nothing useful.

Every call, from a block in the text or from Trae's native tool_calls,
streamed or not, now goes through one step in parts(): a lone arguments,
input, parameters or args key holding an object (or a JSON string of one)
is taken off, up to three layers, when the request's tool has no
parameter of that name. A tool whose own parameter is called input keeps
it, and a call to a tool the request doesn't list is left as it is.

Run: bun test in packages/trae, 96 pass. unwrap.test.mjs uses the
reporter's arguments byte for byte; its three tests fail with the step
stubbed out.
2026-10-10 18:14:24 +08:00

76 lines
3.9 KiB
JavaScript

// bee2an on X (yetone/magpie, 2026-10-10): asked for
// {"name":…,"arguments":{…}}, the model wrote the arguments wrapped once
// more, and their agent's write got {"arguments":{"content":…,"path":…}}.
// The arguments are the ones in their screenshot, byte for byte.
import "./nonet.mjs"
import { afterEach, expect, test } from "bun:test"
import { TraeCNAuthPlugin, _internal } from "./index.mjs"
import { fakeTrae, signedIn, sse } from "./fake.mjs"
let f
afterEach(() => f?.close())
async function ask(body, auth = signedIn()) {
const hooks = await TraeCNAuthPlugin({ client: {} })
const opts = await hooks.auth.loader(async () => auth)
return opts.fetch(opts.baseURL + "/chat/completions", { method: "POST", body: JSON.stringify(body) })
}
async function chunks(res) {
const out = []
for (const line of (await res.text()).split("\n")) {
if (!line.startsWith("data: ")) continue
const d = line.slice(6)
out.push(d === "[DONE]" ? d : JSON.parse(d))
}
return out
}
const callsOf = (c) => c.filter((x) => x !== "[DONE]" && x.choices?.length).flatMap((x) => x.choices[0].delta.tool_calls ?? []).map((t) => [t.function.name, JSON.parse(t.function.arguments)])
// pi-go's write
const TOOLS = [
{ type: "function", function: { name: "write", parameters: { type: "object", properties: { path: { type: "string" }, content: { type: "string" } }, required: ["path", "content"] } } },
{ type: "function", function: { name: "task", parameters: { type: "object", properties: { input: { type: "object" } } } } },
]
const BEE = '{"arguments":{"content":"P\\n\\n","path":"/Users/bee/j/pi-go/playground/cases/run-20261010-1805/trail2.txt"}}'
const BARE = { content: "P\n\n", path: "/Users/bee/j/pi-go/playground/cases/run-20261010-1805/trail2.txt" }
test("bee2an's write, wrapped in a block's arguments, reaches the agent bare (streamed)", async () => {
f = fakeTrae()
const block = '<tool_call>{"name":"write","arguments":' + BEE + "}</tool_call>"
f.route("POST /api/agent/v3/llm_utils_chat", () => sse([
["output", { response: block.slice(0, 40) }],
["output", { response: block.slice(40) }],
["done", { finish_reason: "stop" }],
]))
const c = await chunks(await ask({ model: "deepseek-v4.1-flash", stream: true, tools: TOOLS, messages: [{ role: "user", content: "hi" }] }))
expect(callsOf(c)).toEqual([["write", BARE]])
})
test("bee2an's write as Trae's native call, wrapped, reaches the agent bare (not streamed)", async () => {
f = fakeTrae()
f.route("POST /api/agent/v3/llm_utils_chat", () => sse([
["output", { tool_calls: [{ id: "c1", function: { name: "write", arguments: BEE.slice(0, 25) } }] }],
["output", { tool_calls: [{ id: "c1", function: { name: "write", arguments: BEE } }] }],
["done", { finish_reason: "tool_calls" }],
]))
const res = await ask({ model: "deepseek-v4.1-flash", tools: TOOLS, messages: [{ role: "user", content: "hi" }] })
const m = (await res.json()).choices[0].message
expect(m.tool_calls.map((t) => [t.function.name, JSON.parse(t.function.arguments)])).toEqual([["write", BARE]])
})
test("a layer is only taken off where the tool has no parameter of its name", () => {
const u = (a, n) => JSON.parse(_internal.unwrapped(a, n, TOOLS))
expect(u(BEE, "write")).toEqual(BARE)
// twice wrapped, and wrapped as a string
expect(u('{"arguments":{"input":{"path":"a","content":"b"}}}', "write")).toEqual({ path: "a", content: "b" })
expect(u('{"arguments":"{\\"path\\":\\"a\\",\\"content\\":\\"b\\"}"}', "write")).toEqual({ path: "a", content: "b" })
// the tool's own input parameter stays
expect(u('{"input":{"q":1}}', "task")).toEqual({ input: { q: 1 } })
// bare arguments, a second key, a tool not in the request: as they are
expect(u(JSON.stringify(BARE), "write")).toEqual(BARE)
expect(u('{"arguments":{"path":"a"},"content":"b"}', "write")).toEqual({ arguments: { path: "a" }, content: "b" })
expect(u(BEE, "other")).toEqual(JSON.parse(BEE))
})