yao/agent/robot/executor/run.go
Max ac5e3e484f Enhance Task Validation and Update TODO.md
- Introduced a validation mechanism for task results, including a detailed validation structure with scores and issues.
- Updated the input formatter to include validation results in the output, improving clarity on task success and validation status.
- Enhanced test cases to cover the new validation fields and ensure comprehensive testing of task results.
- Revised TODO.md to reflect the addition of validation features and the current status of the agent's development phases.
2026-01-16 10:30:37 +08:00

81 lines
2.1 KiB
Go

package executor
import (
"fmt"
"time"
"github.com/yaoapp/yao/agent/robot/types"
)
// RunExecution executes P3: Run phase
//
// Iterates through tasks and executes each one using the specified executor.
// Supports three executor types: assistant, mcp, process.
//
// Implementation (TODO Phase 7):
// 1. Iterate tasks
// 2. For each task, call executor (assistant/mcp/process)
// 3. Validate results
// 4. Collect results
func (e *Executor) RunExecution(_ *types.Context, exec *types.Execution, _ interface{}) error {
// TODO (Phase 7): Replace with real task execution
// for i, task := range exec.Tasks {
// exec.Current = &types.CurrentState{Task: &task, TaskIndex: i}
// result, err := executeTask(ctx, task, robot)
// if err != nil {
// return err
// }
// exec.Results = append(exec.Results, result)
// }
// Handle empty tasks case
if len(exec.Tasks) == 0 {
exec.Current = &types.CurrentState{
TaskIndex: 0,
Progress: "0/0 tasks",
}
exec.Results = []types.TaskResult{}
return nil
}
// Set current state (will be updated as tasks complete)
exec.Current = &types.CurrentState{
TaskIndex: 0,
Progress: fmt.Sprintf("0/%d tasks", len(exec.Tasks)),
}
// Simulate execution of each task
exec.Results = make([]types.TaskResult, len(exec.Tasks))
for i := range exec.Tasks {
// Update current state
exec.Current.TaskIndex = i
exec.Current.Task = &exec.Tasks[i]
exec.Current.Progress = fmt.Sprintf("%d/%d tasks", i+1, len(exec.Tasks))
// Mark task start time
startTime := time.Now()
exec.Tasks[i].StartTime = &startTime
// Simulate Agent Stream delay for each task
e.simulateStreamDelay()
// Mark task as completed
exec.Tasks[i].Status = types.TaskCompleted
endTime := time.Now()
exec.Tasks[i].EndTime = &endTime
// Generate mock result with actual duration
exec.Results[i] = types.TaskResult{
TaskID: exec.Tasks[i].ID,
Success: true,
Output: fmt.Sprintf("Mock output for %s: Task completed successfully", exec.Tasks[i].ID),
Duration: endTime.Sub(startTime).Milliseconds(),
Validation: &types.ValidationResult{
Passed: true,
Score: 1.0,
},
}
}
return nil
}