trae 0.2.44: a chat is sent its model's max_tokens, so an enterprise reply isn't cut at 2000
@liuyuexue2020 on X (0.2.43, Trae CN enterprise seat, console.enterprise.trae.cn,
model AI/deekseek-v4.1-flash): in Trae the model writes past 2000 tokens;
through magpie every reply stopped at exactly 2,000 output tokens (their
Usage rows: 26,037 / 2,000, 24,870 / 2,000, 23,097 / 2,000, streamed).
Cause: chatBody sent max_tokens only when the agent named one, held to the
__dev detail's max_tokens (`most`). An enterprise model has no __dev
detail, so it had no `most`, its listed output limit was 0, and an agent
naming no limit sent llm_utils_chat none. Trae's own client always sends
one: the ai-agent's ModelConfig carries the detail's max_tokens with every
model ("[ModelConfig] Received config_name=, model_name=, max_turn=,
prompt_max_tokens=, max_tokens=" in Trae CN 3.4.20's ai-agent strings;
CloudModelDetailInfo has max_tokens beside model_name and provider). The
2000 is most likely what Trae gives a request naming none; that wasn't
measured, having no seat.
Now:
- an enterprise model's `most` and listed output come from its own detail
(enterpriseDetail: the __dev one, else the first naming a model);
- every chat whose model has a known `most` sends it when the agent names
no limit, and holds a larger ask to it, as Max mode already did. A
preset asked through the function naming its __dev detail now sends
that detail's max_tokens too, the value Trae's client sends; a function
that doesn't name it still sends nothing.
- a detail with no max_tokens sends the agent's limit or none, as before.
Siblings: Trae CN and Trae international are one plugin (both sites go
through chatBody); SOLO's functions (solo_agent, solo_coder, ...) too. No
other plugin in the repo sets a fixed max_tokens/max_output_tokens cap
(grep for 1000/1024/2000/2048/4000/4096 near those keys). magpie's gateway
sends no fixed 2000 (its fill-in, askedOutput, is Anthropic-only).
Run (mote, HOME=$(mktemp -d), this tree on 62645ece):
packages/trae bun test: 287 pass, 0 fail (24 files);
bun scripts/check.mjs trae: ok;
root bun test: 9058 pass, 0 fail, 9078 tests across 636 files (514s);
bun scripts/check.mjs (all packages): ok.
Broken by hand: with 0.2.43's index.mjs, entmodels.test.mjs has 2 of 10
red: the enterprise test (max_tokens 0 listed / none sent, expected 8192)
and the preset test (undefined, expected 32000).
Not tried: a real enterprise seat (we have none), so the detail's
max_tokens in the fixture (8192) is invented and the 2000 default
is inferred from the reporter's numbers. If their detail carries no
max_tokens, a request naming none still goes without one.
This commit is contained in:
@@ -255,7 +255,11 @@ config, where Trae's list doesn't carry it, sent no `model_name`, and got
|
||||
4023 "something went wrong") — **not verified with a real enterprise seat**. A refused chat's error names
|
||||
the model, the functions tried and the host, and says when the account's
|
||||
list doesn't have the model. Context is the list's `context_window_tokens.dev`,
|
||||
output the `__dev` model's `max_tokens`. A model with a `__max` model and
|
||||
output the `__dev` model's `max_tokens` (an enterprise model's own detail's,
|
||||
since 0.2.44). That `max_tokens` is sent with every chat, the agent's limit
|
||||
held to it and it sent when the agent names none, as Trae's own client
|
||||
sends the model's `max_tokens` with each model: asked with none, an
|
||||
enterprise seat's replies stopped at exactly 2000 output tokens (0.2.43). A model with a `__max` model and
|
||||
a bigger `context_window_tokens.max` is listed again as its Max,
|
||||
`<id>-max` ("… (Max)"), with that window and the `__max` model's
|
||||
`max_tokens`; the two can come from different functions' lists (chat_v3
|
||||
|
||||
@@ -146,3 +146,45 @@ test("an enterprise model's __dev detail is the one asked by; a preset's body ga
|
||||
const p = _internal.chatBody({ model: "glm-5", messages: [{ role: "user", content: "hi" }] }, "chat_v3", "", 0, null, "s", false, null, preset)
|
||||
for (const k of ["model_name", "provider", "config_source", "is_custom_model"]) expect(k in p).toBe(false)
|
||||
})
|
||||
|
||||
// the reporter's next case (@liuyuexue2020 on X, 0.2.43, AI/deekseek-v4.1-flash
|
||||
// on console.enterprise.trae.cn): every reply stopped at exactly 2000 output
|
||||
// tokens, where the same model in Trae wrote more. Trae's own client sends
|
||||
// the model detail's max_tokens with every model; the plugin sent the
|
||||
// agent's limit only, and an enterprise model none at all when the agent
|
||||
// named none. The fake answers as the reporter met it: a request naming no
|
||||
// limit gets 2000 tokens.
|
||||
test("an enterprise model's chat is held to its detail's max_tokens, and sent it when the agent names none", async () => {
|
||||
const hooks = await plugin([preset, ...listed])
|
||||
const ms = await hooks.provider.models({ models: {} }, { auth: signedIn() })
|
||||
expect(ms["AI/deekseek-v4.1-flash"].limit.output).toBe(8192)
|
||||
f.route("POST /api/agent/v3/llm_utils_chat", (r) => {
|
||||
const out = Math.min(r.json.max_tokens || 2000, 8192)
|
||||
return sse([["output", { response: "x" }], ["done", { usage: { prompt_tokens: 10, completion_tokens: out } }]])
|
||||
})
|
||||
const opts = await hooks.auth.loader(async () => signedIn())
|
||||
const ask = async (extra) => {
|
||||
const res = await opts.fetch(opts.baseURL + "/chat/completions", { method: "POST", body: JSON.stringify({ model: "AI/deekseek-v4.1-flash", messages: [{ role: "user", content: "write a lot" }], ...extra }) })
|
||||
expect(res.status).toBe(200)
|
||||
return f.seen.filter((r) => r.path === "/api/agent/v3/llm_utils_chat").at(-1).json.max_tokens
|
||||
}
|
||||
expect(await ask({})).toBe(8192)
|
||||
expect(await ask({ max_tokens: 100 })).toBe(100)
|
||||
expect(await ask({ max_tokens: 100000 })).toBe(8192)
|
||||
expect(await ask({ max_completion_tokens: 3000 })).toBe(3000)
|
||||
})
|
||||
|
||||
test("an enterprise detail with no max_tokens sends the agent's limit or none", () => {
|
||||
const bare = { ...listed[0], model_detail_list: [{ model_name: "deekseek-v4.1-flash", provider: "AI" }] }
|
||||
const req = { model: bare.config_name, messages: [{ role: "user", content: "hi" }] }
|
||||
expect("max_tokens" in _internal.chatBody(req, "chat_v3", "", 0, null, "s", false, null, bare)).toBe(false)
|
||||
expect(_internal.chatBody({ ...req, max_tokens: 5000 }, "chat_v3", "", 0, null, "s", false, null, bare).max_tokens).toBe(5000)
|
||||
})
|
||||
|
||||
test("a preset asked with no limit is sent its __dev max_tokens, as Trae's client sends it", () => {
|
||||
const req = { model: "glm-5", messages: [{ role: "user", content: "hi" }] }
|
||||
expect(_internal.chatBody(req, "chat_v3", "glm-5__dev", 32000, null, "s", false, null, preset).max_tokens).toBe(32000)
|
||||
expect(_internal.chatBody({ ...req, max_tokens: 100 }, "chat_v3", "glm-5__dev", 32000, null, "s", false, null, preset).max_tokens).toBe(100)
|
||||
// a function whose list doesn't name the model's __dev detail: nothing known, nothing sent
|
||||
expect("max_tokens" in _internal.chatBody(req, "solo_agent", "", 0, null, "s", false, null, preset)).toBe(false)
|
||||
})
|
||||
|
||||
+15
-2
@@ -1632,10 +1632,21 @@ function chatBody(req, fn, modelName, most = 0, max = null, session = "", sees =
|
||||
}
|
||||
const effort = effortOf(levels, req.reasoning_effort ?? req.reasoningEffort)
|
||||
if (effort) body.reasoning_effort = effort
|
||||
// the reply limit is always sent when the list gives the model one, as
|
||||
// Trae's own client does: its agent's ModelConfig carries the detail's
|
||||
// max_tokens with every model (ai-agent, "[ModelConfig] Received
|
||||
// config_name=, model_name=, …, max_tokens="). Asked with none, an
|
||||
// enterprise seat's every reply stopped at exactly 2000 output tokens,
|
||||
// where the same model in Trae wrote more (@liuyuexue2020 on X,
|
||||
// AI/deekseek-v4.1-flash, 0.2.43), most likely the limit Trae gives a
|
||||
// request naming none (no seat to measure it on). An enterprise
|
||||
// model has no __dev detail for most to come from, so its own detail's
|
||||
// max_tokens is the one.
|
||||
if (!(most > 0) && enterpriseModel(entry)) most = Number(enterpriseDetail(entry)?.max_tokens) || 0
|
||||
const asked = req.max_completion_tokens ?? req.max_tokens
|
||||
if (Number.isFinite(asked) && asked > 0) body.max_tokens = most > 0 ? Math.min(Math.floor(asked), most) : Math.floor(asked)
|
||||
else if (most > 0) body.max_tokens = most
|
||||
if (max?.window) {
|
||||
if (!body.max_tokens && most > 0) body.max_tokens = most
|
||||
body.user_message_context = { model_info: { prompt_max_tokens: max.window - (body.max_tokens || 0) } }
|
||||
}
|
||||
// an enterprise's built-in model says where its config comes from beside
|
||||
@@ -4085,7 +4096,9 @@ const makePlugin = (site) => async ({ client }) => {
|
||||
const was = provider.models?.[id] ?? {}
|
||||
// context_window_tokens: dev is what a request gets, max only in Max mode
|
||||
const ctx = Number(m.context_window_tokens?.dev ?? m.context_window_size?.max?.[0] ?? m.context_window_size?.max ?? m.context_window_tokens?.max ?? m.prompt_max_tokens) || was.limit?.context || MODEL.limit.context
|
||||
const out = Number(devModel(m)?.max_tokens) || was.limit?.output || 0
|
||||
// output: the detail requests are served by (an enterprise model's own
|
||||
// when it has no __dev one)
|
||||
const out = Number((enterpriseModel(m) ? enterpriseDetail(m) : devModel(m))?.max_tokens) || was.limit?.output || 0
|
||||
const name = m.display_config?.display_name || m.display_name || m.display_model_name || was.name || id
|
||||
const input = (k) => (MODEL.modalities?.input ?? []).includes(k)
|
||||
// the list's multimodal says whether the model takes images, over the
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-trae-auth",
|
||||
"version": "0.2.43",
|
||||
"version": "0.2.44",
|
||||
"description": "OpenCode provider plugins for Trae: Trae CN (trae.cn) and Trae Global (trae.ai), free tier included, with Trae's own browser sign-in",
|
||||
"type": "module",
|
||||
"main": "./opencode.mjs",
|
||||
|
||||
Reference in New Issue
Block a user