Agents can invoke external tools like weather APIs, calculators, web search, database queries, and more. The results are in raw JSON. This pattern shows you how to render structured, type-safe UI cards for every tool call your agent makes, complete with loading states and error handling.Documentation Index
Fetch the complete documentation index at: https://langchain-5e9cc07a-preview-cbuipl-1779916257-33d1bcf.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
How tool calling works
When a LangGraph agent decides it needs external data, it emits one or more tool calls as part of an AI message. Each tool call includes:- name: the tool being invoked (e.g.
"get_weather","calculator") - args: the structured arguments passed to the tool
- id: a unique identifier linking the call to its result
ToolMessage. The useStream hook unifies all of this into a single
toolCalls array you can render directly.
Setting up useStream
The first step is wiring up useStream to your agent backend. The hook returns
reactive state including a toolCalls array that updates in real time as the
agent streams.
The code examples use
useStream<typeof myAgent> for type-safe stream state. See Type inference for Python or JavaScript backends.The AssembledToolCall type
Each entry in thetoolCalls array is an AssembledToolCall object:
| Property | Description |
|---|---|
name | The name of the tool (e.g. "get_weather") |
callId | Unique ID matching the AI message’s tool_calls entry |
id | Alias for callId, matching message-level tool calls |
namespace | Namespace where the tool call was emitted |
input | Structured arguments the agent passed to the tool |
args | Alias for input, matching message-level tool calls |
output | Tool output after a successful call, or null while running or after an error |
status | Lifecycle state: "running", "finished", or "error" |
error | Error details when the tool call fails |
Filtering tool calls per message
An AI message may trigger multiple tool calls, and your chat may contain many AI messages. To render the right tool cards under each message, filter by matchingcallId against the message’s tool_calls array:
Building specialized tool cards
Rather than dumping raw JSON, build dedicated UI components for each tool. Usename to select the right card:
Weather card example
Loading and error states
Always handle the pending and error states to give users clear feedback:Type-safe tool arguments
If your tools are defined with structured schemas, you can use theToolCallFromTool utility type to get fully typed args:
Rendering tool calls inline with streaming text
Tool calls often arrive interleaved with streamed text. TheuseStream hook
keeps toolCalls in sync with the stream, so pending cards appear as soon as
the agent emits the call, before the tool has finished executing.
This means users see:
- The AI’s text as it streams in
- A loading card the moment a tool call is emitted
- The card updates to show the result once the tool completes
Tool calls update in place. The same
callId transitions from "running" to
"finished" (or "error"), so your UI re-renders the same component
with new state.Handling multiple concurrent tool calls
Agents can invoke several tools in parallel. ThetoolCalls array will contain
multiple entries with status: "running" simultaneously. Each resolves
independently, so your UI should handle partial completion gracefully:
Best practices
Follow these guidelines when building tool call UIs:- Always handle all three states:
running,finished, anderror. Users should never see a blank card. - Validate results safely. Tool outputs are typed as
unknownuntil you narrow them for a specific card. - Provide a generic fallback. Not every tool needs a bespoke card. Render a collapsible JSON view for unknown tool names.
- Show the tool name and args during loading. Users want to know what the agent is doing, even before the result arrives.
- Keep cards compact. Tool cards sit inline with chat messages. Avoid overwhelming the conversation with oversized widgets.
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

