Skip to content

Support per-agent model selection in workflow scripts #9

Description

@Michaelliv

Problem

The agent() global accepts a model option, and phase metadata accepts a model field — but neither actually switches the model the subagent runs on. Today, buildAgentInstructions in src/workflow.ts just stringifies it into the prompt:

if (options.model) lines.push(`Requested model: ${options.model}`);

So it's a hint to the subagent, not a real model switch. All subagents end up on whatever model WorkflowAgent was constructed with (inherited from the parent session).

Proposal

Thread options.model from AgentRunOptions into the createAgentSession({ model }) call in WorkflowAgent.run (src/agent.ts). Roughly:

const { session } = await createAgentSession({
  cwd: this.cwd,
  agentDir: getAgentDir(),
  sessionManager: SessionManager.inMemory(),
  settingsManager: SettingsManager.inMemory({ compaction: { enabled: false } }),
  customTools,
  ...this.sessionOptions,
  ...(options.model ? { model: options.model } : {}),
});

And drop the "Requested model: ..." line from buildAgentInstructions — it becomes redundant once the real switch works.

Why

Lets a workflow pick a cheap/fast model for fan-out scans and a stronger model for synthesis, e.g.:

const findings = await parallel(files.map(f => () =>
  agent(`Audit ${f}`, { model: 'haiku', label: f })
))

const summary = await agent(
  'Synthesize these findings:\n' + JSON.stringify(findings),
  { model: 'sonnet', label: 'synthesis' },
)

Out of scope

Per-phase defaults and workflow-level model config — separate issue if wanted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions