polymath-agent 0.3.0 → 0.3.1
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/dist/cli.js +42 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2169,6 +2169,25 @@ ${stderr}`)) };
|
|
|
2169
2169
|
|
|
2170
2170
|
// src/agent/loop.ts
|
|
2171
2171
|
var MAX_ITERS_PER_STEP = 6;
|
|
2172
|
+
var KNOWN_TOOLS = new Set(TOOL_SCHEMAS.map((t) => t.function.name));
|
|
2173
|
+
function parseTextToolCall(content) {
|
|
2174
|
+
if (!content) return null;
|
|
2175
|
+
const json = extractJson(content);
|
|
2176
|
+
if (!json) return null;
|
|
2177
|
+
try {
|
|
2178
|
+
const obj = JSON.parse(json);
|
|
2179
|
+
const name = obj?.name ?? obj?.tool ?? obj?.function?.name;
|
|
2180
|
+
if (typeof name !== "string" || !KNOWN_TOOLS.has(name)) return null;
|
|
2181
|
+
const args = obj.arguments ?? obj.parameters ?? obj.function?.arguments ?? {};
|
|
2182
|
+
return {
|
|
2183
|
+
id: `textcall_${name}`,
|
|
2184
|
+
type: "function",
|
|
2185
|
+
function: { name, arguments: typeof args === "string" ? args : JSON.stringify(args) }
|
|
2186
|
+
};
|
|
2187
|
+
} catch {
|
|
2188
|
+
return null;
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2172
2191
|
async function runAgent(goal, deps, emit) {
|
|
2173
2192
|
const { client: client2, models, policy, sessionId, cwd } = deps;
|
|
2174
2193
|
let totalCostUsd = 0;
|
|
@@ -2288,6 +2307,26 @@ async function runAgent(goal, deps, emit) {
|
|
|
2288
2307
|
}
|
|
2289
2308
|
continue;
|
|
2290
2309
|
}
|
|
2310
|
+
const textCall = useTools ? parseTextToolCall(result.content) : null;
|
|
2311
|
+
if (textCall) {
|
|
2312
|
+
stepToolCalls++;
|
|
2313
|
+
emit({ type: "tool-call", name: textCall.function.name, args: textCall.function.arguments });
|
|
2314
|
+
const outcome = executeTool(textCall.function.name, textCall.function.arguments, toolCtx);
|
|
2315
|
+
emit({ type: "tool-result", name: textCall.function.name, result: outcome.result });
|
|
2316
|
+
if (outcome.finishSummary != null) {
|
|
2317
|
+
summary = outcome.finishSummary;
|
|
2318
|
+
finishedBy = "finish-tool";
|
|
2319
|
+
break;
|
|
2320
|
+
}
|
|
2321
|
+
messages.push({ role: "assistant", content: result.content });
|
|
2322
|
+
messages.push({
|
|
2323
|
+
role: "user",
|
|
2324
|
+
content: `Tool ${textCall.function.name} returned:
|
|
2325
|
+
${outcome.result}
|
|
2326
|
+
Continue with this step. When the objective is met, reply with ONLY {"name":"finish","arguments":{"summary":"<one line>"}}.`
|
|
2327
|
+
});
|
|
2328
|
+
continue;
|
|
2329
|
+
}
|
|
2291
2330
|
summary = result.content || summary;
|
|
2292
2331
|
if (summary) finishedBy = "text";
|
|
2293
2332
|
break;
|
|
@@ -2344,7 +2383,8 @@ function stepSystemPrompt(goal, step, priorSummaries, useTools) {
|
|
|
2344
2383
|
What previous steps accomplished:
|
|
2345
2384
|
${priorSummaries.join("\n")}` : "";
|
|
2346
2385
|
const toolNote = useTools ? `
|
|
2347
|
-
You may use the provided tools (read_file, write_file, list_dir, run_command). Call the \`finish\` tool with a one-line summary when this step's objective is met
|
|
2386
|
+
You may use the provided tools (read_file, write_file, list_dir, run_command). Call the \`finish\` tool with a one-line summary when this step's objective is met.
|
|
2387
|
+
If you cannot call tools natively, reply with ONLY one JSON object per turn, no prose: {"name":"<tool>","arguments":{...}}` : `
|
|
2348
2388
|
Return a concise result for this step. Do not ask the user questions.`;
|
|
2349
2389
|
return `You are the "${step.type}" stage of an autonomous coding agent.
|
|
2350
2390
|
Overall goal: ${goal}
|
|
@@ -2570,7 +2610,7 @@ function truncate2(s, n) {
|
|
|
2570
2610
|
|
|
2571
2611
|
// src/index.ts
|
|
2572
2612
|
var program = new Command();
|
|
2573
|
-
program.name("poly").description("Polymath \u2014 cost-optimized, multi-model TUI coding agent").version("0.3.
|
|
2613
|
+
program.name("poly").description("Polymath \u2014 cost-optimized, multi-model TUI coding agent").version("0.3.1");
|
|
2574
2614
|
function client(config) {
|
|
2575
2615
|
return new OpenRouterClient({
|
|
2576
2616
|
apiKey: resolveApiKey(config),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polymath-agent",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Polymath — a cost-optimized, multi-model TUI coding agent. Decomposes work into typed tasks, routes each task to the cheapest capable model via OpenRouter, and logs real usage/cost by date + model.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|