feat: coordinator mode — system prompt injection for orchestration tasks

This commit is contained in:
2026-04-05 23:06:23 +02:00
parent dd9f4e390a
commit 8d3d498245
2 changed files with 65 additions and 0 deletions

View File

@@ -301,9 +301,35 @@ func (e *Engine) buildRequest(ctx context.Context) provider.Request {
)
}
// Inject coordinator guidance for orchestration tasks
if e.cfg.Router != nil {
prompt := ""
for i := len(e.history) - 1; i >= 0; i-- {
if e.history[i].Role == message.RoleUser {
prompt = e.history[i].TextContent()
break
}
}
if router.ClassifyTask(prompt).Type == router.TaskOrchestration {
req.SystemPrompt = coordinatorPrompt() + "\n\n" + req.SystemPrompt
}
}
return req
}
// coordinatorPrompt returns the system prompt block injected for orchestration tasks.
func coordinatorPrompt() string {
return `You are operating in coordinator mode. Your role is to decompose complex work into parallel tasks and orchestrate elfs.
Rules:
- Use spawn_elfs to dispatch N tasks in parallel when they don't share write state.
- Use list_results to discover outputs produced by prior tool calls in this session.
- Pass result file paths to elfs in their prompts so they can read prior outputs with read_result or fs.read.
- Writes are serial: if two elfs would write the same file, sequence them.
- Synthesize elf outputs into a coherent final answer.`
}
func (e *Engine) executeTools(ctx context.Context, calls []message.ToolCall, cb Callback) ([]message.ToolResult, error) {
// Partition into read-only (parallel) and write (serial) batches
type toolCallWithTool struct {