fix(agent): align tools + preserve indentation

This commit is contained in:
Peter Steinberger
2026-01-05 17:55:20 +00:00
parent 196eb86e38
commit 7c89ce93b5
12 changed files with 88 additions and 46 deletions

View File

@@ -1,7 +1,12 @@
import fs from "node:fs/promises";
import os from "node:os";
import type { AgentMessage, ThinkingLevel } from "@mariozechner/pi-agent-core";
import type {
AgentMessage,
AgentToolResult,
AgentToolUpdateCallback,
ThinkingLevel,
} from "@mariozechner/pi-agent-core";
import type { Api, AssistantMessage, Model } from "@mariozechner/pi-ai";
import {
buildSystemPrompt,
@@ -11,6 +16,7 @@ import {
SessionManager,
SettingsManager,
type Skill,
type ToolDefinition,
} from "@mariozechner/pi-coding-agent";
import type { ThinkLevel, VerboseLevel } from "../auto-reply/thinking.js";
import { formatToolAggregate } from "../auto-reply/tool-meta.js";
@@ -52,6 +58,35 @@ import {
import { buildAgentSystemPromptAppend } from "./system-prompt.js";
import { loadWorkspaceBootstrapFiles } from "./workspace.js";
function toToolDefinitions(tools: { execute: unknown }[]): ToolDefinition[] {
return tools.map((tool) => {
const record = tool as {
name?: unknown;
label?: unknown;
description?: unknown;
parameters?: unknown;
execute: (
toolCallId: string,
params: unknown,
signal?: AbortSignal,
onUpdate?: AgentToolUpdateCallback<unknown>,
) => Promise<AgentToolResult<unknown>>;
};
const name = typeof record.name === "string" ? record.name : "tool";
return {
name,
label: typeof record.label === "string" ? record.label : name,
description:
typeof record.description === "string" ? record.description : "",
// biome-ignore lint/suspicious/noExplicitAny: TypeBox schema from pi-agent-core uses a different module instance.
parameters: record.parameters as any,
execute: async (toolCallId, params, onUpdate, _ctx, signal) => {
return await record.execute(toolCallId, params, signal, onUpdate);
},
} satisfies ToolDefinition;
});
}
export type EmbeddedPiAgentMeta = {
sessionId: string;
provider: string;
@@ -412,7 +447,9 @@ export async function runEmbeddedPiAgent(params: {
// Split tools into built-in (recognized by pi-coding-agent SDK) and custom (clawdbot-specific)
const builtInToolNames = new Set(["read", "bash", "edit", "write"]);
const builtInTools = tools.filter((t) => builtInToolNames.has(t.name));
const customTools = tools.filter((t) => !builtInToolNames.has(t.name));
const customTools = toToolDefinitions(
tools.filter((t) => !builtInToolNames.has(t.name)),
);
const { session } = await createAgentSession({
cwd: resolvedWorkspace,