Skip to main content
LangGraph provides two different APIs to build agent workflows: the Graph API and the Functional API. Both APIs share the same underlying runtime and can be used together in the same application, but they are designed for different use cases and development preferences. This guide will help you understand when to use each API based on your specific requirements.

Quick decision guide

Use the Graph API when you need:
  • Complex workflow visualization for debugging and documentation
  • Explicit state management with shared data across multiple nodes
  • Conditional branching with multiple decision points
  • Parallel execution paths that need to merge later
  • Team collaboration where visual representation aids understanding
Use the Functional API when you want:
  • Minimal code changes to existing procedural code
  • Standard control flow (if/else, loops, function calls)
  • Function-scoped state without explicit state management
  • Rapid prototyping with less boilerplate
  • Linear workflows with simple branching logic

Detailed comparison

When to use the Graph API

The Graph API uses a declarative approach where you define nodes, edges, and shared state to create a visual graph structure. 1. Complex decision trees and branching logic When your workflow has multiple decision points that depend on various conditions, the Graph API makes these branches explicit and easy to visualize.
2. State management across multiple components When you need to share and coordinate state between different parts of your workflow, the Graph API’s explicit state management is beneficial.
3. Parallel processing with synchronization When you need to run multiple operations in parallel and then combine their results, the Graph API handles this naturally.
4. Team development and documentation The visual nature of the Graph API makes it easier for teams to understand, document, and maintain complex workflows.

When to use the Functional API

The Functional API uses an imperative approach that integrates LangGraph features into standard procedural code. 1. Existing procedural code When you have existing code that uses standard control flow and want to add LangGraph features with minimal refactoring.
2. Linear workflows with simple logic When your workflow is primarily sequential with straightforward conditional logic.
3. Rapid prototyping When you want to quickly test ideas without the overhead of defining state schemas and graph structures.
4. Function-scoped state management When your state is naturally scoped to individual functions and doesn’t need to be shared broadly.

Combining both APIs

You can use both APIs together in the same application. This is useful when different parts of your system have different requirements.

Migration between APIs

From Functional to Graph API

When your functional workflow grows complex, you can migrate to the Graph API:

From Graph to Functional API

When your graph becomes overly complex for simple linear processes:

Summary

Choose the Graph API when you need explicit control over workflow structure, complex branching, parallel processing, or team collaboration benefits. Choose the Functional API when you want to add LangGraph features to existing code with minimal changes, have simple linear workflows, or need rapid prototyping capabilities. Both APIs provide the same core LangGraph features (persistence, streaming, human-in-the-loop, memory) but package them in different paradigms to suit different development styles and use cases.