Documentation Index
Fetch the complete documentation index at: https://mintlify.com/software-mansion/react-native-executorch/llms.txt
Use this file to discover all available pages before exploring further.
Tool Calling
Tool calling enables your LLM to interact with external functions, APIs, and data sources. The model can decide when to call a tool, extract the necessary parameters, and incorporate the results into its response.How It Works
- You provide tool definitions describing available functions
- User sends a message that might require a tool
- Model decides whether to call a tool and generates a structured tool call
- Your
executeToolCallbackruns the tool and returns the result - Model incorporates the result into its final answer
Basic Setup
Tool Definitions
Tool definitions follow a JSON schema-like structure. The exact format depends on your model’s chat template, but most models support this structure:Parameter Types
string: Text valuesnumber: Numeric valuesboolean: True/false valuesarray: Lists of valuesobject: Nested objects
Enums
Restrict parameters to specific values:Execute Tool Callback
TheexecuteToolCallback function receives a ToolCall object and must return a string result:
Example with Multiple Tools
Complete Example: Calculator Assistant
Using Tools with generate()
You can also pass tools directly to thegenerate method:
generate(), you still need to configure executeToolCallback via configure().
Display Tool Calls
By default, JSON tool call representations are hidden from the message history. SetdisplayToolCalls: true to include them:
displayToolCalls: true, the message history will include entries like:
Best Practices
- Clear descriptions - Write detailed tool and parameter descriptions to help the model understand when and how to use each tool
- Error handling - Always wrap tool execution in try-catch blocks
- Validate inputs - Check that tool arguments are valid before executing
- Return strings - Always return string results, even for numeric or boolean results
- Security - Never execute arbitrary code (avoid
eval). Use safe libraries for operations like math evaluation - Async operations - Tool callbacks can be async, perfect for API calls
- Null for unknown - Return
nullif the tool name is unrecognized