File tree Expand file tree Collapse file tree 3 files changed +330
-208
lines changed
Expand file tree Collapse file tree 3 files changed +330
-208
lines changed Original file line number Diff line number Diff line change @@ -523,7 +523,7 @@ function sidebarDevelopment(): DefaultTheme.SidebarItem[] {
523523 link : "/development/call-core-services/model-tool" ,
524524 } ,
525525 {
526- text : "Agent" ,
526+ text : "Agent 与 Sub-Agent " ,
527527 link : "/development/call-core-services/agent" ,
528528 } ,
529529 {
Original file line number Diff line number Diff line change @@ -85,6 +85,53 @@ ChatLuna 服务是整个系统的核心,用于管理插件、对话、模型
8585
8686创建一个嵌入模型的计算引用。若模型不可用会回退为空嵌入实现。
8787
88+ ### chatluna.createAgent()
89+
90+ - ** options** : ` CreateChatLunaAgentOptions `
91+ - 返回值: ` Promise<ChatLunaAgent> `
92+
93+ 创建一个高层 Agent 实例。这是当前推荐的 Agent 入口。
94+
95+ 最常用的参数只有几个:
96+
97+ - ` model ` : 必填,支持直接传 ` platform/model `
98+ - ` tools ` : 可选,传工具名数组即可
99+ - ` preset ` 或 ` system ` : 二选一;前者复用预设,后者直接写系统提示词
100+ - ` mode ` : 可选,默认 ` tool-calling `
101+ - ` maxSteps ` : 可选,限制最多调用多少轮工具
102+
103+ 返回的 ` ChatLunaAgent ` 主要有 3 个方法:
104+
105+ - ` generate(...) ` : 普通调用
106+ - ` stream(...) ` : 流式调用
107+ - ` asTool(...) ` : 包成工具给别的 Agent 用
108+
109+ 更完整的教程见:[ ` /development/call-core-services/agent ` ] ( /development/call-core-services/agent )
110+
111+ 示例:
112+
113+ ``` ts
114+ import type {} from " koishi-plugin-chatluna/services/chat" ;
115+
116+ const agent = await ctx .chatluna .createAgent ({
117+ name: " researcher" ,
118+ model: " openai/gpt-5-nano" ,
119+ embeddings: " openai/text-embedding-3-small" ,
120+ tools: [" web-search" , " web-browser" ],
121+ preset: " sydney" ,
122+ mode: " tool-calling" ,
123+ maxSteps: 8 ,
124+ });
125+
126+ const result = await agent .generate ({
127+ prompt: " 搜索 OpenAI 最近新闻并整理重点" ,
128+ session ,
129+ conversationId: " conversation-id" ,
130+ });
131+
132+ console .log (result .output );
133+ ```
134+
88135### 属性
89136
90137#### chatluna.platform
You can’t perform that action at this time.
0 commit comments