add deferred tools support for kimi in openai-completions api
This commit is contained in:
@@ -36,6 +36,7 @@ cp permission-gate.ts ~/.pi/agent/extensions/
|
||||
| `questionnaire.ts` | Multi-question input with tab bar navigation between questions |
|
||||
| `tool-override.ts` | Override built-in tools (e.g., add logging/access control to `read`) |
|
||||
| `dynamic-tools.ts` | Register tools after startup (`session_start`) and at runtime via command, with prompt snippets and tool-specific prompt guidelines |
|
||||
| `kimi-deferred-tools.ts` | Search for and progressively activate tools for Kimi's deferred-tool loading protocol |
|
||||
| `structured-output.ts` | Final structured-output tool that returns `terminate: true` so the agent can end on the tool call |
|
||||
| `built-in-tool-renderer.ts` | Custom compact rendering for built-in tools (read, bash, edit, write) while keeping original behavior |
|
||||
| `minimal-mode.ts` | Override built-in tool rendering for minimal display (only tool calls, no output in collapsed mode) |
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Minimal Kimi deferred-tool loading demo.
|
||||
*
|
||||
* pi -e ./kimi-deferred-tools.ts
|
||||
* example prompt: Use the available tools to calculate 100 + 500. Do not calculate it yourself.
|
||||
*/
|
||||
|
||||
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
||||
import { Type } from "typebox";
|
||||
|
||||
function calculate(_expr: string): string {
|
||||
return "42";
|
||||
}
|
||||
|
||||
export default function (pi: ExtensionAPI): void {
|
||||
pi.registerTool({
|
||||
name: "Calculator",
|
||||
label: "Calculator",
|
||||
description: "Evaluate a simple arithmetic expression.",
|
||||
parameters: Type.Object({
|
||||
expr: Type.String({ description: "An expression such as 100 + 500" }),
|
||||
}),
|
||||
async execute(_toolCallId, params) {
|
||||
return {
|
||||
content: [{ type: "text", text: calculate(params.expr) }],
|
||||
details: {},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
pi.registerTool({
|
||||
name: "tool_search",
|
||||
label: "Tool Search",
|
||||
description: "Find and activate tools for a capability.",
|
||||
promptSnippet: "Search for additional tools when the active tools cannot perform the task",
|
||||
parameters: Type.Object({
|
||||
query: Type.String({ description: "Capability to search for" }),
|
||||
}),
|
||||
async execute(_toolCallId, params) {
|
||||
if (!params.query.toLowerCase().includes("calc")) {
|
||||
return {
|
||||
content: [{ type: "text", text: "The relevant tools do not exist." }],
|
||||
details: { matches: [], added: [] },
|
||||
};
|
||||
}
|
||||
|
||||
const active = pi.getActiveTools();
|
||||
const added = active.includes("Calculator") ? [] : ["Calculator"];
|
||||
if (added.length > 0) pi.setActiveTools([...active, ...added]);
|
||||
|
||||
return {
|
||||
content: [{ type: "text", text: "Success. Found 1 matching tool(s)" }],
|
||||
details: { matches: ["Calculator"], added },
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
pi.on("session_start", () => {
|
||||
pi.setActiveTools(["tool_search"]);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user