LLM Agent Tool-Call Sequence Diagram

An LLM agent tool-call sequence diagram shows, in time order, the messages between a user, the agent program, the LLM API, a tool and a memory store. This sample traces one question, "Do I need an umbrella in Paris tomorrow?", through the standard tool-use loop: the model asks for a tool, the agent runs it, the result goes back, and the loop ends when the model answers. It uses UML 2.5 sequence diagram notation.


1. The Diagram

LLM Agent with Tool Calling: "Do I need an umbrella in Paris tomorrow?" :User :Agent :LLM API :WeatherTool :Memory 1: ask(question) 2: load(history, prefs) 3: last 10 turns, city=Paris loop [stop_reason = tool_use, max 5 turns] 4: messages + tool schemas 5: tool_use get_forecast(Paris, D+1) 6: get_forecast(Paris, D+1) 7: {rain: 70%, 14 C} 8: messages + tool_result 9: end_turn "Yes, 70% rain..." loop exits when the LLM answers instead of calling a tool 10: save(turn) 11: "Yes, take one"

The key point the diagram makes is who executes what: the LLM only proposes tool calls; the agent executes them and stays in control.

  1. The user sends a question to the agent, the program that owns the loop. Its activation bar spans the whole request.
  2. The agent loads recent conversation turns and preferences from memory.
  3. Memory replies (dashed arrow) with context, including that the user's city is Paris.
  4. Inside the loop fragment, the agent calls the LLM API with the messages and the JSON schemas of the tools it may use.
  5. The LLM does not run anything itself. It returns stop_reason: tool_use with the tool name and arguments.
  6. The agent validates the arguments and calls get_forecast.
  7. The tool returns structured data.
  8. The agent appends a tool_result message and calls the LLM again.
  9. This time the LLM ends its turn with text, so the loop guard is false and the loop exits. The cap of five turns stops runaway loops.
  10. The agent saves the turn to memory.
  11. The answer is returned to the user.

2. How to Read It

Notation Used :Role activation call (sync) reply loop [guard] repeat while guard holds alt [cond] [else] alternative branch Time runs top to bottom; numbers give message order.

Each participant is a lifeline: a head box with a dashed line down. A thin bar shows when it is active. Solid arrows with filled heads are synchronous calls; dashed arrows with open heads are replies. Rectangles with a tab are combined fragments: loop repeats, alt chooses one branch by guard.

3. Variant: Tool Timeout

Variant: The Tool Times Out :User :Agent :LLM API :WeatherTool :Memory 6: get_forecast(Paris, D+1) no reply in 10 s alt [retry succeeds] 6a: retry after 2 s backoff 7: {rain: 70%} [still failing] 8: tool_result is_error: timeout 9: "Forecast unavailable, check later" 11: graceful answer

Error paths are where agents fail in production, so draw them. Here the tool does not reply in ten seconds. An alt fragment shows the two outcomes: one retry with backoff succeeds, or the agent sends an error tool_result so the model can explain the problem instead of inventing a forecast.

4. Pros, Cons, and When to Use

Pros

Cons

When to use

When not to use

5. As Diagrams-as-Code

The main diagram as a Mermaid sequence diagram:

sequenceDiagram
  actor U as User
  participant A as Agent
  participant L as LLM API
  participant T as WeatherTool
  participant M as Memory
  U->>A: ask(question)
  A->>M: load(history, prefs)
  M-->>A: last 10 turns, city=Paris
  loop stop_reason = tool_use, max 5 turns
    A->>L: messages + tool schemas
    L-->>A: tool_use get_forecast(Paris, D+1)
    A->>T: get_forecast(Paris, D+1)
    T-->>A: {rain: 70%, 14 C}
    A->>L: messages + tool_result
    L-->>A: end_turn "Yes, 70% rain..."
  end
  A->>M: save(turn)
  A-->>U: "Yes, take one: 70% rain"