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

Method runModelStep

pkg/agent/processor.go:94–294  ·  view source on GitHub ↗

runModelStep 运行模型步骤

(ctx context.Context)

Source from the content-addressed store, hash-verified

92
93// runModelStep 运行模型步骤
94func (a *Agent) runModelStep(ctx context.Context) error {
95 procLog.Info(ctx, "runModelStep started", map[string]any{"agent_id": a.id})
96
97 // 检查执行模式
98 executionMode := a.getExecutionMode()
99 if executionMode == types.ExecutionModeNonStreaming {
100 procLog.Info(ctx, "using NON-STREAMING mode (fast execution)", map[string]any{"agent_id": a.id})
101 return a.runNonStreamingStep(ctx)
102 }
103
104 procLog.Info(ctx, "using STREAMING mode (real-time feedback)", map[string]any{"agent_id": a.id})
105 a.setBreakpoint(types.BreakpointStreamingModel)
106
107 // 准备工具Schema(包含使用示例)
108 toolSchemas := make([]provider.ToolSchema, 0, len(a.toolMap))
109 for _, tool := range a.toolMap {
110 schema := provider.ToolSchema{
111 Name: tool.Name(),
112 Description: tool.Description(),
113 InputSchema: tool.InputSchema(),
114 }
115 // 检查工具是否实现了 ExampleableTool 接口
116 if exampleable, ok := tool.(tools.ExampleableTool); ok {
117 examples := exampleable.Examples()
118 if len(examples) > 0 {
119 providerExamples := make([]provider.ToolExample, len(examples))
120 for i, ex := range examples {
121 providerExamples[i] = provider.ToolExample{
122 Description: ex.Description,
123 Input: ex.Input,
124 Output: ex.Output,
125 }
126 }
127 schema.InputExamples = providerExamples
128 }
129 }
130 toolSchemas = append(toolSchemas, schema)
131 }
132 toolNames := make([]string, len(toolSchemas))
133 for i, ts := range toolSchemas {
134 toolNames[i] = ts.Name
135 }
136 procLog.Debug(ctx, "prepared tool schemas", map[string]any{"agent_id": a.id, "count": len(toolSchemas), "names": toolNames})
137
138 // 调用模型
139 // 确保系统提示词包含工具手册(如果还没有注入)
140 a.mu.RLock()
141 hasManual := strings.Contains(a.template.SystemPrompt, "### Tools Manual")
142 toolMapSize := len(a.toolMap)
143 currentSystemPrompt := a.template.SystemPrompt
144 messages := a.messages // 复制当前消息列表
145 a.mu.RUnlock()
146
147 if !hasManual && toolMapSize > 0 {
148 procLog.Debug(ctx, "manual not found, injecting", map[string]any{"agent_id": a.id, "tool_map_size": toolMapSize})
149 a.injectToolManual()
150 a.mu.RLock()
151 currentSystemPrompt = a.template.SystemPrompt

Callers 2

processMessagesMethod · 0.95
executeToolsMethod · 0.95

Calls 15

getExecutionModeMethod · 0.95
runNonStreamingStepMethod · 0.95
setBreakpointMethod · 0.95
injectToolManualMethod · 0.95
handleStreamResponseMethod · 0.95
shouldTrimMessagesMethod · 0.95
trimMessagesInMemoryMethod · 0.95
executeToolsMethod · 0.95
EventEmitterFuncFuncType · 0.92
EmitProgressMethod · 0.80
EmitControlMethod · 0.80
EmitMonitorMethod · 0.80

Tested by

no test coverage detected