Code Story

Code Story: Agentic AI

multi-step workflows, chaining calls, human-in-the-loop

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?
  1. When the task has multiple clearly-ordered steps and each step’s output is the next step’s input.
  2. When you want repeatability — the same workflow produces the same kind of output regardless of who runs it.
  3. 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:
  1. Analyze — Read existing code; produce a JSON summary of types, functions, and dependencies.
  2. Plan — Feed the summary to a second call; ask for a numbered implementation plan as JSON.
  3. Generate — Feed the plan to a third call; ask for source code, one file at a time.
  4. 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

ResourceDescription
CodeBites: Agentic AI Track page with multi-step workflow examples.