Browse Source

Sync docs with the defineTool DSL and actual demo code

The architecture cookbook's tool-plugin example now uses defineTool
with typed args (the raw-JSON-Schema + `args: any` example contradicted
the type-safety policy it sits next to); a note explains raw schemas
remain the MCP interop path. The echo-agent README's mock-llm row now
matches the code (registerAdapter(['mock-echo'])) and the echo-tool
row mentions the typed registration.
Tianyi Cui 3 months ago
parent
commit
2b447625fa
2 changed files with 14 additions and 6 deletions
  1. 12 4
      docs/architecture.md
  2. 2 2
      examples/echo-agent/README.md

+ 12 - 4
docs/architecture.md

@@ -261,23 +261,31 @@ implements it **without modifying the loop**:
 
 
 ```ts
 ```ts
 import type { Context } from 'cordis'
 import type { Context } from 'cordis'
+import { defineTool } from '@deepseek-ai/dsh-tools'
 
 
 export const name = 'my-tool'
 export const name = 'my-tool'
 export const inject = ['tools']
 export const inject = ['tools']
 
 
 export function apply(ctx: Context) {
 export function apply(ctx: Context) {
-  ctx.tools.register({
+  ctx.tools.register(defineTool({
     name: 'read_file',
     name: 'read_file',
     description: 'Read a file from disk.',
     description: 'Read a file from disk.',
-    parameters: { type: 'object', properties: { path: { type: 'string' } }, required: ['path'] },
-    async execute(args: any) {
+    parameters: {
+      path: { type: 'string', required: true, description: 'Absolute file path' },
+    },
+    async execute(args) {
+      // args is typed: { path: string }
       const text = await readFile(args.path, 'utf8')
       const text = await readFile(args.path, 'utf8')
       return [{ type: 'text', text }]
       return [{ type: 'text', text }]
     },
     },
-  })
+  }))
 }
 }
 ```
 ```
 
 
+(Raw JSON-Schema `ToolDefinition`s are still accepted by
+`ctx.tools.register()` directly — that's how MCP-sourced tools arrive.
+`defineTool` is the typed sugar for first-party tools.)
+
 ### A hook plugin (permission gate)
 ### A hook plugin (permission gate)
 
 
 ```ts
 ```ts

+ 2 - 2
examples/echo-agent/README.md

@@ -18,8 +18,8 @@ Runnable demo: stdin chat with a scripted mock model and an echo tool.
 
 
 | File | Role | Key patterns demonstrated |
 | File | Role | Key patterns demonstrated |
 |---|---|---|
 |---|---|---|
-| `mock-llm.ts` | `LlmAdapter` registration | `ctx.llm.registerAdapter([])`, streaming chunks with proper `block-start`/`block-end` protocol |
-| `echo-tool.ts` | Tool registration | `ctx.tools.register()`, tool execution returning `ContentBlock[]` |
+| `mock-llm.ts` | `LlmAdapter` registration | `ctx.llm.registerAdapter(['mock-echo'], …)`, streaming chunks with proper `block-start`/`block-end` protocol |
+| `echo-tool.ts` | Tool registration | `ctx.tools.register(defineTool(…))` with typed `execute` args, tool execution returning `ContentBlock[]` |
 | `session-jsonl.ts` | Persistence | `session/event` listener + `session/flush` drain, fiber-dispose cleanup |
 | `session-jsonl.ts` | Persistence | `session/event` listener + `session/flush` drain, fiber-dispose cleanup |
 | `stdio-chat.ts` | UI | `agent/stream-chunk`, `session/event` (tool/*), stdin→send/steer |
 | `stdio-chat.ts` | UI | `agent/stream-chunk`, `session/event` (tool/*), stdin→send/steer |
 | `start.ts` | Bootstrap | `Context` + `Loader` + `plugin-include` wired to `cordis.yml` |
 | `start.ts` | Bootstrap | `Context` + `Loader` + `plugin-include` wired to `cordis.yml` |