支持多轮工具调用
This commit is contained in:
+3
-1
@@ -1,6 +1,6 @@
|
||||
import { createAnthropic } from '@ai-sdk/anthropic';
|
||||
import { createDeepSeek } from '@ai-sdk/deepseek';
|
||||
import { generateText, streamText, type ModelMessage, type Tool as AITool, type LanguageModel } from 'ai';
|
||||
import { generateText, streamText, stepCountIs, type ModelMessage, type Tool as AITool, type LanguageModel } from 'ai';
|
||||
import type { Tool, ToolResult, Message, AgentConfig, ProviderType } from '../types/index.js';
|
||||
import { buildZodSchema } from '../types/index.js';
|
||||
|
||||
@@ -82,6 +82,7 @@ export class Agent {
|
||||
messages: this.conversationHistory,
|
||||
tools: vercelTools,
|
||||
maxOutputTokens: this.config.maxTokens,
|
||||
stopWhen: stepCountIs(10), // 允许最多 10 轮工具调用
|
||||
onChunk: ({ chunk }) => {
|
||||
if (chunk.type === 'tool-call') {
|
||||
onStream(`\n[调用工具: ${chunk.toolName}]\n`);
|
||||
@@ -114,6 +115,7 @@ export class Agent {
|
||||
messages: this.conversationHistory,
|
||||
tools: vercelTools,
|
||||
maxOutputTokens: this.config.maxTokens,
|
||||
stopWhen: stepCountIs(10), // 允许最多 10 轮工具调用
|
||||
});
|
||||
|
||||
fullResponse = result.text;
|
||||
|
||||
Reference in New Issue
Block a user