Module 16 Lesson 3: Streaming Intermediate Steps
·Agentic AI

Module 16 Lesson 3: Streaming Intermediate Steps

Watch the agent work. How to capture and stream the 'Thought' and 'Action' phases to the UI in real-time.

Streaming the Chain: Visibility is Trust

When an agent is working in a LangGraph or a Crew, it might perform 10 "Hidden" actions before it answers you. In this lesson, we learn the technical implementation of intermediate streaming.

1. The Async Message Protocol

In a standard API, you get one response. In a streaming API, you get a Stream of Events.

  • event: 'thought', payload: 'Searching for X...'
  • event: 'action', payload: 'Call Tool(Y)'
  • event: 'result', payload: 'Success: 200'
  • event: 'final', payload: 'Here is your answer.'

2. Using LangGraph stream()

LangGraph has a built-in .stream() method that yields these events automatically.

# Server-side
for event in app.stream(inputs):
    # This loop runs every time a NODE finishes
    for key, value in event.items():
        print(f"Node '{key}' is done.")
        # Send this event to the front-end via WebSockets or SSE

3. Visualizing the Real-time Timeline

sequenceDiagram
    participant U as User (UI)
    participant B as Backend (Queue)
    participant A as Agent (LangGraph)
    
    U->>B: Query: 'How is Tesla doing?'
    B->>A: Start Graph
    A->>B: EVENT: Node 'Researcher' start
    B->>U: UI shows: 'Researcher is waking up...'
    A->>B: EVENT: Tool 'Search' called with 'TSLA'
    B->>U: UI shows: 'Searching Google Finance...'
    A->>B: EVENT: Final Answer
    B->>U: UI shows: 'Tesla is...'

4. The "Collapsible Log" Pattern

Don't clutter the main chat area with these technical logs. Use a Status Bar or a Dropdown.

  • User sees: "Working... (View Details)"
  • If they click "View Details," they see the raw traces. This satisfies both the power user and the casual user.

5. Handling Latency

By showing the intermediate steps, you buy yourself "Grace Time."

  • If the agent takes 10 seconds to search and 10 seconds to write:
  • Without Logs: 20 seconds of silence (Bad).
  • With Logs: 2 actions every 10 seconds (Good).

Key Takeaways

  • Event-based streaming is mandatory for multi-node agents.
  • Transparency allows users to see where an agent gets stuck.
  • LangGraph .stream() is the engine for node-by-node updates.
  • Collapsible UIs keep the interface clean while preserving detail.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn