Questions
11 of 24
1What is a Tool in LangChain and how does it differ from a plain function or API call?
2What is the difference between the tool() helper, DynamicTool, and StructuredTool class?
3How does an LLM decide which tool to call — what role does the tool description play?
4What is the role of Zod schema in tool definitions and how does it map to OpenAI's function calling spec?
5What is a ToolNode in LangGraph and how does it differ from calling a tool manually inside a graph node?
6How do you wrap a REST API call with auth headers inside a Tool in TypeScript?
7How do you handle async errors and retries inside a Tool without crashing the agent loop?
8How do you pass runtime context (userId, authToken, DB connection) into a Tool using RunnableConfig?
9How do you build a Toolkit (grouped set of related tools) using BaseToolkit?
10How do you validate and sanitize tool output before it is passed back to the LLM?
11How do you stream tool call results back to the client in real time?
12How do you implement tool-level authorization — allowing certain tools only for certain users?
13How do you build stateful tools that read/write to a database across multiple agent turns?
14How do you prevent tool abuse or infinite loops where an agent keeps calling the same tool repeatedly?
15How do you implement parallel tool calling — when the LLM decides to call multiple tools simultaneously?
16How do you create a human-in-the-loop tool that pauses the agent and waits for user approval before executing?
17How do you unit test and mock tools in isolation without invoking the LLM?
18How do you implement tool call caching to avoid redundant API calls for identical inputs?
19How do you design a multi-agent system where one agent's tool is actually another agent (agent-as-tool pattern)?
20How does LangGraph's ToolNode handle tool call errors and surface them back into the message state?
21What is the difference between tool_choice: "auto", "required", and "none" when binding tools to an LLM?
22How do you implement dynamic tool loading — where the set of available tools changes based on user role or session state?
23How do you trace and observe tool call latency in production using LangSmith?
24What are the token cost implications of registering too many tools and how do you mitigate it?
11 / 24

How do you stream tool call results back to the client in real time?

Stream tool call results in real time by combining LangChain/LangGraph's astream_events API to capture tool lifecycle events and Server-Sent Events (SSE) or WebSockets to push structured updates to the client, using the useStream hook on the frontend to receive and render typed tool calls and their results.

Streaming tool call results to the client in real time involves two key parts: capturing granular events on the backend as the agent executes tools, and pushing those events to the frontend over a persistent connection. On the backend, LangGraph's astream_events API provides a detailed stream of events, including on_tool_start and on_tool_end, which you can forward to the client via Server-Sent Events (SSE) or WebSockets. On the frontend, the useStream hook from @langchain/react automatically consumes this stream and provides a reactive toolCalls array that updates in real time as tools are invoked and completed. This approach gives you a smooth, token-by-token feel for tool execution without the complexity of managing raw WebSocket connections manually .

The core of a real-time tool-call streaming implementation is LangGraph's astream_events API. This method streams every granular event that occurs during agent execution, including when a tool call starts (on_tool_start), when it ends (on_tool_end), and even individual text tokens from the LLM (on_chat_model_stream). To capture tool calls, your agent must be created with a model that supports tool calling and is configured with streaming=True (for providers like Anthropic or OpenAI) to ensure that events are emitted in a timely fashion .

Backend: Tool Event Streaming with SSE (FastAPI)

On the frontend, the useStream hook from @langchain/react integrates seamlessly with the streaming backend. It consumes the SSE stream and automatically populates a reactive toolCalls array. Each entry in this array has a state (pending, completed, or error) and contains both the tool call request (with its name and args) and its result. This allows you to build a UI that updates in real time, showing a loading indicator the moment a tool call is emitted and then displaying the result as soon as it arrives .

Frontend: React Component with useStream

The useStream hook returns a toolCalls array of objects with a specific structure that gives you full control over the rendering of each tool's lifecycle. For optimal user experience, every tool should handle the three lifecycle states .

ToolCallWithResult Properties
  1. 1

    call.id: A unique ID for the tool call, used to match calls to results and filter them per message.

  2. 2

    call.name: The name of the tool (e.g., get_weather, calculator).

  3. 3

    call.args: The typed arguments the agent passed to the tool, inferred from the tool's Zod schema for full type safety.

  4. 4

    result: The ToolMessage response, available once the tool finishes execution.

  5. 5

    state: The lifecycle state, which can be "pending" (tool is running), "completed" (success), or "error" (failure).

A key UX feature of a streaming agent is that tool calls and their results are interleaved with the LLM's text output. The useStream hook maintains the correct order, allowing you to render the conversational flow naturally .

Rendering Interleaved Stream
Best Practices and Key Constraints
  1. 1

    Use Server-Sent Events (SSE) over WebSockets for simpler implementations, as SSE works seamlessly with HTTP and avoids issues with session affinity in serverless or autoscaling environments .

  2. 2

    Always provide fallback UI for the three tool call states: pending, completed, and error .

  3. 3

    For type safety, define your tools with Zod schemas in TypeScript; the useStream hook will infer the argument types, ensuring your UI components receive correctly typed data .

  4. 4

    When using models like GPT-5, note that they may aggregate response chunks, which can prevent token-level streaming in astream_events. For token-by-token text streaming, models like Anthropic's Claude Sonnet are more reliable .

  5. 5

    For multi-agent systems (deep agents), LangGraph provides stream.subagents, allowing you to stream tool calls and results from subagents independently, providing a richer view of the entire decision-making process .