#Function Calling
Function Calling allows adding dynamic functionality to your extensions by letting the LLM use structured data that you then can use to trigger a specific functionality of the extension.
Attention
This feature is currently under development. Implementation details may change.
#Example use cases
- Query external APIs for additional information (news, weather, web search, etc.).
- Perform calculations or conversions based on user input.
- Store and recall important memories or facts, including RAG and database queries.
- Introduce true randomness into the conversation (dice rolls, coin flips, etc.).
#Officially supported extensions using function calling
- Image Generation (built-in) - generate images based on user prompts.
- Web Search - trigger a web search for a query.
- RSS - fetch the latest news from RSS feeds.
- AccuWeather - fetch the weather information from AccuWeather.
- D&D Dice - roll dice for D&D games.
#Prerequisites and limitations
- This feature is only available for certain Chat Completion sources: OpenAI, Claude, MistralAI, Groq, Cohere, OpenRouter, AI21, Google AI Studio, DeepSeek and Custom API sources.
- Text Completion APIs don't support function calls, but some locally-hosted backends like Ollama and TabbyAPI may run in Custom OpenAI-compatible mode under Chat Completion.
- The support for function calling must be explicitly allowed by the user first. This is done by enabling the "Enable function calling" option in the AI Response Configuration panel.
- There is no guarantee that an LLM will perform any function calls at all. Most of them require an explicit "activation" through the prompt (e.g., the user asking to "Roll a dice", "Get the weather", etc.).
- Not all prompts can trigger a tool call. Continuations, impersonation, background ('quiet') prompts are not allowed to trigger a tool call. They can still use past successful tool calls in their responses.
#How to make a function tool
#Check if the feature is supported
To determine if the function tool calling feature is supported, you can call isToolCallingSupported
from the SillyTavern.getContext()
object. This will check if the current API supports function tool calling and if it's enabled in the settings. Here is an example of how to check if the feature is supported:
#Register a function
To register a function tool, you need to call the registerFunctionTool
function from the SillyTavern.getContext()
object and pass the required parameters. Here is an example of how to register a function tool:
#Unregister a function
To deactivate a function tool, you need to call the unregisterFunctionTool
function from the SillyTavern.getContext()
object and pass the name of the function tool to disable. Here is an example of how to unregister a function tool:
#Tips and tricks
- Successful tool calls are saved as a part of the visible history and will be displayed in the chat UI, so you can inspect the actual parameters and results. If that is not desirable, set the
stealth: true
flag when registering a function tool. - If you don't want to see the tool call in the chat history. If you want to stylize or hide them with custom CSS, target a
toolCall
class on.mes
elements, i.e..mes.toolCall { display: none; }
or.mes.toolCall { color: #999; }
.