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

Method ExecuteToolDirect

pkg/agent/agent.go:1111–1130  ·  view source on GitHub ↗

ExecuteToolDirect 直接执行工具(程序化工具调用) 这个方法允许 Agent 或外部代码直接调用工具,绕过 LLM 决策 主要用于程序化工具编排场景

(ctx context.Context, toolName string, input map[string]any)

Source from the content-addressed store, hash-verified

1109// 这个方法允许 Agent 或外部代码直接调用工具,绕过 LLM 决策
1110// 主要用于程序化工具编排场景
1111func (a *Agent) ExecuteToolDirect(ctx context.Context, toolName string, input map[string]any) (any, error) {
1112 a.mu.RLock()
1113 tool, exists := a.toolMap[toolName]
1114 a.mu.RUnlock()
1115
1116 if !exists {
1117 return nil, fmt.Errorf("tool not found: %s", toolName)
1118 }
1119
1120 // 构建工具上下文
1121 tc := a.buildToolContext(ctx)
1122
1123 // 执行工具
1124 result, err := tool.Execute(ctx, input, tc)
1125 if err != nil {
1126 return nil, fmt.Errorf("execute tool %s: %w", toolName, err)
1127 }
1128
1129 return result, nil
1130}
1131
1132// ExecuteToolsDirect 批量直接执行工具(顺序执行)
1133func (a *Agent) ExecuteToolsDirect(ctx context.Context, calls []ToolCall) []ToolCallResult {

Callers 2

ExecuteToolsDirectMethod · 0.95
handleDirectToolCallMethod · 0.45

Calls 2

buildToolContextMethod · 0.95
ExecuteMethod · 0.65

Tested by

no test coverage detected