Skip to main content
Multi-agent blog writing system using LangGraph workflow.

Code

from bindu.penguin.bindufy import bindufy
from graph import build_graph
from schemas import AgentResponse

graph = build_graph()

def handler(messages):
    try:
        # Handle possible dict wrapper
        if isinstance(messages, dict) and "messages" in messages:
            messages = messages["messages"]

        if not messages:
            raise ValueError("No messages received")

        last_message = messages[-1]

        # Support both formats:
        # 1) [{"role": "user", "content": "..."}]
        # 2) ["plain string"]
        if isinstance(last_message, dict):
            query = last_message.get("content", "")
        else:
            query = str(last_message)

        result = graph.invoke({
            "topic": query,
            "plan": None,
            "sections": [],
            "final": None
        })

        return result["final"]

    except Exception as e:
        return AgentResponse(
            answer="Agent execution failed.",
        )

config = {
    "author": "amritanshu9973@gmail.com",
    "name": "langgraph_blog_writing_agent",
    "deployment": {
        "url": "http://localhost:3773",
        "expose": True,
        "cors_origins": ["*"],
    },
    "skills": ["skills/blog_writing_agent"],
}

bindufy(config, handler)

How It Works

Agent Roles
  • Orchestrator: Breaks topic into structured plan with sections and word counts
  • Workers: Write individual sections simultaneously with specific technical depth
  • Reducer: Aggregates sections into final cohesive markdown article
Map-Reduce Pattern
  • Orchestrator creates detailed plan with specific tasks
  • Fanout distributes tasks to parallel workers
  • Workers write sections simultaneously ensuring constraints
  • Reducer combines sections into final article
State Management
  • topic: User input for blog topic
  • plan: Structured outline with sections and requirements
  • sections: Individual written sections from workers
  • final: Completed markdown article
Execution Flow
  1. Orchestrator breaks topic into detailed plan
  2. Workers write sections in parallel
  3. Reducer aggregates and formats final article
  4. Returns cohesive blog post

Run

# Set API key
echo "OPENAI_API_KEY=your-key-here" > examples/langgraph_blog_writing_agent/.env

# Run blog writing agent
uv run examples/langgraph_blog_writing_agent/main.py
Try: “Write a blog post about the future of artificial intelligence in healthcare” Go to frontend and run npm run dev Open http://localhost:5173 and try to chat with the LangGraph blog writing agent

Graph Structure

The agent uses a LangGraph workflow with:
  • orchestrator node for planning
  • worker nodes for parallel section writing
  • reducer node for final aggregation
  • State management across workflow steps