Run 运行 WorkflowAgent
(ctx context.Context, input string)
| 189 | |
| 190 | // Run 运行 WorkflowAgent |
| 191 | func (wa *WorkflowAgent) Run(ctx context.Context, input string) (string, error) { |
| 192 | wa.mu.RLock() |
| 193 | workflow := wa.workflow |
| 194 | wa.mu.RUnlock() |
| 195 | |
| 196 | if workflow == nil { |
| 197 | return "", errors.New("no workflow attached to agent") |
| 198 | } |
| 199 | |
| 200 | workflowInput := &WorkflowInput{ |
| 201 | Input: input, |
| 202 | } |
| 203 | |
| 204 | result, err := wa.executeWorkflow(ctx, workflowInput) |
| 205 | if err != nil { |
| 206 | return "", err |
| 207 | } |
| 208 | |
| 209 | return wa.formatOutput(result), nil |
| 210 | } |
| 211 | |
| 212 | // RunStream 流式运行 WorkflowAgent |
| 213 | func (wa *WorkflowAgent) RunStream(ctx context.Context, input string) <-chan AgentStreamEvent { |