ExecuteToolCall 执行工具调用(通过中间件栈)
( ctx context.Context, req *ToolCallRequest, finalHandler ToolCallHandler, )
| 59 | |
| 60 | // ExecuteToolCall 执行工具调用(通过中间件栈) |
| 61 | func (s *Stack) ExecuteToolCall( |
| 62 | ctx context.Context, |
| 63 | req *ToolCallRequest, |
| 64 | finalHandler ToolCallHandler, |
| 65 | ) (*ToolCallResponse, error) { |
| 66 | // 构建中间件链 |
| 67 | handler := finalHandler |
| 68 | for i := len(s.middlewares) - 1; i >= 0; i-- { |
| 69 | m := s.middlewares[i] |
| 70 | currentHandler := handler |
| 71 | handler = func(ctx context.Context, req *ToolCallRequest) (*ToolCallResponse, error) { |
| 72 | return m.WrapToolCall(ctx, req, currentHandler) |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | return handler(ctx, req) |
| 77 | } |
| 78 | |
| 79 | // OnAgentStart 通知所有中间件 Agent 启动 |
| 80 | func (s *Stack) OnAgentStart(ctx context.Context, agentID string) error { |
no test coverage detected