Expose tool prompt guidelines to extensions

closes #4879
This commit is contained in:
Mario Zechner
2026-05-28 11:03:25 +02:00
Unverified
parent 17d39ccfd4
commit edd26444af
5 changed files with 12 additions and 6 deletions
+1
View File
@@ -4,6 +4,7 @@
### Fixed
- Fixed `pi.getAllTools()` to expose each tool's `promptGuidelines` for extensions that need per-tool guideline attribution ([#4879](https://github.com/earendil-works/pi/issues/4879)).
- Fixed follow-up messages queued by `agent_end` extension handlers to drain before the agent becomes idle ([#5115](https://github.com/earendil-works/pi-mono/pull/5115) by [@DanielThomas](https://github.com/DanielThomas)).
- Fixed extension input events to report `streamingBehavior` only for prompts actually queued during streaming ([#5107](https://github.com/earendil-works/pi-mono/pull/5107)).
- Fixed fenced `diff` code blocks and other highlight.js scopes to keep theme-aware syntax colors after the `cli-highlight` replacement ([#5092](https://github.com/earendil-works/pi/issues/5092)).
+3 -2
View File
@@ -1493,7 +1493,8 @@ const all = pi.getAllTools();
// [{
// name: "read",
// description: "Read file contents...",
// parameters: ...,
// parameters: ...,
// promptGuidelines: ["Use read to examine files instead of cat or sed."],
// sourceInfo: { path: "<builtin:read>", source: "builtin", scope: "temporary", origin: "top-level" }
// }, ...]
const names = all.map(t => t.name);
@@ -1502,7 +1503,7 @@ const extensionTools = all.filter((t) => t.sourceInfo.source !== "builtin" && t.
pi.setActiveTools(["read", "bash"]); // Switch to read-only
```
`pi.getAllTools()` returns `name`, `description`, `parameters`, and `sourceInfo`.
`pi.getAllTools()` returns `name`, `description`, `parameters`, `promptGuidelines`, and `sourceInfo`.
Typical `sourceInfo.source` values:
- `builtin` for built-in tools
@@ -759,13 +759,14 @@ export class AgentSession {
}
/**
* Get all configured tools with name, description, parameter schema, and source metadata.
* Get all configured tools with name, description, parameter schema, prompt guidelines, and source metadata.
*/
getAllTools(): ToolInfo[] {
return Array.from(this._toolDefinitions.values()).map(({ definition, sourceInfo }) => ({
name: definition.name,
description: definition.description,
parameters: definition.parameters,
promptGuidelines: definition.promptGuidelines,
sourceInfo,
}));
}
@@ -1213,7 +1213,7 @@ export interface ExtensionAPI {
/** Get the list of currently active tool names. */
getActiveTools(): string[];
/** Get all configured tools with parameter schema and source metadata. */
/** Get all configured tools with parameter schema, prompt guidelines, and source metadata. */
getAllTools(): ToolInfo[];
/** Set the active tools by name. */
@@ -1424,8 +1424,8 @@ export type GetSessionNameHandler = () => string | undefined;
export type GetActiveToolsHandler = () => string[];
/** Tool info with name, description, parameter schema, and source metadata */
export type ToolInfo = Pick<ToolDefinition, "name" | "description" | "parameters"> & {
/** Tool info with name, description, parameter schema, prompt guidelines, and source metadata. */
export type ToolInfo = Pick<ToolDefinition, "name" | "description" | "parameters" | "promptGuidelines"> & {
sourceInfo: SourceInfo;
};
@@ -72,6 +72,9 @@ describe("AgentSession dynamic tool registration", () => {
const readTool = allTools.find((tool) => tool.name === "read");
expect(allTools.map((tool) => tool.name)).toContain("dynamic_tool");
expect(dynamicTool?.promptGuidelines).toEqual([
"Use dynamic_tool when the user asks for dynamic behavior tests.",
]);
expect(dynamicTool?.sourceInfo).toMatchObject({
path: "<inline:1>",
source: "inline",