Skip to main content
Point at a Python file, get back a structured health report. The python tool node calls a local analyze.py module that uses the standard library ast module to measure line counts, function lengths, and argument complexity — no external dependencies. An LLM then interprets the raw numbers and writes concrete improvement suggestions.

What it demonstrates

  • python tool node calling a local module function
  • Chaining a tool node to a downstream agent via an edge
  • Using {{ analyze.metrics }} to pass tool output into an agent system prompt
  • Reading from CODE_HEALTH_FILE env var for flexible file targeting
  • PYTHONPATH for importing a recipe-local Python module

Prerequisites

The analyze module lives alongside the workflow. Set PYTHONPATH so the runtime can find it:
To analyze your own file instead of the bundled sample.py:

Run it

Analyze your own file:

Workflow

docs/cookbook/code-health-report/workflow.yaml
Python tool node args are not template-interpolated — they are passed as-is to the function. The run_analysis function reads CODE_HEALTH_FILE directly from os.environ, which is why no args are needed here.

How data flows

  1. analyze calls analyze.run_analysis() from the local module. The function reads a Python source file, parses it with ast, and returns a metrics dict (line counts, function count, average function length, max argument count).
  2. The result is written to working.analyze.metrics.
  3. interpret resolves {{ analyze.metrics }} in its system prompt and generates the health report.

Graph

Next steps

Tool Nodes

Full HTTP and Python tool node reference, including module resolution and error handling.

Blind Code Review

Multi-turn refinement: write code, review it, then revise — without the reviewer seeing the spec.