Skip to main content

Tools System

Unlike Plugins (which are server-side code interceptors that modify the request before reaching the AI), Tools are capabilities or functions explicitly handed to the LLM. The model reasons autonomously and decides when and which tools to execute to answer the user's query.

Tools are located in the tools/ folder of your installation (not in plugins/).

Configuration

To enable Tool Calling mode, add the following section to your config/config.json:

{
"tool_calling": {
"enabled": true,
"expert_label": "document-expert",
"max_iterations": 5
}
}

Parameters:

  • enabled: Enables (true) or disables (false) tool execution mode.
  • expert_label: The expert identifier in experts.json that will process the initial query and decide tool calls. It must be a tool calling compatible model.
  • max_iterations: Maximum number of tool call/execution cycles to avoid infinite loops (default is 5).

Compatible Models

To use Tool Calling, the expert configured in expert_label must support tool definitions:

BackendRecommended Models
Ollama (Local)llama3.1:8b, qwen2.5:7b, qwen2.5:14b
API Cloud (litellm)gpt-4o, gpt-4o-mini, claude-3.5-sonnet, gemini-1.5-pro

Tools Contract

Any script in the tools/ folder can register tools for the LLM by implementing two functions:

1. get_tools() -> list

Returns the list of tool specifications in OpenAI/JSON Schema format.

def get_tools() -> list:
return [
{
"type": "function",
"function": {
"name": "tool_name",
"description": "Explanation of when to use this tool",
"parameters": {
"type": "object",
"properties": {
"parameter": {
"type": "string",
"description": "Parameter description"
}
},
"required": ["parameter"]
}
}
}
]

2. execute_tool(tool_name: str, arguments: dict) -> str | None

Executes the specified tool logic and returns its result as a text string.

def execute_tool(tool_name: str, arguments: dict) -> str | None:
if tool_name == "tool_name":
param = arguments.get("parameter")
# Tool logic
return f"Result with parameter: {param}"
return None

If the script does not recognize the tool_name, it must return None to allow other scripts to process it.


Output Cleanup and Post-processing

l3mcore implements automatic cleanup mechanisms to ensure the responses delivered to the user are conversational and direct:

  • Classic Routing Deactivation: When Tool Calling mode is enabled, classic interceptors (override_route) are automatically disabled to prevent duplicate tool executions and prevent the user's prompt from being polluted with technical queries or debugging blocks.
  • JSON Blocks Filter: The server post-processes the assistant's final response by removing any JSON string or block of tool calls generated by the language model (e.g., {"name": "...", "parameters": {...}}).
  • Technical Queries Hiding: Built-in tools like ask_database do not include technical statements (like SQL queries) in their responses unless expressly requested, ensuring the LLM only returns the interpreted response in natural language.