Skip to content

Commit ddf3dc6

Browse files
authored
Update agent model and parameters in documentation
Updated the model version for the agent and added additional parameters for agent creation.
1 parent 8c04f65 commit ddf3dc6

File tree

1 file changed

+280
-11
lines changed
  • docs/development/call-core-services

1 file changed

+280
-11
lines changed

docs/development/call-core-services/agent.md

Lines changed: 280 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ ChatLuna 提供了一套更高层的 Agent API,用于组装 Agent,甚至是
99
```ts twoslash
1010
// @noImplicitAny: false
1111
// @strictNullChecks: false
12+
import { Context, Schema } from 'koishi'
13+
14+
const ctx = new Context()
15+
16+
// ---cut---
1217
import type {} from "koishi-plugin-chatluna/services/chat";
1318

1419
const agent = await ctx.chatluna.createAgent({
1520
name: "researcher",
1621
description: "一个负责搜索和整理资料的 Agent",
17-
model: "openai/gpt-5-nano",
22+
model: "openai/gpt-5.4",
1823
embeddings: "openai/text-embedding-3-small",
1924
tools: ["web-search", "web-browser"],
2025
preset: "sydney",
@@ -40,7 +45,30 @@ const agent = await ctx.chatluna.createAgent({
4045

4146
创建完成后,直接使用 `generate()` 即可。
4247

43-
```ts
48+
```ts twoslash
49+
// @noImplicitAny: false
50+
// @strictNullChecks: false
51+
import { Context, Schema } from 'koishi'
52+
53+
const ctx = new Context()
54+
55+
56+
import type {} from "koishi-plugin-chatluna/services/chat";
57+
58+
const agent = await ctx.chatluna.createAgent({
59+
name: "researcher",
60+
description: "一个负责搜索和整理资料的 Agent",
61+
model: "openai/gpt-5.4",
62+
embeddings: "openai/text-embedding-3-small",
63+
tools: ["web-search", "web-browser"],
64+
preset: "sydney",
65+
mode: "tool-calling",
66+
maxSteps: 8,
67+
handleParsingErrors: true,
68+
});
69+
70+
// ---cut---
71+
4472
const result = await agent.generate({
4573
prompt: "搜索 OpenAI 最近一周的重要新闻,并整理成 3 条摘要",
4674
session,
@@ -69,7 +97,29 @@ console.log(result.message);
6997
- `steps`: Agent 事件流
7098
- `result`: 最终结果 Promise
7199

72-
```ts
100+
```ts twoslash
101+
// @noImplicitAny: false
102+
// @strictNullChecks: false
103+
import { Context, Schema } from 'koishi'
104+
105+
const ctx = new Context()
106+
107+
108+
import type {} from "koishi-plugin-chatluna/services/chat";
109+
110+
const agent = await ctx.chatluna.createAgent({
111+
name: "researcher",
112+
description: "一个负责搜索和整理资料的 Agent",
113+
model: "openai/gpt-5.4",
114+
embeddings: "openai/text-embedding-3-small",
115+
tools: ["web-search", "web-browser"],
116+
preset: "sydney",
117+
mode: "tool-calling",
118+
maxSteps: 8,
119+
handleParsingErrors: true,
120+
});
121+
122+
// ---cut---
73123
const stream = await agent.stream({
74124
prompt: "帮我总结这个仓库最近的变更",
75125
session,
@@ -94,7 +144,29 @@ console.log(result.output);
94144

95145
如果你只想监听而不消费流,也可以直接使用:
96146

97-
```ts
147+
```ts twoslash
148+
// @noImplicitAny: false
149+
// @strictNullChecks: false
150+
import { Context, Schema } from 'koishi'
151+
152+
const ctx = new Context()
153+
154+
155+
import type {} from "koishi-plugin-chatluna/services/chat";
156+
157+
const agent = await ctx.chatluna.createAgent({
158+
name: "researcher",
159+
description: "一个负责搜索和整理资料的 Agent",
160+
model: "openai/gpt-5.4",
161+
embeddings: "openai/text-embedding-3-small",
162+
tools: ["web-search", "web-browser"],
163+
preset: "sydney",
164+
mode: "tool-calling",
165+
maxSteps: 8,
166+
handleParsingErrors: true,
167+
});
168+
169+
// ---cut---
98170
await agent.generate({
99171
prompt: "写一个简短总结",
100172
session,
@@ -113,18 +185,28 @@ await agent.generate({
113185

114186
这种方式更适合一次性交接:主 Agent 把某个任务完整交给子 Agent,然后拿回最终结果。
115187

116-
```ts
188+
```ts twoslash
189+
// @noImplicitAny: false
190+
// @strictNullChecks: false
191+
import { Context, Schema } from 'koishi'
192+
193+
const ctx = new Context()
194+
195+
// ---cut---
196+
197+
import type {} from "koishi-plugin-chatluna/services/chat";
198+
117199
const explore = await ctx.chatluna.createAgent({
118200
name: "explore",
119201
description: "搜索代码库并总结结构",
120-
model: "openai/gpt-5-nano",
202+
model: "openai/gpt-5.4-mini",
121203
tools: ["read", "grep", "glob"],
122204
system: "你是一个擅长阅读代码库的子 Agent。",
123205
});
124206

125207
const main = await ctx.chatluna.createAgent({
126208
name: "main",
127-
model: "openai/gpt-5",
209+
model: "openai/gpt-5.4",
128210
tools: ["web-search"],
129211
system: "你是主 Agent,负责根据任务选择合适的工具。",
130212
});
@@ -156,7 +238,15 @@ const delegateTool = explore.asTool({
156238

157239
就应该使用 `createTaskTool()`
158240

159-
```ts
241+
```ts twoslash
242+
// @noImplicitAny: false
243+
// @strictNullChecks: false
244+
import { Context, Schema } from 'koishi'
245+
246+
const ctx = new Context()
247+
248+
// ---cut---
249+
import type {} from "koishi-plugin-chatluna/services/chat";
160250
import {
161251
createTaskTool,
162252
renderAvailableAgents,
@@ -212,7 +302,68 @@ const taskTool = taskRuntime.createTool();
212302

213303
如果你希望主 Agent 直接通过工具调用这些 Sub-Agent,通常会先把 `task` 工具注册到平台,再在主 Agent 里启用它:
214304

215-
```ts
305+
```ts twoslash
306+
// @noImplicitAny: false
307+
// @strictNullChecks: false
308+
import { Context, Schema } from 'koishi'
309+
310+
const ctx = new Context()
311+
312+
313+
import type {} from "koishi-plugin-chatluna/services/chat";
314+
import {
315+
createTaskTool,
316+
renderAvailableAgents,
317+
} from "koishi-plugin-chatluna/llm-core/agent";
318+
319+
const planner = await ctx.chatluna.createAgent({
320+
name: "planner",
321+
description: "拆解任务并输出执行计划",
322+
model: "openai/gpt-5-nano",
323+
tools: ["web-search"],
324+
system: "你负责把任务拆解成简洁可执行的步骤。",
325+
});
326+
327+
const researcher = await ctx.chatluna.createAgent({
328+
name: "researcher",
329+
description: "负责联网搜索和资料整理",
330+
model: "openai/gpt-5-nano",
331+
tools: ["web-search", "web-browser"],
332+
system: "你负责收集资料并给出结构化结论。",
333+
});
334+
335+
const taskRuntime = createTaskTool({
336+
list() {
337+
return [
338+
{
339+
id: planner.id,
340+
name: planner.name,
341+
description: planner.description,
342+
},
343+
{
344+
id: researcher.id,
345+
name: researcher.name,
346+
description: researcher.description,
347+
},
348+
];
349+
},
350+
async get(name) {
351+
if (name === planner.name) {
352+
return { agent: planner };
353+
}
354+
355+
if (name === researcher.name) {
356+
return { agent: researcher };
357+
}
358+
},
359+
async refresh() {
360+
console.log("task state updated");
361+
},
362+
});
363+
364+
// ---cut---
365+
const taskTool = taskRuntime.createTool();
366+
216367
ctx.chatluna.platform.registerTool("task", {
217368
description: taskRuntime.buildToolDescription(),
218369
selector: () => true,
@@ -236,7 +387,66 @@ const main = await ctx.chatluna.createAgent({
236387

237388
后台模式示例:
238389

239-
```ts
390+
```ts twoslash
391+
// @noImplicitAny: false
392+
// @strictNullChecks: false
393+
import { Context, Schema } from 'koishi'
394+
395+
const ctx = new Context()
396+
397+
398+
import type {} from "koishi-plugin-chatluna/services/chat";
399+
import {
400+
createTaskTool,
401+
renderAvailableAgents,
402+
} from "koishi-plugin-chatluna/llm-core/agent";
403+
404+
const planner = await ctx.chatluna.createAgent({
405+
name: "planner",
406+
description: "拆解任务并输出执行计划",
407+
model: "openai/gpt-5-nano",
408+
tools: ["web-search"],
409+
system: "你负责把任务拆解成简洁可执行的步骤。",
410+
});
411+
412+
const researcher = await ctx.chatluna.createAgent({
413+
name: "researcher",
414+
description: "负责联网搜索和资料整理",
415+
model: "openai/gpt-5-nano",
416+
tools: ["web-search", "web-browser"],
417+
system: "你负责收集资料并给出结构化结论。",
418+
});
419+
420+
const taskRuntime = createTaskTool({
421+
list() {
422+
return [
423+
{
424+
id: planner.id,
425+
name: planner.name,
426+
description: planner.description,
427+
},
428+
{
429+
id: researcher.id,
430+
name: researcher.name,
431+
description: researcher.description,
432+
},
433+
];
434+
},
435+
async get(name) {
436+
if (name === planner.name) {
437+
return { agent: planner };
438+
}
439+
440+
if (name === researcher.name) {
441+
return { agent: researcher };
442+
}
443+
},
444+
async refresh() {
445+
console.log("task state updated");
446+
},
447+
});
448+
449+
// ---cut---
240450
const result = await taskRuntime.runTask(
241451
{
242452
action: "run",
@@ -259,7 +469,66 @@ console.log(result);
259469

260470
后续你可以继续:
261471

262-
```ts
472+
```ts twoslash
473+
// @noImplicitAny: false
474+
// @strictNullChecks: false
475+
import { Context, Schema } from 'koishi'
476+
477+
const ctx = new Context()
478+
479+
480+
import type {} from "koishi-plugin-chatluna/services/chat";
481+
import {
482+
createTaskTool,
483+
renderAvailableAgents,
484+
} from "koishi-plugin-chatluna/llm-core/agent";
485+
486+
const planner = await ctx.chatluna.createAgent({
487+
name: "planner",
488+
description: "拆解任务并输出执行计划",
489+
model: "openai/gpt-5-nano",
490+
tools: ["web-search"],
491+
system: "你负责把任务拆解成简洁可执行的步骤。",
492+
});
493+
494+
const researcher = await ctx.chatluna.createAgent({
495+
name: "researcher",
496+
description: "负责联网搜索和资料整理",
497+
model: "openai/gpt-5-nano",
498+
tools: ["web-search", "web-browser"],
499+
system: "你负责收集资料并给出结构化结论。",
500+
});
501+
502+
const taskRuntime = createTaskTool({
503+
list() {
504+
return [
505+
{
506+
id: planner.id,
507+
name: planner.name,
508+
description: planner.description,
509+
},
510+
{
511+
id: researcher.id,
512+
name: researcher.name,
513+
description: researcher.description,
514+
},
515+
];
516+
},
517+
async get(name) {
518+
if (name === planner.name) {
519+
return { agent: planner };
520+
}
521+
522+
if (name === researcher.name) {
523+
return { agent: researcher };
524+
}
525+
},
526+
async refresh() {
527+
console.log("task state updated");
528+
},
529+
});
530+
531+
// ---cut---
263532
await taskRuntime.runTask({ action: "list" }, runConfig);
264533
await taskRuntime.runTask({ action: "status", id: "task-id" }, runConfig);
265534
await taskRuntime.runTask(

0 commit comments

Comments
 (0)