Merge pull request #4383 from maximilianzuern/docs/fixToolConfig
fix(coding-agent) docs: update tool configuration API in SDK docs
This commit is contained in:
@@ -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
|
Specify which built-in tools to enable:
|
||||||
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
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ The runtime example shows how to build a recreate function that closes over proc
|
|||||||
| `02-custom-model.ts` | Select model and thinking level |
|
| `02-custom-model.ts` | Select model and thinking level |
|
||||||
| `03-custom-prompt.ts` | Replace or modify system prompt |
|
| `03-custom-prompt.ts` | Replace or modify system prompt |
|
||||||
| `04-skills.ts` | Discover, filter, or replace skills |
|
| `04-skills.ts` | Discover, filter, or replace skills |
|
||||||
| `05-tools.ts` | Built-in tools, custom tools |
|
| `05-tools.ts` | Built-in tool allowlists |
|
||||||
| `06-extensions.ts` | Logging, blocking, result modification |
|
| `06-extensions.ts` | Logging, blocking, result modification |
|
||||||
| `07-context-files.ts` | AGENTS.md context files |
|
| `07-context-files.ts` | AGENTS.md context files |
|
||||||
| `08-slash-commands.ts` | File-based slash commands |
|
| `08-slash-commands.ts` | File-based slash commands |
|
||||||
@@ -40,9 +40,6 @@ import {
|
|||||||
ModelRegistry,
|
ModelRegistry,
|
||||||
SessionManager,
|
SessionManager,
|
||||||
SettingsManager,
|
SettingsManager,
|
||||||
codingTools,
|
|
||||||
readOnlyTools,
|
|
||||||
readTool, bashTool, editTool, writeTool,
|
|
||||||
} from "@earendil-works/pi-coding-agent";
|
} from "@earendil-works/pi-coding-agent";
|
||||||
|
|
||||||
// Auth and models setup
|
// Auth and models setup
|
||||||
@@ -64,7 +61,7 @@ await loader.reload();
|
|||||||
const { session } = await createAgentSession({ resourceLoader: loader, authStorage, modelRegistry });
|
const { session } = await createAgentSession({ resourceLoader: loader, authStorage, modelRegistry });
|
||||||
|
|
||||||
// Read-only
|
// Read-only
|
||||||
const { session } = await createAgentSession({ tools: readOnlyTools, authStorage, modelRegistry });
|
const { session } = await createAgentSession({ tools: ["read", "grep", "find", "ls"], authStorage, modelRegistry });
|
||||||
|
|
||||||
// In-memory
|
// In-memory
|
||||||
const { session } = await createAgentSession({
|
const { session } = await createAgentSession({
|
||||||
@@ -92,8 +89,8 @@ const { session } = await createAgentSession({
|
|||||||
authStorage: customAuth,
|
authStorage: customAuth,
|
||||||
modelRegistry: customRegistry,
|
modelRegistry: customRegistry,
|
||||||
resourceLoader,
|
resourceLoader,
|
||||||
tools: [readTool, bashTool],
|
tools: ["read", "bash", "my_tool"],
|
||||||
customTools: [{ tool: myTool }],
|
customTools: [myTool],
|
||||||
sessionManager: SessionManager.inMemory(),
|
sessionManager: SessionManager.inMemory(),
|
||||||
settingsManager: SettingsManager.inMemory(),
|
settingsManager: SettingsManager.inMemory(),
|
||||||
});
|
});
|
||||||
@@ -117,7 +114,7 @@ await session.prompt("Hello");
|
|||||||
| `agentDir` | `~/.pi/agent` | Config directory |
|
| `agentDir` | `~/.pi/agent` | Config directory |
|
||||||
| `model` | From settings/first available | Model to use |
|
| `model` | From settings/first available | Model to use |
|
||||||
| `thinkingLevel` | From settings/"off" | off, low, medium, high |
|
| `thinkingLevel` | From settings/"off" | off, low, medium, high |
|
||||||
| `tools` | `codingTools` | Built-in tools |
|
| `tools` | `["read", "bash", "edit", "write"]` built-ins | Allowlist tool names across built-in, extension, and custom tools |
|
||||||
| `customTools` | `[]` | Additional tool definitions |
|
| `customTools` | `[]` | Additional tool definitions |
|
||||||
| `resourceLoader` | DefaultResourceLoader | Resource loader for extensions, skills, prompts, themes |
|
| `resourceLoader` | DefaultResourceLoader | Resource loader for extensions, skills, prompts, themes |
|
||||||
| `sessionManager` | `SessionManager.create(cwd)` | Persistence |
|
| `sessionManager` | `SessionManager.create(cwd)` | Persistence |
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ function getAttributionHeaders(
|
|||||||
* await loader.reload();
|
* await loader.reload();
|
||||||
* const { session } = await createAgentSession({
|
* const { session } = await createAgentSession({
|
||||||
* model: myModel,
|
* model: myModel,
|
||||||
* tools: [readTool, bashTool],
|
* tools: ["read", "bash"],
|
||||||
* resourceLoader: loader,
|
* resourceLoader: loader,
|
||||||
* sessionManager: SessionManager.inMemory(),
|
* sessionManager: SessionManager.inMemory(),
|
||||||
* });
|
* });
|
||||||
|
|||||||
Reference in New Issue
Block a user