MCPcopy Create free account
hub / github.com/astercloud/aster / runNonStreamingStep

Method runNonStreamingStep

pkg/agent/processor.go:1257–1358  ·  view source on GitHub ↗

runNonStreamingStep 非流式执行模型步骤(快速模式)

(ctx context.Context)

Source from the content-addressed store, hash-verified

1255
1256// runNonStreamingStep 非流式执行模型步骤(快速模式)
1257func (a *Agent) runNonStreamingStep(ctx context.Context) error {
1258 // 准备工具Schema(包含使用示例)
1259 toolSchemas := make([]provider.ToolSchema, 0, len(a.toolMap))
1260 for _, tool := range a.toolMap {
1261 schema := provider.ToolSchema{
1262 Name: tool.Name(),
1263 Description: tool.Description(),
1264 InputSchema: tool.InputSchema(),
1265 }
1266 // 检查工具是否实现了 ExampleableTool 接口
1267 if exampleable, ok := tool.(tools.ExampleableTool); ok {
1268 examples := exampleable.Examples()
1269 if len(examples) > 0 {
1270 providerExamples := make([]provider.ToolExample, len(examples))
1271 for i, ex := range examples {
1272 providerExamples[i] = provider.ToolExample{
1273 Description: ex.Description,
1274 Input: ex.Input,
1275 Output: ex.Output,
1276 }
1277 }
1278 schema.InputExamples = providerExamples
1279 }
1280 }
1281 toolSchemas = append(toolSchemas, schema)
1282 }
1283
1284 // 准备消息
1285 a.mu.RLock()
1286 messages := make([]types.Message, len(a.messages))
1287 copy(messages, a.messages)
1288 currentSystemPrompt := a.template.SystemPrompt
1289 a.mu.RUnlock()
1290
1291 // 创建Provider选项
1292 streamOpts := &provider.StreamOptions{
1293 Tools: toolSchemas,
1294 System: currentSystemPrompt,
1295 Temperature: 0.7,
1296 MaxTokens: 32000, // Claude 4 Sonnet/Opus 最大支持 64000 output tokens
1297 }
1298
1299 procLog.Debug(ctx, "calling Complete API", map[string]any{"messages": len(messages), "tools": len(toolSchemas)})
1300
1301 // 调用Complete API(非流式)
1302 response, err := a.provider.Complete(ctx, messages, streamOpts)
1303 if err != nil {
1304 return fmt.Errorf("complete call failed: %w", err)
1305 }
1306
1307 // 添加响应消息
1308 a.mu.Lock()
1309 a.messages = append(a.messages, response.Message)
1310 a.mu.Unlock()
1311
1312 // 提取工具调用从ContentBlocks
1313 toolUses := make([]*types.ToolUseBlock, 0)
1314 for _, block := range response.Message.ContentBlocks {

Callers 1

runModelStepMethod · 0.95

Calls 9

executeToolsMethod · 0.95
copyFunction · 0.85
NameMethod · 0.65
DescriptionMethod · 0.65
InputSchemaMethod · 0.65
ExamplesMethod · 0.65
DebugMethod · 0.65
CompleteMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected