yao/agent/robot/executor/standard/inspiration.go
Max 0c2123bb30 Enhance Input Formatting and Error Handling in Robot Executor
- Introduced a new method to format available resources, improving clarity on the tools and agents accessible to the robot.
- Updated the RunGoals and RunInspiration methods to include resource information in user prompts, ensuring achievable goals and insights.
- Revised error messages in the executor to provide more context, enhancing debugging capabilities.
- Added comprehensive tests for the new resource formatting functionality and updated existing tests to reflect changes in error handling.
- Improved documentation for robot configuration, emphasizing the importance of available resources in goal and task generation.
2026-01-16 16:57:48 +08:00

70 lines
1.9 KiB
Go

package standard
import (
"fmt"
"time"
robottypes "github.com/yaoapp/yao/agent/robot/types"
)
// RunInspiration executes P0: Inspiration phase
// Calls the Inspiration Agent to generate daily briefing
//
// Input:
// - ClockContext from trigger input or current time
// - Robot identity and resources
//
// Output:
// - InspirationReport with markdown content
func (e *Executor) RunInspiration(ctx *robottypes.Context, exec *robottypes.Execution, _ interface{}) error {
// Get robot for identity and resources
robot := exec.GetRobot()
if robot == nil {
return fmt.Errorf("robot not found in execution")
}
// Build clock context from trigger input or current time
var clock *robottypes.ClockContext
if exec.Input != nil && exec.Input.Clock != nil {
clock = exec.Input.Clock
} else {
clock = robottypes.NewClockContext(time.Now(), "")
}
// Get agent ID for inspiration phase
agentID := "__yao.inspiration" // default
if robot.Config != nil && robot.Config.Resources != nil {
agentID = robot.Config.Resources.GetPhaseAgent(robottypes.PhaseInspiration)
}
// Build prompt using InputFormatter
formatter := NewInputFormatter()
userContent := formatter.FormatClockContext(clock, robot)
// Add available resources - critical for generating achievable insights
resourcesContent := formatter.FormatAvailableResources(robot)
if resourcesContent != "" {
userContent += "\n\n" + resourcesContent
}
// Call agent
caller := NewAgentCaller()
result, err := caller.CallWithMessages(ctx, agentID, userContent)
if err != nil {
return fmt.Errorf("inspiration agent (%s) call failed: %w", agentID, err)
}
// Parse response - get markdown content
content := result.GetText()
if content == "" {
return fmt.Errorf("inspiration agent (%s) returned empty response", agentID)
}
// Build InspirationReport
exec.Inspiration = &robottypes.InspirationReport{
Clock: clock,
Content: content,
}
return nil
}