The smart workflow

A straight-line graph is fine until reality shows up. What if the user did not paste a job description? Running the JD analyzer on an empty string wastes a call and produces garbage downstream. Conditional edges let the graph decide which node to visit next based on state.

cv_agentic_analyzer.py
python
def route_after_extraction(state: CVAnalysisState) -> str:
    """Pick the next node based on what we have in state."""
    jd = state.get("job_description", "") or ""
    if len(jd.strip()) < 10:
        # No meaningful JD. Skip JD analysis and go straight to strengths.
        return "analyze_strengths"
    return "analyze_jd"

workflow.add_conditional_edges(
    "extract_content",
    route_after_extraction,
    {
        "analyze_jd": "analyze_jd",
        "analyze_strengths": "analyze_strengths",
    },
)

A conditional edge calls the router function, reads state, and hands control to the matching node. The graph stays declarative while the routing logic stays in plain Python.

You could, and people do. The cost is that the graph no longer tells the truth. A reader of the graph thinks the JD node always runs. Conditional edges lift the decision up to the orchestration layer so the graph shape matches the actual execution.

Quiz: Quiz

Loading practice…