Function calling lets the model use your code. You describe functions (tools), the model decides when to call them and with what arguments, and you run them locally. Then you send the result back, and the model weaves it into a natural-language answer. This is how you connect Mavera to databases, APIs, file systems — anything your code can reach.Documentation Index
Fetch the complete documentation index at: https://docs.mavera.io/llms.txt
Use this file to discover all available pages before exploring further.
Mavera uses the OpenAI-compatible tools interface. If you’ve used function calling with OpenAI, you already know the pattern. Same SDKs, same flow.
How It Works
Every function-calling interaction follows a five-step cycle. The model never executes code itself — it tells you what to call and with what arguments, and you do the rest. The cycle can repeat — the model may call additional functions based on earlier results.Quick Example
Let’s build a completeget_weather flow. You define the function, the model calls it, and you return the result.
Check for function calls and execute locally
The model doesn’t return text — it returns items with
type: "function_call" in the output. Parse the arguments and run your function.Defining Functions
Each tool definition lives inside atools array entry. The function fields are defined at the top level of the tool object using JSON Schema for parameters.
Function Definition Fields
| Field | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Always "function" |
name | string | Yes | The function name the model will reference. Use snake_case. |
description | string | Yes | Plain-English explanation of what the function does. The model reads this to decide when to call it. |
parameters | object | Yes | A JSON Schema object describing the function’s arguments. |
strict | boolean | No | When true, the model’s arguments are guaranteed to match your schema exactly. See Strict Mode. |
Writing Good Descriptions
Thedescription field is the most important part. The model reads it to decide when to call the function. Be specific. Say what the function returns.
Complex Schema Example
Here’s asearch_products function with filters, enums, and nested objects:
Handling Tool Calls
The model can return zero, one, or multiple function calls in a single response. Your code needs to handle all three cases. When the model calls functions, theoutput array contains items with type: "function_call". Each has a name, arguments (a JSON string), and a call_id (reference it when returning results).
Dispatch Pattern for Multiple Tools
When you offer several functions, you need a dispatcher. Map function names to callables, loop through every function call, and send all results back in one request.When the model calls multiple functions, send all results back in a single request. Each
function_call_output must reference the correct call_id.When No Tool is Called
Sometimes the model answers directly —status is "completed" and the output contains text content. Always check before dispatching:
Strict Mode
Setstrict: true to guarantee the model’s arguments match your JSON Schema exactly. No extra fields, no missing fields, correct types every time.
Requirements
Strict mode has two hard requirements:- All properties must be in
required. If a field is optional, use a union type:{"type": ["string", "null"]}. additionalPropertiesmust befalseat every level — root and nested objects.
Tool Choice
Thetool_choice parameter controls whether and how the model uses your functions.
Options
| Value | Behavior |
|---|---|
"auto" | Default. The model decides whether to call a function or respond with text. |
"required" | The model must call at least one function. It won’t respond with text only. |
"none" | The model cannot call any function, even if tools are defined. Useful for follow-up turns where you want a text-only answer. |
{"type": "function", "name": "..."} | Force a specific function. The model must call exactly this function. |
Code Examples
Using with Personas
Function calling and personas are a powerful combination. The persona shapes how the model uses your functions and how it frames the results. The same function call, filtered through different personas, produces different responses.Example: Customer Support Bot
Imagine a support bot for an e-commerce store. You define two functions —lookup_order and process_refund — and attach a frustrated-customer persona. The persona influences which functions the model calls, when it calls them, and how it communicates the results.
frustrated_customer_support persona, the model will proactively look up the order, acknowledge the delay with empathy, and likely offer a resolution — possibly calling process_refund before the customer even asks. A different persona (say, a corporate-formal one) would use the same functions but frame the response differently.
Best Practices
Write clear, specific descriptions
Write clear, specific descriptions
The model decides which function to call based on the
description field. Vague descriptions lead to wrong calls. Include what the function does, what it returns, and any constraints.Keep your function count under 20
Keep your function count under 20
Every function definition consumes tokens in the prompt. More functions means higher latency and cost — and the model has more room to pick the wrong one. If you have many functions, group them by use case and only send the relevant subset per request.
Always use strict mode in production
Always use strict mode in production
Without
strict: true, the model might omit optional fields, add unexpected fields, or use wrong types. Strict mode guarantees the output matches your schema. The tradeoff — listing every field as required — is minimal.Don't make the model fill arguments you already know
Don't make the model fill arguments you already know
If your code already knows the
user_id or session_id, don’t include those as function parameters for the model to fill. Pass them directly in your dispatch logic. This reduces errors and keeps schemas simpler.Combine sequential functions when possible
Combine sequential functions when possible
If two functions are always called together (e.g.,
get_customer then get_orders), consider merging them into a single get_customer_with_orders function. Fewer round-trips means lower latency and cost.Return concise function results
Return concise function results
The function result goes back into the prompt as tokens. Return only the fields the model needs to formulate a response. Don’t dump an entire database row if the model only needs three fields.
Handle errors in function results gracefully
Handle errors in function results gracefully
If your function fails, return a structured error message — not a stack trace. The model can use a clean error to generate a helpful response to the user.
See Also
Responses API
Full reference for the responses API — streaming, analysis mode, structured outputs, and more
Personas
50+ pre-built personas to combine with function calling for audience-aware tool use
Authentication
Set up your API key and configure the SDK
API Reference
Complete Responses API endpoint specification