@hexdecimal16/nexo 0.4.18 → 0.4.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/src/providers/agy-p.js +83 -17
- package/package.json +1 -1
|
@@ -97,24 +97,37 @@ function spawnRunner(command) {
|
|
|
97
97
|
};
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Context nexo budgets for agy models (gpt-oss aside). The models take 1M tokens elsewhere, but `agy acp` answers an
|
|
102
|
+
* empty turn somewhere past ~210k tokens (seen working at 210k, failing at 315k), so nexo must compact before that.
|
|
103
|
+
*/
|
|
104
|
+
const AGY_CONTEXT = 200_000;
|
|
100
105
|
/**
|
|
101
106
|
* Antigravity CLI base model ids (the `model` config option in `agy acp`), paired with display name, context window and
|
|
102
|
-
*
|
|
103
|
-
* billing, so cost stays zero.
|
|
107
|
+
* the highest `thought_level` the model offers (`null`: no `thought_level` option, so no reasoning effort). Antigravity
|
|
108
|
+
* uses account quota rather than API billing, so cost stays zero.
|
|
104
109
|
*/
|
|
105
110
|
const AGY_MODELS = [
|
|
106
|
-
["gemini-4-neon", "Gemini 4 Neon",
|
|
107
|
-
["gemini-4-carbon", "Gemini 4 Carbon",
|
|
108
|
-
["gemini-4-argon", "Gemini 4 Argon",
|
|
109
|
-
["gemini-4-hydrogen", "Gemini 4 Hydrogen",
|
|
110
|
-
["gemini-3.8-flash", "Gemini 3.8 Flash",
|
|
111
|
-
["gemini-pro-orchestrator-neon", "Orchestrator (Neon)",
|
|
112
|
-
["gemini-pro-orchestrator", "Orchestrator (Carbon)",
|
|
113
|
-
["gemini-pro-orchestrator-argon", "Orchestrator (Argon)",
|
|
114
|
-
["claude-opus-5-5", "Claude Opus 5.5",
|
|
115
|
-
["claude-sonnet-5-5", "Claude Sonnet 5.5",
|
|
116
|
-
["gpt-oss-120b-medium", "GPT-OSS 120B (Medium)", 128_000,
|
|
111
|
+
["gemini-4-neon", "Gemini 4 Neon", AGY_CONTEXT, "xhigh"],
|
|
112
|
+
["gemini-4-carbon", "Gemini 4 Carbon", AGY_CONTEXT, "high"],
|
|
113
|
+
["gemini-4-argon", "Gemini 4 Argon", AGY_CONTEXT, "high"],
|
|
114
|
+
["gemini-4-hydrogen", "Gemini 4 Hydrogen", AGY_CONTEXT, "xhigh"],
|
|
115
|
+
["gemini-3.8-flash", "Gemini 3.8 Flash", AGY_CONTEXT, "high"],
|
|
116
|
+
["gemini-pro-orchestrator-neon", "Orchestrator (Neon)", AGY_CONTEXT, null],
|
|
117
|
+
["gemini-pro-orchestrator", "Orchestrator (Carbon)", AGY_CONTEXT, null],
|
|
118
|
+
["gemini-pro-orchestrator-argon", "Orchestrator (Argon)", AGY_CONTEXT, null],
|
|
119
|
+
["claude-opus-5-5", "Claude Opus 5.5", AGY_CONTEXT, "high"],
|
|
120
|
+
["claude-sonnet-5-5", "Claude Sonnet 5.5", AGY_CONTEXT, "high"],
|
|
121
|
+
["gpt-oss-120b-medium", "GPT-OSS 120B (Medium)", 128_000, null],
|
|
117
122
|
];
|
|
123
|
+
/**
|
|
124
|
+
* The efforts nexo may pick for a model, as pi's clamp reads them: `thought_level` runs low..high (plus xhigh on some
|
|
125
|
+
* models), and has no "off" or "minimal", which clamp up to low rather than leave the model on its own default (high).
|
|
126
|
+
* pi counts xhigh and max as supported only when mapped, so without this map they would clamp down to high.
|
|
127
|
+
*/
|
|
128
|
+
function agyThinkingLevels(topLevel) {
|
|
129
|
+
return { off: null, minimal: null, low: "low", medium: "medium", high: "high", xhigh: topLevel === "xhigh" ? "xhigh" : null, max: null };
|
|
130
|
+
}
|
|
118
131
|
/** Antigravity's base models, borrowing `maxTokens` from pi-ai's Google/Anthropic catalog where an entry matches. */
|
|
119
132
|
function agyPModels() {
|
|
120
133
|
const builtin = new Map();
|
|
@@ -122,7 +135,7 @@ function agyPModels() {
|
|
|
122
135
|
for (const m of getBuiltinModels(provider))
|
|
123
136
|
builtin.set(m.id, m);
|
|
124
137
|
}
|
|
125
|
-
return AGY_MODELS.map(([id, displayName, contextWindow,
|
|
138
|
+
return AGY_MODELS.map(([id, displayName, contextWindow, topLevel]) => {
|
|
126
139
|
const base = builtin.get(id);
|
|
127
140
|
return {
|
|
128
141
|
...(base ?? { maxTokens: id.startsWith("gemini-") ? 65_536 : 32_000 }),
|
|
@@ -131,7 +144,8 @@ function agyPModels() {
|
|
|
131
144
|
api: AGY_P_API,
|
|
132
145
|
provider: AGY_P_PROVIDER,
|
|
133
146
|
baseUrl: "",
|
|
134
|
-
reasoning,
|
|
147
|
+
reasoning: topLevel !== null,
|
|
148
|
+
thinkingLevelMap: topLevel === null ? undefined : agyThinkingLevels(topLevel),
|
|
135
149
|
input: ["text", "image"],
|
|
136
150
|
contextWindow,
|
|
137
151
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
@@ -193,6 +207,51 @@ export function agyTranscriptParts(messages) {
|
|
|
193
207
|
parts.push({ type: "text", text: `\n\n${note}` });
|
|
194
208
|
return parts;
|
|
195
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* `agy acp` silently cuts a prompt message at about 68k tokens and keeps its beginning, so on a long conversation the
|
|
212
|
+
* model never saw the newest tool results or user message and kept redoing its last step. The system prompt is not
|
|
213
|
+
* cut, so past `PROMPT_CHARS` of text the start of the transcript moves there and the message keeps its last
|
|
214
|
+
* `TAIL_CHARS` (at ~2.5 characters a token for code and JSON, both stay well under the cap).
|
|
215
|
+
*/
|
|
216
|
+
const PROMPT_CHARS = 100_000;
|
|
217
|
+
const TAIL_CHARS = 40_000;
|
|
218
|
+
const CONTINUED_NOTE = "(The conversation so far is in your instructions under \"Conversation so far\"; it continues here.)\n\n";
|
|
219
|
+
/** Splits a long transcript into the part that goes in the system prompt (`history`) and the message to send. */
|
|
220
|
+
export function splitAgyPrompt(parts) {
|
|
221
|
+
const textChars = parts.reduce((n, p) => n + (p.type === "text" ? p.text.length : 0), 0);
|
|
222
|
+
if (textChars <= PROMPT_CHARS)
|
|
223
|
+
return { prompt: [...parts] };
|
|
224
|
+
const tail = [];
|
|
225
|
+
let budget = TAIL_CHARS;
|
|
226
|
+
let i = parts.length - 1;
|
|
227
|
+
let headEnd = "";
|
|
228
|
+
for (; i >= 0; i--) {
|
|
229
|
+
const part = parts[i];
|
|
230
|
+
if (part.type !== "text") {
|
|
231
|
+
tail.unshift(part);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (part.text.length <= budget) {
|
|
235
|
+
tail.unshift(part);
|
|
236
|
+
budget -= part.text.length;
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
const cut = part.text.length - budget;
|
|
240
|
+
if (budget > 0)
|
|
241
|
+
tail.unshift({ type: "text", text: part.text.slice(cut) });
|
|
242
|
+
headEnd = part.text.slice(0, cut);
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
// Images before the split cannot go in the system prompt; they stay as a marker where they were.
|
|
246
|
+
const history = parts
|
|
247
|
+
.slice(0, Math.max(0, i))
|
|
248
|
+
.map((p) => (p.type === "text" ? p.text : "[image]"))
|
|
249
|
+
.join("") + headEnd;
|
|
250
|
+
return { history, prompt: [{ type: "text", text: CONTINUED_NOTE }, ...tail] };
|
|
251
|
+
}
|
|
252
|
+
function historySection(history) {
|
|
253
|
+
return `# Conversation so far\n\nThe transcript below is cut where the user message continues it.\n\n${history}`;
|
|
254
|
+
}
|
|
196
255
|
/** MCP config agy reads from `<gemini dir>/config/`: the mirror swaps in an empty one. */
|
|
197
256
|
const MCP_CONFIG = "mcp_config.json";
|
|
198
257
|
/**
|
|
@@ -519,6 +578,8 @@ class AcpConnection {
|
|
|
519
578
|
void rm(this.dir, { recursive: true, force: true }).catch(() => { });
|
|
520
579
|
}
|
|
521
580
|
}
|
|
581
|
+
/** Why a turn failed when agy answered nothing at all. */
|
|
582
|
+
export const AGY_P_EMPTY_REPLY = "agy returned an empty reply with no token usage (the conversation may exceed what agy accepts; compact it or start a new session)";
|
|
522
583
|
/** Why a tools turn ended without a usable reply; the engine retries it a few times (see `isFormatFailure`). */
|
|
523
584
|
export const AGY_P_BAD_REPLY = "reply was not a JSON object in the required format";
|
|
524
585
|
/** True when a reply that did not parse was an attempt at the JSON format rather than a plain-prose answer. */
|
|
@@ -576,7 +637,10 @@ function streamAgyP(getConn, model, context, options) {
|
|
|
576
637
|
const tools = getCurrentTools(context.messages);
|
|
577
638
|
const useTools = tools.length > 0 && options?.toolChoice !== "none";
|
|
578
639
|
const knownTools = useTools ? new Set(tools.map((t) => t.name)) : new Set();
|
|
579
|
-
const
|
|
640
|
+
const { history, prompt } = splitAgyPrompt(agyTranscriptParts(context.messages));
|
|
641
|
+
const systemPrompt = [getCurrentSystemPrompt(context.messages), useTools ? agyToolsSection(tools) : "", history ? historySection(history) : ""]
|
|
642
|
+
.filter((s) => s.length > 0)
|
|
643
|
+
.join("\n\n");
|
|
580
644
|
const idleMs = parseIdleMs(process.env[AGY_P_IDLE_ENV]);
|
|
581
645
|
const closeSession = (session) => {
|
|
582
646
|
if (!session || session.conn.closed)
|
|
@@ -774,7 +838,6 @@ function streamAgyP(getConn, model, context, options) {
|
|
|
774
838
|
let session;
|
|
775
839
|
try {
|
|
776
840
|
stream.push({ type: "start", partial: snapshot() });
|
|
777
|
-
const prompt = agyTranscriptParts(context.messages);
|
|
778
841
|
const opened = await startSession();
|
|
779
842
|
if (opened === "aborted" || signal?.aborted)
|
|
780
843
|
return fail("aborted", "Request was aborted");
|
|
@@ -801,6 +864,9 @@ function streamAgyP(getConn, model, context, options) {
|
|
|
801
864
|
}
|
|
802
865
|
if (outcome.error)
|
|
803
866
|
return fail("error", `agy failed: ${outcome.error}`, usage);
|
|
867
|
+
// No text, no calls and no usage: agy declined the prompt without saying why, as it does past its context limit.
|
|
868
|
+
if (!outcome.text.trim() && outcome.recoveredCalls.length === 0 && usage.totalTokens === 0)
|
|
869
|
+
return fail("error", `agy failed: ${AGY_P_EMPTY_REPLY}`, usage);
|
|
804
870
|
let stopReason = outcome.stopReason === "max_tokens" ? "length" : "stop";
|
|
805
871
|
if (useTools) {
|
|
806
872
|
const fromOutcome = (o) => o.recoveredCalls.length > 0
|