支持多轮工具调用

This commit is contained in:
2025-12-10 16:40:48 +08:00
parent 9973e8ec06
commit 4b451b2d58
2 changed files with 183 additions and 1 deletions
+3 -1
View File
@@ -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;