SK.
Back to all posts

Building Intelligent Agents with LangGraph

3 min read

In the evolving landscape of AI engineering, stateless chains are often insufficient for complex tasks. Enter LangGraphβ€”a framework that allows us to build stateful, multi-actor applications with LLMs.

I recently built a multi-agent investment analysis system and learned a lot about what works (and what doesn’t) in production agent architectures. Here’s my synthesis.

Why State Matters

Most simple RAG applications are β€œfire and forget”. User asks question β†’ retrieve context β†’ generate response β†’ done.

But real-world processes involve:

  • Loops: Retry with different strategies if first attempt fails
  • Branches: Different paths based on intermediate results
  • Memory: Carrying context across multiple steps
  • Human-in-the-loop: Pausing for approval, then continuing

LangGraph models these as graphs with nodes (actions) and edges (transitions).

The Mental Model

Think of LangGraph as a state machine for AI:

              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚  START  β”‚
              β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
                   β”‚
                   β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”Œβ”€β”€β”€β”€β”‚   Agent    │────┐
         β”‚    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
    needs_tool          ready_to_respond
         β”‚                      β”‚
         β–Ό                      β–Ό
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚  Tool   β”‚           β”‚  END    β”‚
    β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         └───────────────────┐
                             β”‚
                    back_to_agent

Each node is a function. Each edge is a routing decision.

Key Pattern: The ReAct Loop

The most common pattern is ReAct (Reason + Act):

def create_react_agent(tools: list[Tool], llm: ChatModel):
    """Create a ReAct agent using LangGraph."""
    
    # Define the graph
    graph = StateGraph(AgentState)
    
    # Add nodes
    graph.add_node("agent", call_agent)
    graph.add_node("tools", execute_tools)
    
    # Add edges
    graph.add_edge(START, "agent")
    graph.add_conditional_edges(
        "agent",
        should_continue,  # Function that checks if tools needed
        {
            "continue": "tools",
            "end": END
        }
    )
    graph.add_edge("tools", "agent")  # Loop back
    
    return graph.compile()

The agent reasons about what to do, optionally calls tools, then loops until it has an answer.

What I Learned Building Multi-Agent Systems

1. Information Asymmetry is Powerful

In my investment agent system, I gave the Bull and Bear agents different initial information. This forced them to actually discover counterarguments rather than generating token-level balance.

2. Agents Will Game Your System

Without explicit constraints, agents find shortcuts:

  • Making unfalsifiable claims (β€œThe market could go up or down”)
  • Appealing to authority without specifics (β€œExperts say…”)
  • Hedging everything into meaninglessness

Solution: Add an Evidence Grader that scores claims independently.

3. Temperature Matters Per Agent

Different roles benefit from different creativity levels:

Agent TypeTemperatureWhy
Analyst (Bull/Bear)0.7Confident, diverse arguments
Synthesizer0.3Careful, balanced
Grader0.1Consistent, reliable

4. Limit Your Rounds

I tested 1, 2, 3, and 5 debate rounds:

  • 1 round: No real synthesis
  • 2 rounds: Sweet spotβ€”each side responds once
  • 3+ rounds: Agents start agreeing too much, lose diversity

Common Mistakes to Avoid

  1. Too much state: Start with minimal state, add only what you need
  2. Unclear termination: Always define explicit end conditions
  3. No observability: Log every node transitionβ€”debugging graph flows is hard otherwise
  4. Ignoring token budgets: Multi-agent = multiple LLM calls = costs add up fast

When NOT to Use LangGraph

  • Simple, linear workflows (just use LangChain chains)
  • When you need <1s latency (graph overhead adds ~100-200ms)
  • Exploratory prototyping (start simpler, add LangGraph later)

Resources

If you’re getting started:

The agent paradigm is young but promising. I’m excited to see what we build.


Have questions or want to discuss agent architectures? Reach out on LinkedIn.

Related Posts