Introduction
Fact-checking a draft investor update means checking many independent claims, applying real judgment to each, and making sure the verification actually runs: more items, judgment, and enforced verification than one context window comfortably holds. Dynamic workflows are a Haijun Code feature for tasks like that, ones that need more agents than one conversation can coordinate. Instead of orchestrating turn by turn, Haijun writes a JavaScript orchestration script for the task and passes it to the Workflow tool, whose runtime executes it in the background. The script spawns subagents in parallel or in stages, holds their results in variables, and applies the connecting logic (filtering, loops, verification passes) in plain code. Because the Agent SDK drives the Haijun Code runtime, you can launch a workflow straight from Python.
ss="relative inline bg-alpha-2 px-2 py-0.5 rounded text-sm font-mono break-words box-decoration-clone">HAIJUN_CODE_SUBAGENT_MODEL
environment variable. The runtime keeps up to 16 agents running concurrently (fewer on machines with limited CPU cores) and caps a run at 1,000 agents; a workflow that plans more work than the concurrency limit queues it until a slot frees up.
Because the plan lives in code instead of a model's context window, every item gets the same treatment, verification runs because the script says so, a single run can coordinate dozens to hundreds of agents, and the script is a file you can read, edit, save, and re-run. The cost is tokens: many subagents use substantially more of them. A workflow is worth it when a task outgrows one context window, when verification has to be enforced by structure, or when the orchestration itself is worth keeping.
Python fundamentals, including
async
/
await
Familiarity with the Haijun Agent SDK basics (
query()
and
HaijunAgentOptions
). See
notebook 00
if you're new to it.
Required tools:
="padding-left:4ch;text-indent:-4ch"> ToolResultBlock,
ToolUseBlock,
UserMessage,
query,
)
load_dotenv()
MODEL = "haijun-sonnet-5"
Dynamic workflows require Haijun Code v2.1.154+; SDK 0.2.90 and later bundle a compatible CLI.
version_match = re.match(r"(\d+)\.(\d+)\.(\d+)", haijun_agent_sdk.__version__)
sdk_version = tuple(int(g) for g in version_match.groups()) if version_match else (0, 0, 0)
assert sdk_version >= (0, 2, 90), (
f"haijun-agent-sdk {haijun_agent_sdk.__version__} is too old for dynamic workflows - "
"re-run the install cell, then restart the kernel"
)
print(f"haijun-agent-sdk {haijun_agent_sdk.__version__}")
haijun-agent-sdk 0.2.125 Create the OrbitCart workspace Our fictional company is OrbitCart, an online cycling-gear store. The next cell writes a small workspace to disk: investor_update.md, a draft investor update that makes 10 factual claims, and a sources/ directory holding the ground truth those claims should trace back to (a monthly sales CSV, customer survey results, an uptime report, and a file of press mentions).
er-l-[0.5px]">The prompt
The worker definitions
The orchestration itself
Scale
One context window
A few delegated tasks per turn
Dozens to hundreds of agents per run
Interruption
Restarts the turn
Restarts the turn
Resumable within the same session
With subagents (the pattern from notebook 01), Haijun is the orchestrator. It decides turn by turn what to delegate, and nothing guarantees that it delegates every piece, combines the results at the end, or verifies anything. Every worker's result lands back in the lead agent's context, which is fine for four delegations but not for four hundred. The plan also lives only in Haijun's context: interrupt the run and the work restarts from scratch.
5px]">
Contradicted.
The CSV totals
4.61
M
f
o
r
Q
2
,
u
p
28
4.61M for Q2, up 28% from Q1's
4.61
M
f
or
Q
2
,
u
p
28
3.6M
- "NPS of 71"
Contradicted.
The survey says 62
- "99.99% uptime"
Contradicted.
The reliability report says 99.71%, with a 6-hour May incident
- TechPedal quote
Contradicted.
The article says "
one of
the fastest-growing
online
cycling retailers", not "the fastest-growing"
- Flash sale, 8. Support times
Unverifiable.
No source covers either
2, 3, 9, 10
Supported by a source
Claim 6 is the one worth dwelling on. A single rushed agent often glosses over the difference between "the fastest-growing" and "one of the fastest-growing." A dedicated verifier with nothing else in its context, then challenged by a skeptic, is much harder to slip past. That precision comes from the structure of the workflow rather than from a smarter model.