CodeStory_AgenticAI.html
copyright © James Fawcett
Revised: 05/04/2026
6. Agentic AI
An agentic workflow chains multiple agent calls together, with the output of one
becoming the input of the next. Each call can have a different focus: analyze,
plan, generate, test. This chapter covers how to structure multi-step workflows,
how to pass state between calls, and where to add human-in-the-loop checkpoints.
When does autonomy help?
- When the task has multiple clearly-ordered steps and each step’s
output is the next step’s input.
- When you want repeatability — the same workflow produces the same
kind of output regardless of who runs it.
- When the individual steps are too small to justify a full CLI session
but too many to do manually each time.
6.1 Analyze → Plan → Generate → Test
A four-call workflow for producing a new module:
- Analyze — Read existing code; produce a JSON summary
of types, functions, and dependencies.
- Plan — Feed the summary to a second call; ask for a
numbered implementation plan as JSON.
- Generate — Feed the plan to a third call; ask for
source code, one file at a time.
- Test — Run the generated code, capture stdout/stderr,
feed errors back into a fourth call for a fix.
6.2 Passing State Between Calls
Use plain Python data structures to carry results forward. A dict
or dataclass per step is enough for most workflows. For long-running
pipelines, serialize to a JSON file so a failed step can be retried without
re-running the earlier ones.
6.3 Human-in-the-Loop Checkpoints
Pause after high-risk steps for user confirmation. A simple
input("Continue? [y/N] ") is enough for a personal script.
For production workflows, write the plan to a file and require an explicit
approval file before the generate step runs.
6.4 References