> ## Documentation Index
> Fetch the complete documentation index at: https://www.getmaxim.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Tool Calls

> Track external system calls triggered by LLM responses in your agentic endpoints. Tool calls represent interactions with external services, allowing you to monitor execution time and responses.

## Creating and Logging Tool Calls

<CodeGroup>
  ```typescript JS/TS theme={null}
  const toolCall = completion.choices[0].message.tool_calls[0];
  const traceToolCall = trace.toolCall({
      id: toolCall.id,
      name: toolCall.function.name,
      description: "Get current temperature for a given location.",
      args: toolCall.function.arguments,
      tags: { location: toolCall.function.arguments["location"] }
  });

  try {
      const result = callExternalService(toolCall.function.name, toolCall.function.arguments);
      traceToolCall.result(result);
  } catch (error) {
      traceToolCall.error(error);
  }
  ```

  ```python Python theme={null}
  tool_call = completion.choices[0].message.tool_calls[0]
  trace_tool_call = trace.tool_call({
      "id":tool_call.id,
      "name":tool_call.function.name,
      "description":"Get current temperature for a given location.",
      "args":tool_call.function.arguments,
      "tags":{ "location": tool_call.function.arguments["location"] }
  })
  try:
      result = call_external_service(tool_call.function.name, tool_call.function.arguments)
      trace_tool_call.result(result)
  except Exception as e:
      error = ToolCallError(message=str(e), type=type(e).__name__)
      trace_tool_call.error(error)
  ```
</CodeGroup>

<Note>
  Replace 'trace.toolCall' with 'span.toolCall' when you are creating tool calls within an existing span
</Note>

<img src="https://mintcdn.com/maximai/fHnWe0mnvuD5228y/images/docs/tracing/via-sdk/tool_call.png?fit=max&auto=format&n=fHnWe0mnvuD5228y&q=85&s=5f02215489788b68abb316c5853c8378" alt="Tool Calls" width="2388" height="1698" data-path="images/docs/tracing/via-sdk/tool_call.png" />

<Note>[Schedule a demo](https://getmaxim.ai/demo) to see how Maxim AI helps teams ship reliable agents.</Note>
