### 1. Structural Definition of Function Calling
To invoke a function, the LLM needs the schema passed in the `tools` parameter. The structure is rigid.
* **Type**: Always `"function"`. * **Name**: The function identifier. * **Description**: Text that helps the model choose when to use it. * **Parameters**: A JSON schema for inputs. It requires: * `type`: Usually `"object"`. * `properties`: Input fields and types (string, integer, etc.). * `required`: Mandatory fields. * `additionalProperties`: Often `false` to enforce strictness. * **Strict Mode**: An optional boolean. Set to `true` to prevent invalid arguments.
**Example Schema:** ```json { "type": "function", "name": "get_weather", "description": "Retrieves current weather for the given location.", "parameters": { "type": "object", "properties": { "location": { "type": "string" }, "units": { "type": "string", "enum": ["celsius", "fahrenheit"] } }, "required": ["location", "units"], "additionalProperties": false }, "strict": true } ```
### 2. How the LLM Decides to Invoke a Function
The choice to call a function or generate text internally hinges on necessity, utility, and affordability.
* **Internal vs. External Assessment**: The model checks if the task is solvable internally or needs external tools. * **Meta-Cognition**: New methods use lightweight linear probes on hidden states to catch meta-cognitive signals. These trigger tool use only when needed, moving beyond prompt engineering. * **Intervenable Representation**: Tool selection is linearly readable in the model's internal representation. This allows steering or correction during decoding.
### 3. Runtime Execution for AI Agents (The Agent Loop)
For agents, function calling drives an iterative loop.
1. **Input**: The LLM gets the user prompt and tool schemas. 2. **Decision**: The LLM picks a tool or a final answer. 3. **Execution**: If a tool is chosen, your infrastructure intercepts the call, runs the function, and captures the result. 4. **Feedback**: The result becomes a message in the conversation history. 5. **Iteration**: The loop repeats until a final response emerges.
### 4. The ReAct Pattern (Reasoning + Acting)
Modern agent frameworks often use **ReAct** to interleave reasoning with actions. This reduces hallucinations and aids error recovery.
* **Structure**: * **Thought**: The model reasons about the next step. * **Action**: The model invokes a tool (e.g., `Action: get_weather(location="NYC", units="celsius")`). * **Observation**: The model receives the output. * **Loop**: The model cycles through Thought, Action, and Observation until it has enough info for a final answer.
### Application to Liminality
Since **Liminality** is a question-decomposition and routing MCP server, these patterns matter for:
1. **Routing**: Defining sub-questions as functions via the `tools` parameter. This lets the LLM break complex queries into actionable sub-tasks. 2. **Grounding**: Using ReAct to ensure each sub-question relies on real tools (like Acme CRM or HubSpot) before returning reusable routes. 3. **Efficiency**: Applying the necessity/utility/affordability logic to skip unnecessary calls. This optimizes traffic for your flagship LLM users.
This answer was worked out by Liminality — Physea's engine that decomposes a request, grounds each part to a real tool, and returns a reusable, checkable route.
Connect it over MCP: https://mcp.physea.ai/mcp · physea.ai