The Tool Call pattern (also known as Function Calling) enables Large Language Models to interact with external systems, APIs, and data sources by invoking predefined tools during a conversation.

This pattern allows LLMs to:
get_weather(location, units)search_database(query, filters)send_email(to, subject, body)calculate(expression)fetch_url(url)| Step | From | To | Description |
|---|---|---|---|
| 1 | User | Application | User sends a message |
| 2 | Application | LLM API | Request includes message + tool definitions |
| 3 | LLM API | Application | LLM returns tool_calls if needed |
| 4 | Application | Tool Router | Route each tool call |
| 5 | Tool Router | Tools | Execute with provided arguments |
| 6 | Tools | External | Query APIs or data sources |
| 7 | External | Tools | Return results |
| 8 | Tools | Application | Return formatted results |
| 9 | Application | LLM API | Continue conversation with results |
| 10 | LLM API | Application | Generate final response |
| 11 | Application | User | Display response |
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City name or coordinates"
},
"units": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"default": "celsius"
}
},
"required": ["location"]
}
}
}
{
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"location\": \"San Francisco\", \"units\": \"celsius\"}"
}
}
]
}
| Pattern | Relationship |
|---|---|
| Agentic RAG | Uses tool calls for retrieval |
| ReAct (Reasoning + Acting) | Combines reasoning with tool use |
| Chain of Thought | Reasoning before tool selection |
@startuml
title LLM Tool Call Pattern
skinparam participant {
BackgroundColor #E3F2FD
BorderColor #1565C0
}
actor User
participant "Application" as App
participant "LLM API" as LLM
participant "Tool Router" as Router
collections "Tools" as Tools
database "External APIs\n& Data Sources" as External
== User Request ==
User -> App : Send message
activate App
App -> LLM : API Request with\n- User message\n- Tool definitions\n- System prompt
activate LLM
LLM --> App : Response with\ntool_calls array
deactivate LLM
== Tool Execution ==
App -> Router : Route tool call
activate Router
Router -> Tools : Execute tool\nwith arguments
activate Tools
Tools -> External : Query/Action
activate External
External --> Tools : Result
deactivate External
Tools --> Router : Tool result
deactivate Tools
Router --> App : Formatted result
deactivate Router
== Response Generation ==
App -> LLM : Continue with\ntool results
activate LLM
LLM --> App : Final response
deactivate LLM
App --> User : Display response
deactivate App
@enduml