Building AI Agents with LangChain and LangGraph: Part 2 › Introduction to Agentic Workflows

Michael BrenndoerferAugust 2, 20252 min read
Building AI Agents with LangChain and LangGraph: Part 2 › Introduction to Agentic WorkflowsOne section · Sections in this article4 / 9 ↓
Reading tools Definitions & inline links

Toggle tooltip visibility. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Now we move beyond simple tool calling to create agentic workflows - systems that can orchestrate multiple steps, maintain state, and make decisions about what to do next.

The key difference is structure and orchestration:

  • Part 1: Direct tool calling (human → model → tool → response)
  • Part 2: Workflow orchestration (human → workflow → multiple steps → response)

Defining Workflow State

LangGraph's StateGraph is the foundation that makes this possible, allowing us to define how data flows between different processing steps.

Every agentic workflow needs a way to pass data between steps. LangGraph uses TypedDict schemas to define what information flows through your system.

Our simple schema captures:

  • request: A user request
  • reply: The final result from our tool

This state acts as the "memory" of our workflow, ensuring each step has access to the information it needs.

In[3]:
Code
class StateSchema(TypedDict):
    request: str
    reply: str
In[4]:
Code
def reply_tool_node(state: StateSchema) -> StateSchema:
    output = model_with_tools.invoke(state["request"])
    args = output.tool_calls[0]["args"]
    reply_msg = draft_customer_reply.invoke(args)
    return {"reply": reply_msg}

Creating Workflow Nodes

Nodes are the processing units of your workflow. Each node is a function that:

  1. Receives the current state
  2. Performs some computation or action
  3. Returns updates to merge back into the state

Our reply_tool_node demonstrates the pattern: it takes the user's request, uses our model to generate a tool call, executes the tool, and returns the result.

In[5]:
Code
# init workflow
workflow = StateGraph(StateSchema)

# nodes
workflow.add_node("reply_tool_node", reply_tool_node)

# edges
workflow.add_edge(START, "reply_tool_node")
workflow.add_edge("reply_tool_node", END)

# full workflow
app = workflow.compile()

Building the Workflow Graph

Now we assemble our workflow by defining the flow between nodes:

  1. Initialize the StateGraph with our schema
  2. Add nodes that process the data
  3. Add edges that define the execution flow
  4. Compile into an executable application

This creates a clear, visual representation of how our agent processes requests - from start to finish.

In[6]:
Code
app.invoke({"request": "This is about Franks order. Tell him it's 2 days late."})
Out[6]:
Console
{'request': "This is about Franks order. Tell him it's 2 days late.",
 'reply': 'I am drafting a reply to Frank in the category Order Status.\n Content: Your order is 2 days late.'}

Testing Our First Agentic Workflow

Let's see our workflow in action. Notice how the request flows through our defined structure, and the state accumulates information as it progresses through each step.

Visualizing the Workflow

LangGraph automatically generates visual representations of your workflows. This helps you understand and debug complex agent behaviors by seeing exactly how data flows through your system.

In[7]:
Code
Image(app.get_graph().draw_mermaid_png())
Out[7]:
Visualization
Notebook output