mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-20 07:04:34 +00:00
Add SDK usage examples
12 examples showing increasing levels of customization: - 01-minimal: all defaults - 02-custom-model: model and thinking level - 03-custom-prompt: replace or modify prompt - 04-skills: discover, filter, merge skills - 05-tools: built-in tools, custom tools - 06-hooks: logging, blocking, result modification - 07-context-files: AGENTS.md files - 08-slash-commands: file-based commands - 09-api-keys-and-oauth: API key resolution, OAuth config - 10-settings: compaction, retry, terminal settings - 11-sessions: persistence options - 12-full-control: replace everything Also exports FileSlashCommand type from index.ts
This commit is contained in:
parent
86cfe6a436
commit
56121dcac1
15 changed files with 723 additions and 0 deletions
67
packages/coding-agent/examples/sdk/05-tools.ts
Normal file
67
packages/coding-agent/examples/sdk/05-tools.ts
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
* Tools Configuration
|
||||
*
|
||||
* Use built-in tool sets, individual tools, or add custom tools.
|
||||
*/
|
||||
|
||||
import { Type } from "@sinclair/typebox";
|
||||
import {
|
||||
createAgentSession,
|
||||
discoverCustomTools,
|
||||
SessionManager,
|
||||
codingTools, // read, bash, edit, write (default)
|
||||
readOnlyTools, // read, bash
|
||||
readTool,
|
||||
bashTool,
|
||||
grepTool,
|
||||
type CustomAgentTool,
|
||||
} from "../../src/index.js";
|
||||
|
||||
// Read-only mode (no edit/write)
|
||||
const { session: readOnly } = await createAgentSession({
|
||||
tools: readOnlyTools,
|
||||
sessionManager: SessionManager.inMemory(),
|
||||
});
|
||||
console.log("Read-only session created");
|
||||
|
||||
// Custom tool selection
|
||||
const { session: custom } = await createAgentSession({
|
||||
tools: [readTool, bashTool, grepTool],
|
||||
sessionManager: SessionManager.inMemory(),
|
||||
});
|
||||
console.log("Custom tools session created");
|
||||
|
||||
// Inline custom tool (needs TypeBox schema)
|
||||
const weatherTool: CustomAgentTool = {
|
||||
name: "get_weather",
|
||||
label: "Get Weather",
|
||||
description: "Get current weather for a city",
|
||||
parameters: Type.Object({
|
||||
city: Type.String({ description: "City name" }),
|
||||
}),
|
||||
execute: async (_toolCallId, params) => ({
|
||||
content: [{ type: "text", text: `Weather in ${(params as { city: string }).city}: 22°C, sunny` }],
|
||||
details: {},
|
||||
}),
|
||||
};
|
||||
|
||||
const { session } = await createAgentSession({
|
||||
customTools: [{ tool: weatherTool }],
|
||||
sessionManager: SessionManager.inMemory(),
|
||||
});
|
||||
|
||||
session.subscribe((event) => {
|
||||
if (event.type === "message_update" && event.assistantMessageEvent.type === "text_delta") {
|
||||
process.stdout.write(event.assistantMessageEvent.delta);
|
||||
}
|
||||
});
|
||||
|
||||
await session.prompt("What's the weather in Tokyo?");
|
||||
console.log();
|
||||
|
||||
// Merge with discovered tools from cwd/.pi/tools and ~/.pi/agent/tools:
|
||||
// const discovered = await discoverCustomTools();
|
||||
// customTools: [...discovered, { tool: myTool }]
|
||||
|
||||
// Or add paths without replacing discovery:
|
||||
// additionalCustomToolPaths: ["/extra/tools"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue