mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
feat(subturn): support stateful iteration for evaluator-optimizer pattern
Add ActualSystemPrompt and InitialMessages fields to SubTurnConfig to enable stateful worker context passing across multiple evaluation iterations. Changes: - Add ActualSystemPrompt field to separate system role from user task description - Add InitialMessages field to preload ephemeral session history before agent loop starts - Add Messages field to ToolResult for carrying session history (internal use, not serialized) - Update runTurn to inject system prompt and preload history from InitialMessages - Update AgentLoopSpawner to map new fields from tools.SubTurnConfig to agent.SubTurnConfig This enables the evaluator-optimizer execution strategy in team tool to maintain worker context across iterations while keeping SubTurn isolation intact.
This commit is contained in:
+10
-1
@@ -1,6 +1,10 @@
|
||||
package tools
|
||||
|
||||
import "encoding/json"
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/sipeed/picoclaw/pkg/providers"
|
||||
)
|
||||
|
||||
// ToolResult represents the structured return value from tool execution.
|
||||
// It provides clear semantics for different types of results and supports
|
||||
@@ -34,6 +38,11 @@ type ToolResult struct {
|
||||
// Media contains media store refs produced by this tool.
|
||||
// When non-empty, the agent will publish these as OutboundMediaMessage.
|
||||
Media []string `json:"media,omitempty"`
|
||||
|
||||
// Messages holds the ephemeral session history after execution.
|
||||
// Only populated by SubTurn executions; used by evaluator_optimizer
|
||||
// to carry stateful worker context across evaluation iterations.
|
||||
Messages []providers.Message `json:"-"`
|
||||
}
|
||||
|
||||
// NewToolResult creates a basic ToolResult with content for the LLM.
|
||||
|
||||
+12
-10
@@ -17,15 +17,17 @@ type SubTurnSpawner interface {
|
||||
|
||||
// SubTurnConfig holds configuration for spawning a sub-turn.
|
||||
type SubTurnConfig struct {
|
||||
Model string
|
||||
Tools []Tool
|
||||
SystemPrompt string
|
||||
MaxTokens int
|
||||
Temperature float64
|
||||
Async bool // true for async (spawn), false for sync (subagent)
|
||||
Critical bool // continue running after parent finishes gracefully
|
||||
Timeout time.Duration // 0 = use default (5 minutes)
|
||||
MaxContextRunes int // 0 = auto, -1 = no limit, >0 = explicit limit
|
||||
Model string
|
||||
Tools []Tool
|
||||
SystemPrompt string
|
||||
MaxTokens int
|
||||
Temperature float64
|
||||
Async bool // true for async (spawn), false for sync (subagent)
|
||||
Critical bool // continue running after parent finishes gracefully
|
||||
Timeout time.Duration // 0 = use default (5 minutes)
|
||||
MaxContextRunes int // 0 = auto, -1 = no limit, >0 = explicit limit
|
||||
ActualSystemPrompt string
|
||||
InitialMessages []providers.Message
|
||||
}
|
||||
|
||||
type SubagentTask struct {
|
||||
@@ -203,7 +205,7 @@ After completing the task, provide a clear summary of what was done.`
|
||||
MaxIterations: maxIter,
|
||||
LLMOptions: llmOptions,
|
||||
}, messages, task.OriginChannel, task.OriginChatID)
|
||||
|
||||
|
||||
if err == nil {
|
||||
result = &ToolResult{
|
||||
ForLLM: fmt.Sprintf(
|
||||
|
||||
Reference in New Issue
Block a user