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

# Function calling

> Let a model request an application function and return its result to the conversation.

A function tool describes work your application can perform. The model chooses a function and supplies arguments; your application validates them, runs the function, and returns the result.

Unlike a hosted tool or an MCP connection, declaring a function does not execute application code on the platform.

## Describe the function

Include a tool definition in a Responses request. Use a focused name and a JSON Schema for its arguments:

```json Tool definition theme={null}
{
  "type": "function",
  "name": "lookup_order",
  "description": "Look up the current status of an order.",
  "strict": true,
  "parameters": {
    "type": "object",
    "properties": {
      "order_id": { "type": "string" }
    },
    "required": ["order_id"],
    "additionalProperties": false
  }
}
```

This is the `tools` entry, not a complete request. Keep the model, input, and any conversation settings in the enclosing [Responses request](/docs/generate-a-response).

## Handle a function call

Inspect the response output for `function_call` items. Each item identifies the function, JSON-encoded arguments, and a `call_id`.

Before executing a call:

1. Check the function name against the functions your application supports.
2. Parse and validate the arguments.
3. Check the authenticated user’s permission to perform the operation.
4. Execute the operation and collect its result.

Model-generated arguments are input to your application, not authorization to bypass its access checks.

## Return the result

Send a `function_call_output` item using the matching call ID, and continue from the preceding response:

```json Continuation payload theme={null}
{
  "model": "auto",
  "previous_response_id": "<response-id>",
  "input": [
    {
      "type": "function_call_output",
      "call_id": "<call-id>",
      "output": "{\"status\":\"shipped\"}"
    }
  ]
}
```

The model can answer or request more tools. Handle each requested call and continue until you receive the final answer. Bound the number of iterations and handle errors explicitly.

## Complete workflows

* [Subagents](/docs/spawn-subagents-using-the-responses-api) implements the full loop, including multiple function calls and results.
* [Deep research](/docs/making-deep-research-with-subagents) applies that pattern to research tasks.
* [MCP tools](/docs/mcp-tools) lets MKA1 call an external tool server directly.
