LangGraph with PraisonAI

Run LangGraph-based agent graphs through PraisonAI's YAML and CLI

LangGraph integration lets you run LangGraph state graphs through PraisonAI’s YAML configuration and CLI — no adapter code required.

Diagram

LangGraph Framework

📄 YAML Config

👥 LangGraph Agents

🧠 State Graph

✅ Result

Quick Start

  1. Install

    Both extras are required for end-to-end use:

    bash
    pip install "praisonai[langgraph]"
    pip install "praisonai-frameworks[langgraph]"
  2. Create agents.yaml
    yaml
    framework: langgraph
    topic: Simple Question Answer
    
    roles:
      researcher:
        role: Helper
        goal: Answer simple questions accurately
        backstory: I am a helpful assistant
        tasks:
          answer:
            description: What is the capital of France? Reply with just the city name.
            expected_output: Paris
  3. Run
    bash
    export OPENAI_API_KEY=<your-key>
    praisonai agents.yaml --framework langgraph

How LangGraph Works

Diagram
LangGraph StateGraphLangGraphAdapterFrameworkAdapterRegistryPraisonAILangGraph StateGraphLangGraphAdapterFrameworkAdapterRegistryPraisonAIcreate(“langgraph”)LangGraphAdapter (entry-point)run(config, llm_config, topic, tools_dict)build StateGraph from roles/tasksexecute task sequence (with context wiring)result text“

YAML Format for LangGraph

LangGraph requires the roles format (not the steps workflow format):

yaml
framework: langgraph
topic: Planet facts

roles:
  researcher:
    role: Research_Analyst
    goal: Gather concise facts
    backstory: Expert researcher
    tasks:
      research:
        description: Name one planet in our solar system. Reply with only the planet name.
        expected_output: A planet name
      summarise:
        description: Write one short sentence describing that planet.
        expected_output: One sentence
        context:
          - research

Direct Adapter Use

Advanced — most users should use the CLI / YAML flow above.

Call the adapter directly without the CLI or YAML loader:

python
from praisonai_frameworks.langgraph.adapter import LangGraphAdapter

config = {
    "framework": "langgraph",
    "topic": "Quick test",
    "roles": {
        "helper": {
            "role": "Assistant",
            "goal": "Answer briefly",
            "backstory": "Helpful assistant",
            "tasks": {
                "answer": {
                    "description": "Reply with exactly the word OK.",
                    "expected_output": "OK",
                }
            },
        }
    },
}
llm_config = [{"model": "gpt-4o-mini", "api_key": "<OPENAI_API_KEY>"}]
result = LangGraphAdapter().run(config, llm_config, "Quick test", tools_dict={})
# result starts with "### LangGraph Output ###"

Verify Installation

Use praisonai doctor to confirm LangGraph is detected:

bash
$ praisonai doctor
✓ Runtime 'langgraph' available
  capabilities: agent_creation, tool_execution, sequential_execution
  supports_handoff: False
  supports_tool_loop: True

Probe programmatically via _framework_availability:

python
from praisonai._framework_availability import is_available

if is_available("langgraph"):
    print("LangGraph is installed and importable")

Pip Extras Reference

ExtraInstallsRequired for
praisonai[langgraph]langgraph>=0.2.0,<2, langgraph-prebuilt>=0.2.0,<2, langchain-core>=0.3.0,<2, langchain-openai>=0.2.0,<2, praisonai-tools>=0.1.0Probe + doctor recognition for LangGraph
praisonai-frameworks[langgraph]LangGraph adapter implementation registered via entry-point groupActually executing framework: langgraph

Troubleshooting

framework='langgraph' is not a valid choice — Pre-#2415 PraisonAI versions hardcode choices=["praisonai","crewai","autogen"]. Upgrade to a version that includes dynamic registry-driven CLI choices, or omit --framework and rely on framework: langgraph in your YAML instead.

Framework 'langgraph' was requested but is not installed — Install the extras listed above. The CLI emits an install hint from get_install_hint("langgraph") pointing to praisonai-frameworks[langgraph].

tool_retry_policy validation error on praisonai.run() — Fixed in PraisonAI #2495 by normalising the RetryPolicy object into a dict before agent-config merge. If you are on a version before #2495, pass tool_retry_policy as a plain dict:

python
tool_retry_policy = {"max_attempts": 3, "delay": 1.0, "backoff_factor": 2.0, "max_delay": 10.0}

Best Practices

When to choose LangGraph over other frameworks

Choose LangGraph when you need explicit state graph control, conditional branching between tasks, or when your team already uses LangChain/LangGraph tooling. For simpler sequential workflows, PraisonAI native or CrewAI have lower overhead. For conversational multi-agent setups, AutoGen v0.2 is the more mature option today.

Use context: to express a graph

The context: field in task definitions maps directly to LangGraph edges. A task with context: [task_a, task_b] receives both task outputs as input context. Model your data dependencies as context lists rather than hard-coding them in task descriptions.

Keep the roles format, not steps

LangGraph via PraisonAI requires the roles: YAML format. The newer steps: + agents: workflow format is only supported by the native praisonai framework. If you migrate an existing steps: workflow to LangGraph, convert each step into a task under a role.

Parse the LangGraph Output sentinel

The adapter wraps its result in ### LangGraph Output ###\n.... Downstream parsers and log scrapers can split on this sentinel to extract the LangGraph result separately from PraisonAI’s own output lines.


Related