Skip to content

Commit bf104cb

Browse files
committed
docs: document delegateTask/task_run model override behavior
1 parent 087549e commit bf104cb

10 files changed

Lines changed: 202 additions & 22 deletions

File tree

docs/en/advanced/multi-agent.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ class AgentPool {
7676
strategy?: 'crash' | 'manual';
7777
}): Promise<Agent>;
7878

79-
// Destroy an agent
80-
async destroy(agentId: string): Promise<void>;
79+
// Delete an agent
80+
async delete(agentId: string): Promise<void>;
8181
}
8282
```
8383

@@ -190,7 +190,7 @@ deps.toolRegistry.register('task_run', () => taskRunTool);
190190

191191
When an Agent calls `task_run`:
192192

193-
1. Agent specifies `agentTemplateId`, `prompt`, and optional `context`
193+
1. Agent specifies `agentTemplateId`, `prompt`, optional `context`, and optional `model`
194194
2. SDK creates a sub-Agent with the specified template
195195
3. Sub-Agent processes the task
196196
4. Result returns to parent Agent
@@ -203,6 +203,7 @@ interface TaskRunParams {
203203
prompt: string; // Detailed instructions
204204
agentTemplateId: string; // Template ID to use
205205
context?: string; // Additional context
206+
model?: string | { provider: string; model: string }; // Optional model override
206207
}
207208
```
208209

@@ -217,6 +218,14 @@ interface TaskRunResult {
217218
}
218219
```
219220

221+
**Model Inheritance Notes (`delegateTask`):**
222+
- `task_run` accepts an optional `model` argument; when omitted, delegated sub-Agents reuse the parent Agent's `ModelProvider` instance.
223+
- If you need explicit model control, call `agent.delegateTask(...)` directly:
224+
- omit `model`: inherit parent model instance
225+
- `model: string`: keep parent provider type, override model ID (custom providers require `modelFactory`)
226+
- `model: { provider, model }`: explicitly choose provider + model (custom providers usually require `modelFactory` when provider differs)
227+
- `model: ModelProvider`: use provided provider instance directly
228+
220229
### Sub-Agent Configuration
221230

222231
Configure sub-agent behavior in template:

docs/en/guides/providers.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ const provider = new GeminiProvider(
247247
{
248248
thinking: {
249249
level: 'medium', // 'minimal' | 'low' | 'medium' | 'high'
250-
includeThoughts: true,
251250
},
252251
}
253252
);

docs/en/guides/thinking.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ const provider = new GeminiProvider(
101101
{
102102
thinking: {
103103
level: 'medium', // 'minimal' | 'low' | 'medium' | 'high'
104-
includeThoughts: true,
105104
},
106105
reasoningTransport: 'text',
107106
}

docs/en/guides/tools.md

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,65 @@ const agent = await Agent.create({
6060

6161
### Task (Sub-Agent)
6262

63-
- `task_run`: Dispatch sub-Agents from template pool, supports `subagent_type`, `context`, `model_name` parameters
64-
- Templates can limit depth and available templates via `runtime.subagents`
63+
- `task_run`: Delegate complex work to a sub-Agent selected from your template pool.
64+
- Parameters:
65+
- `description`: Short task title (recommended 3-5 words)
66+
- `prompt`: Detailed instructions for the sub-Agent
67+
- `agentTemplateId`: Must match a registered template ID
68+
- `context`: Optional extra background (appended to the prompt)
69+
- `model`: Optional model override
70+
- `string`: keep parent provider, override model ID
71+
- `{ provider, model }`: explicitly choose provider + model
72+
- Return fields:
73+
- `status`: `ok` or `paused`
74+
- `template`: Template ID that was used
75+
- `text`: Sub-Agent output
76+
- `permissionIds`: Pending permission IDs (if any)
77+
- Templates can restrict delegation depth and allowed template IDs via `runtime.subagents`.
78+
79+
**Minimal Example:**
80+
81+
```typescript
82+
import { createTaskRunTool } from '@shareai-lab/kode-sdk';
83+
84+
const templates = [
85+
{ id: 'researcher', system: 'Research and return structured findings.', whenToUse: 'Need search + analysis' },
86+
{ id: 'writer', system: 'Turn findings into publishable copy.', whenToUse: 'Need final draft' },
87+
];
88+
89+
const taskRunTool = createTaskRunTool(templates);
90+
deps.toolRegistry.register('task_run', () => taskRunTool);
91+
92+
// Example tool-call args:
93+
// {
94+
// "description": "Research pricing",
95+
// "prompt": "Analyze 3 competitors and provide a price table plus recommended range.",
96+
// "agentTemplateId": "researcher",
97+
// "context": "Target market: North America SMB",
98+
// "model": { "provider": "openai", "model": "gpt-4.1-mini" }
99+
// }
100+
```
101+
102+
**Common Errors:**
103+
- `Agent template 'xxx' not found`: `agentTemplateId` is not in the `createTaskRunTool(templates)` list.
104+
- Delegation stops unexpectedly: check `runtime.subagents` limits (depth/allowed templates).
105+
106+
**delegateTask Model Behavior (Important):**
107+
- In `task_run`, `model` is optional. If omitted, sub-Agent reuses parent Agent's `ModelProvider` instance by default.
108+
- If you call `agent.delegateTask(...)` directly, model resolution is:
109+
- `model` omitted: reuse parent `ModelProvider` instance (no `modelFactory` required)
110+
- `model` is `string`: keep parent provider type and only override model ID (for custom providers, this path requires `modelFactory`)
111+
- `model` is `{ provider, model }`: explicitly choose provider + model (if provider differs from parent, custom providers usually require `modelFactory`)
112+
- `model` is `ModelProvider`: use that instance directly
113+
114+
```typescript
115+
// Direct call with explicit model override
116+
await agent.delegateTask({
117+
templateId: 'researcher',
118+
prompt: 'Analyze competitors and produce a pricing matrix.',
119+
model: 'gpt-4.1', // same provider type as parent, model id overridden
120+
});
121+
```
65122

66123
### Skills Tool
67124

docs/en/reference/api.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,25 @@ Creates a forked Agent from a snapshot.
130130
async fork(sel?: SnapshotId | { at?: string }): Promise<Agent>
131131
```
132132

133+
#### `agent.delegateTask(config)`
134+
135+
Create and run a delegated sub-Agent task (commonly used by `task_run`).
136+
137+
```typescript
138+
async delegateTask(config: {
139+
templateId: string;
140+
prompt: string;
141+
model?: string | { provider: string; model: string } | ModelProvider;
142+
tools?: string[];
143+
}): Promise<CompleteResult>
144+
```
145+
146+
**Model resolution rules:**
147+
- `model` omitted: reuse parent `ModelProvider` instance.
148+
- `model` is `string`: keep parent provider type and override only model ID (for custom providers, this path requires `modelFactory`).
149+
- `model` is `{ provider, model }`: explicitly choose provider + model (for custom providers, this path usually requires `modelFactory` when provider differs).
150+
- `model` is `ModelProvider`: use the provided instance directly.
151+
133152
#### `agent.status()`
134153

135154
Returns current Agent status.
@@ -237,6 +256,8 @@ interface AgentConfig {
237256
tools?: string[]; // Tool names to enable
238257
exposeThinking?: boolean; // Emit thinking events
239258
retainThinking?: boolean; // Keep thinking in message history
259+
multimodalContinuation?: 'history'; // Preserve multimodal context across turns
260+
multimodalRetention?: { keepRecent?: number }; // Keep recent multimodal items
240261
overrides?: {
241262
permission?: PermissionConfig;
242263
todo?: TodoConfig;
@@ -482,7 +503,7 @@ class AgentTemplateRegistry {
482503
bulkRegister(templates: AgentTemplateDefinition[]): void;
483504
has(id: string): boolean;
484505
get(id: string): AgentTemplateDefinition;
485-
list(): string[];
506+
list(): AgentTemplateDefinition[];
486507
}
487508
```
488509

@@ -521,7 +542,7 @@ class AgentPool {
521542
async status(agentId: string): Promise<AgentStatus | undefined>;
522543
async fork(agentId: string, snapshotSel?: SnapshotId | { at?: string }): Promise<Agent>;
523544
async resume(agentId: string, config: AgentConfig, opts?: { autoRun?: boolean; strategy?: ResumeStrategy }): Promise<Agent>;
524-
async destroy(agentId: string): Promise<void>;
545+
async delete(agentId: string): Promise<void>;
525546
}
526547
```
527548

@@ -573,9 +594,10 @@ import { AnthropicProvider } from '@shareai-lab/kode-sdk';
573594
const provider = new AnthropicProvider(
574595
process.env.ANTHROPIC_API_KEY!,
575596
process.env.ANTHROPIC_MODEL_ID ?? 'claude-sonnet-4-20250514',
597+
process.env.ANTHROPIC_BASE_URL, // optional
598+
process.env.HTTPS_PROXY, // optional
576599
{
577600
thinking: { enabled: true, budgetTokens: 10000 },
578-
cache: { breakpoints: 4 },
579601
}
580602
);
581603
```
@@ -588,6 +610,8 @@ import { OpenAIProvider } from '@shareai-lab/kode-sdk';
588610
const provider = new OpenAIProvider(
589611
process.env.OPENAI_API_KEY!,
590612
process.env.OPENAI_MODEL_ID ?? 'gpt-4o',
613+
process.env.OPENAI_BASE_URL, // optional
614+
process.env.HTTPS_PROXY, // optional
591615
{
592616
api: 'responses',
593617
responses: { reasoning: { effort: 'medium' } },
@@ -603,8 +627,10 @@ import { GeminiProvider } from '@shareai-lab/kode-sdk';
603627
const provider = new GeminiProvider(
604628
process.env.GOOGLE_API_KEY!,
605629
process.env.GEMINI_MODEL_ID ?? 'gemini-2.0-flash',
630+
process.env.GEMINI_BASE_URL, // optional
631+
process.env.HTTPS_PROXY, // optional
606632
{
607-
thinking: { level: 'medium', includeThoughts: true },
633+
thinking: { level: 'medium' },
608634
}
609635
);
610636
```

docs/zh-CN/advanced/multi-agent.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ class AgentPool {
7676
strategy?: 'crash' | 'manual';
7777
}): Promise<Agent>;
7878

79-
// 销毁 agent
80-
async destroy(agentId: string): Promise<void>;
79+
// 删除 agent
80+
async delete(agentId: string): Promise<void>;
8181
}
8282
```
8383

@@ -190,7 +190,7 @@ deps.toolRegistry.register('task_run', () => taskRunTool);
190190

191191
当 Agent 调用 `task_run` 时:
192192

193-
1. Agent 指定 `agentTemplateId``prompt` 和可选的 `context`
193+
1. Agent 指定 `agentTemplateId``prompt`、可选 `context` 与可选 `model`
194194
2. SDK 使用指定模板创建子 Agent
195195
3. 子 Agent 处理任务
196196
4. 结果返回给父 Agent
@@ -203,6 +203,7 @@ interface TaskRunParams {
203203
prompt: string; // 详细指令
204204
agentTemplateId: string; // 使用的模板 ID
205205
context?: string; // 额外上下文
206+
model?: string | { provider: string; model: string }; // 可选模型覆盖
206207
}
207208
```
208209

@@ -217,6 +218,14 @@ interface TaskRunResult {
217218
}
218219
```
219220

221+
**模型继承说明(`delegateTask`):**
222+
- `task_run` 支持可选 `model` 参数;不传时,默认让被委派的子 Agent 复用父 Agent 的 `ModelProvider` 实例。
223+
- 如果你需要显式控制模型,请直接调用 `agent.delegateTask(...)`
224+
- 不传 `model`:继承父模型实例
225+
- `model: string`:保持父 provider 类型,仅覆盖模型 ID(自定义 provider 需配合 `modelFactory`
226+
- `model: { provider, model }`:显式指定 provider + model(provider 与父模型不同时,自定义 provider 通常需配合 `modelFactory`
227+
- `model: ModelProvider`:直接使用传入的 provider 实例
228+
220229
### 子 Agent 配置
221230

222231
在模板中配置子 agent 行为:

docs/zh-CN/guides/providers.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ const provider = new GeminiProvider(
247247
{
248248
thinking: {
249249
level: 'medium', // 'minimal' | 'low' | 'medium' | 'high'
250-
includeThoughts: true,
251250
},
252251
}
253252
);

docs/zh-CN/guides/thinking.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ const provider = new GeminiProvider(
101101
{
102102
thinking: {
103103
level: 'medium', // 'minimal' | 'low' | 'medium' | 'high'
104-
includeThoughts: true,
105104
},
106105
reasoningTransport: 'text',
107106
}

docs/zh-CN/guides/tools.md

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,65 @@ const agent = await Agent.create({
6060

6161
### Task(子代理)
6262

63-
- `task_run`:根据模板池派发子 Agent,支持 `subagent_type``context``model_name` 参数
64-
- 模板可以通过 `runtime.subagents` 限制深度与可选模板
63+
- `task_run`:把复杂任务委派给指定模板的子 Agent。
64+
- 参数说明:
65+
- `description`:任务短标题(建议 3-5 词)
66+
- `prompt`:对子 Agent 的详细执行指令
67+
- `agentTemplateId`:必须是模板池中已注册的模板 ID
68+
- `context`:可选,附加背景信息(会拼接到 prompt 后)
69+
- `model`:可选的模型覆盖参数
70+
- `string`:沿用父 provider,仅覆盖 model ID
71+
- `{ provider, model }`:显式指定 provider + model
72+
- 返回结果:
73+
- `status``ok``paused`
74+
- `template`:实际使用的模板 ID
75+
- `text`:子 Agent 输出
76+
- `permissionIds`:待审批权限 ID 列表(如有)
77+
- 模板可以通过 `runtime.subagents` 限制递归深度和可选模板。
78+
79+
**最小示例:**
80+
81+
```typescript
82+
import { createTaskRunTool } from '@shareai-lab/kode-sdk';
83+
84+
const templates = [
85+
{ id: 'researcher', system: '你负责调研并给出结构化结论。', whenToUse: '需要先检索再总结' },
86+
{ id: 'writer', system: '你负责把结果整理成可发布文稿。', whenToUse: '需要生成最终文稿' },
87+
];
88+
89+
const taskRunTool = createTaskRunTool(templates);
90+
deps.toolRegistry.register('task_run', () => taskRunTool);
91+
92+
// Agent 在工具调用时传参示例:
93+
// {
94+
// "description": "调研竞品定价",
95+
// "prompt": "调研 3 个主要竞品,输出价格对比表和建议定价区间。",
96+
// "agentTemplateId": "researcher",
97+
// "context": "目标市场:北美中小企业",
98+
// "model": { "provider": "openai", "model": "gpt-4.1-mini" }
99+
// }
100+
```
101+
102+
**常见问题:**
103+
- `Agent template 'xxx' not found``agentTemplateId` 不在传入 `createTaskRunTool(templates)` 的列表中。
104+
- 无法继续委派:检查模板的 `runtime.subagents` 配置是否限制了可用模板或深度。
105+
106+
**delegateTask 的模型行为(重要):**
107+
- `task_run``model` 是可选参数;不传时,子 Agent 默认复用父 Agent 的 `ModelProvider` 实例。
108+
- 如果你直接调用 `agent.delegateTask(...)`,模型解析规则为:
109+
- 不传 `model`:复用父 `ModelProvider` 实例(不依赖 `modelFactory`
110+
- `model``string`:沿用父 provider 类型,仅覆盖 model ID(自定义 provider 走这条时需要 `modelFactory`
111+
- `model``{ provider, model }`:显式指定 provider + model(provider 与父模型不同时,自定义 provider 通常需要 `modelFactory`
112+
- `model``ModelProvider`:直接使用该实例
113+
114+
```typescript
115+
// 直接调用并覆盖 model
116+
await agent.delegateTask({
117+
templateId: 'researcher',
118+
prompt: '分析竞品并输出定价矩阵。',
119+
model: 'gpt-4.1', // 继承父 provider 类型,只覆盖模型 ID
120+
});
121+
```
65122

66123
### Skills 工具
67124

0 commit comments

Comments
 (0)