A Pythonic Alternative to Graph Construction
LangGraph v1.2+ introduced the Functional API, a radically simpler way to build agents using Python decorators instead of explicit graph construction. While the Graph API (StateGraph, nodes, edges) remains the gold standard for complex workflows, the Functional API lets you build production-grade agents with plain Python functions decorated with @entrypoint and @task.
Core Decorators
| Decorator | Purpose | Analogy |
@entrypoint | Defines the top-level agent function that receives user input and orchestrates tasks | The main() of your agent |
@task | Defines an individual unit of work (LLM call, tool execution, data processing) | A single node in a graph |
Functional API Example
from langgraph.func import entrypoint, task
@task
async def research(topic: str) -> str:
"""Search the web and compile research notes."""
results = await web_search(topic)
return summarize(results)
@task
async def write_draft(notes: str) -> str:
"""Write a blog post draft from research notes."""
return await llm.generate(f"Write a blog post based on: {notes}")
@task
async def review(draft: str) -> dict:
"""Score the draft and provide feedback."""
return await llm.generate_json(f"Score 1-10 and give feedback: {draft}")
@entrypoint
async def blog_writer(topic: str) -> str:
notes = await research(topic)
draft = await write_draft(notes)
result = await review(draft)
while result["score"] < 8:
draft = await write_draft(notes + f"\nFeedback: {result['feedback']}")
result = await review(draft)
return draft
Functional API vs Graph API
| Dimension | Functional API | Graph API (StateGraph) |
| Syntax | Plain Python with decorators | Explicit graph builder (addNode, addEdge) |
| Learning Curve | Low — feels like writing normal async code | Medium — requires understanding graph concepts |
| Persistence | ✅ Automatic via @task checkpoints | ✅ Manual checkpointing at nodes |
| Human-in-Loop | ✅ Via interrupt() inside any task | ✅ Via interrupt nodes |
| Parallelism | Native Python asyncio.gather() | Fan-out/fan-in edges |
| Best For | Linear and moderately complex workflows | Complex multi-agent orchestration with branching |
💡 Key Insight: Each @task call is automatically checkpointed. If your agent crashes mid-execution, it resumes from the last completed task — you get persistence and fault tolerance for free, without writing any graph wiring code.