// dynamic-plan.tsx
import { createSmithers, Task, Sequence, Branch } from "smithers-orchestrator";
import { ToolLoopAgent as Agent } from "ai";
import { anthropic } from "@ai-sdk/anthropic";
import { z } from "zod";
const { Workflow, smithers } = createSmithers({
analysis: z.object({
summary: z.string(),
complexity: z.enum(["low", "high"]),
}),
plan: z.object({
steps: z.array(z.string()),
}),
result: z.object({
output: z.string(),
}),
});
const analyzer = new Agent({
model: anthropic("claude-sonnet-4-5-20250929"),
instructions:
"Analyze the given task. Determine if it is low or high complexity. Return a short summary and a complexity rating.",
});
const planner = new Agent({
model: anthropic("claude-sonnet-4-5-20250929"),
instructions: "Break the task into concrete, ordered steps.",
});
const implementer = new Agent({
model: anthropic("claude-sonnet-4-5-20250929"),
instructions: "Implement the requested task and return the result.",
});
export default smithers((ctx) => {
const analysis = ctx.outputMaybe("analysis", { nodeId: "analyze" });
const isComplex = analysis?.complexity === "high";
return (
<Workflow name="dynamic-plan">
<Sequence>
{/* Step 1: Analyze the task */}
<Task id="analyze" output="analysis" agent={analyzer}>
Analyze this task and classify its complexity: "Refactor the authentication
module to support OAuth2 and SAML providers."
</Task>
{/* Step 2: Branch based on complexity */}
<Branch
if={isComplex}
then={
<Sequence>
<Task id="plan" output="plan" agent={planner}>
Create a step-by-step plan for: {analysis?.summary}
</Task>
<Task id="implement" output="result" agent={implementer}>
Execute these steps:{" "}
{ctx
.outputMaybe("plan", { nodeId: "plan" })
?.steps.join(", ")}
</Task>
</Sequence>
}
else={
<Task id="implement" output="result" agent={implementer}>
Quick implementation for: {analysis?.summary}
</Task>
}
/>
</Sequence>
</Workflow>
);
});