fix tool config in SDK docs

This commit is contained in:
Maximilian
2026-05-11 00:32:19 +02:00
parent df72d5eefe
commit 74739567b9

View File

@@ -54,7 +54,7 @@ The main factory function for a single `AgentSession`.
`createAgentSession()` uses a `ResourceLoader` to supply extensions, skills, prompt templates, themes, and context files. If you do not provide one, it uses `DefaultResourceLoader` with standard discovery. `createAgentSession()` uses a `ResourceLoader` to supply extensions, skills, prompt templates, themes, and context files. If you do not provide one, it uses `DefaultResourceLoader` with standard discovery.
```typescript ```typescript
import { createAgentSession } from "@earendil-works/pi-coding-agent"; import { createAgentSession, SessionManager } from "@earendil-works/pi-coding-agent";
// Minimal: defaults with DefaultResourceLoader // Minimal: defaults with DefaultResourceLoader
const { session } = await createAgentSession(); const { session } = await createAgentSession();
@@ -62,7 +62,7 @@ const { session } = await createAgentSession();
// Custom: override specific options // Custom: override specific options
const { session } = await createAgentSession({ const { session } = await createAgentSession({
model: myModel, model: myModel,
tools: [readTool, bashTool], tools: ["read", "bash"],
sessionManager: SessionManager.inMemory(), sessionManager: SessionManager.inMemory(),
}); });
``` ```
@@ -466,64 +466,50 @@ const { session } = await createAgentSession({ resourceLoader: loader });
### Tools ### Tools
```typescript Use tool names, not imported tool instances.
import {
codingTools, // read, bash, edit, write (default)
readOnlyTools, // read, grep, find, ls
readTool, bashTool, editTool, writeTool,
grepTool, findTool, lsTool,
} from "@earendil-works/pi-coding-agent";
// Use built-in tool set - Built-in tool names: `read`, `bash`, `edit`, `write`, `grep`, `find`, `ls`
- Default built-ins: `read`, `bash`, `edit`, `write`
- `noTools: "all"` disables all tools
- `noTools: "builtin"` disables default built-ins while keeping extension and custom tools enabled
```typescript
import { createAgentSession } from "@earendil-works/pi-coding-agent";
// Read-only mode
const { session } = await createAgentSession({ const { session } = await createAgentSession({
tools: readOnlyTools, tools: ["read", "grep", "find", "ls"],
}); });
// Pick specific tools // Pick specific tools
const { session } = await createAgentSession({ const { session } = await createAgentSession({
tools: [readTool, bashTool, grepTool], tools: ["read", "bash", "grep"],
}); });
``` ```
#### Tools with Custom cwd #### Tools with Custom cwd
**Important:** The pre-built tool instances (`readTool`, `bashTool`, etc.) use `process.cwd()` for path resolution. When you specify a custom `cwd` AND provide explicit `tools`, you must use the tool factory functions to ensure paths resolve correctly: When you pass a custom `cwd`, `createAgentSession()` builds selected built-in tools for that cwd.
```typescript ```typescript
import { import { createAgentSession, SessionManager } from "@earendil-works/pi-coding-agent";
createCodingTools, // Creates [read, bash, edit, write] for specific cwd
createReadOnlyTools, // Creates [read, grep, find, ls] for specific cwd
createReadTool,
createBashTool,
createEditTool,
createWriteTool,
createGrepTool,
createFindTool,
createLsTool,
} from "@earendil-works/pi-coding-agent";
const cwd = "/path/to/project"; const cwd = "/path/to/project";
// Use factory for tool sets // Use default tools for custom cwd
const { session } = await createAgentSession({ const { session } = await createAgentSession({
cwd, cwd,
tools: createCodingTools(cwd), // Tools resolve paths relative to cwd sessionManager: SessionManager.inMemory(cwd),
}); });
// Or pick specific tools // Or pick specific tools for custom cwd
const { session } = await createAgentSession({ const { session } = await createAgentSession({
cwd, cwd,
tools: [createReadTool(cwd), createBashTool(cwd), createGrepTool(cwd)], tools: ["read", "bash", "grep"],
sessionManager: SessionManager.inMemory(cwd),
}); });
``` ```
**When you don't need factories:**
- If you omit `tools`, pi automatically creates them with the correct `cwd`
- If you use `process.cwd()` as your `cwd`, the pre-built instances work fine
**When you must use factories:**
- When you specify both `cwd` (different from `process.cwd()`) AND `tools`
> See [examples/sdk/05-tools.ts](../examples/sdk/05-tools.ts) > See [examples/sdk/05-tools.ts](../examples/sdk/05-tools.ts)
### Custom Tools ### Custom Tools
@@ -556,6 +542,8 @@ Use `defineTool()` for standalone definitions and arrays like `customTools: [myT
Custom tools passed via `customTools` are combined with extension-registered tools. Extensions loaded by the ResourceLoader can also register tools via `pi.registerTool()`. Custom tools passed via `customTools` are combined with extension-registered tools. Extensions loaded by the ResourceLoader can also register tools via `pi.registerTool()`.
If you pass `tools`, include each custom or extension tool name you want enabled, for example `tools: ["read", "bash", "my_tool"]`.
> See [examples/sdk/05-tools.ts](../examples/sdk/05-tools.ts) > See [examples/sdk/05-tools.ts](../examples/sdk/05-tools.ts)
### Extensions ### Extensions
@@ -885,12 +873,10 @@ import { getModel } from "@earendil-works/pi-ai";
import { Type } from "typebox"; import { Type } from "typebox";
import { import {
AuthStorage, AuthStorage,
bashTool,
createAgentSession, createAgentSession,
DefaultResourceLoader, DefaultResourceLoader,
defineTool, defineTool,
ModelRegistry, ModelRegistry,
readTool,
SessionManager, SessionManager,
SettingsManager, SettingsManager,
} from "@earendil-works/pi-coding-agent"; } from "@earendil-works/pi-coding-agent";
@@ -944,7 +930,7 @@ const { session } = await createAgentSession({
authStorage, authStorage,
modelRegistry, modelRegistry,
tools: [readTool, bashTool], tools: ["read", "bash", "status"],
customTools: [statusTool], customTools: [statusTool],
resourceLoader: loader, resourceLoader: loader,
@@ -1123,13 +1109,7 @@ defineTool
SessionManager SessionManager
SettingsManager SettingsManager
// Built-in tools (use process.cwd()) // Tool factories
codingTools
readOnlyTools
readTool, bashTool, editTool, writeTool
grepTool, findTool, lsTool
// Tool factories (for custom cwd)
createCodingTools createCodingTools
createReadOnlyTools createReadOnlyTools
createReadTool, createBashTool, createEditTool, createWriteTool createReadTool, createBashTool, createEditTool, createWriteTool