Build extensible agent harness with interactive chat loop
This commit is contained in:
42
extensions/example.ts
Normal file
42
extensions/example.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import type { Extension } from "../src/types.js";
|
||||
|
||||
const exampleExtension: Extension = async ({
|
||||
registerTool,
|
||||
registerCommand,
|
||||
on,
|
||||
addSystemPrompt
|
||||
}) => {
|
||||
await registerTool({
|
||||
name: "echo",
|
||||
description: "Echo text back exactly as provided.",
|
||||
parameters: {
|
||||
type: "object",
|
||||
properties: {
|
||||
text: { type: "string" }
|
||||
},
|
||||
required: ["text"],
|
||||
additionalProperties: false
|
||||
},
|
||||
execute(input: { text: string }) {
|
||||
return input.text;
|
||||
}
|
||||
});
|
||||
|
||||
await registerCommand({
|
||||
name: "tools",
|
||||
description: "Show tools registered by the example extension.",
|
||||
execute() {
|
||||
return "Example extension tools: echo";
|
||||
}
|
||||
});
|
||||
|
||||
addSystemPrompt("The echo tool is available when exact repetition is useful.");
|
||||
|
||||
on("tool.call.completed", ({ tool }) => {
|
||||
if (tool === "echo") {
|
||||
// Placeholder for extension-side behavior such as metrics or persistence.
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export default exampleExtension;
|
||||
Reference in New Issue
Block a user