Skip to content

Tools & Agents

Meloqui supports Tool Calling (also known as Function Calling), allowing LLMs to interact with external data and systems. This transforms the LLM from a text generator into an intelligent agent.

The Agent Loop

When you register tools, Meloqui automatically handles the "Agent Loop"—the back-and-forth process of executing tools requested by the model.

Agent Loop

Registering Tools

typescript
import { ToolRegistry } from 'meloqui';

const registry = new ToolRegistry();

registry.registerTool(
  'get_weather',
  async ({ location }) => {
    return { temp: 72, condition: 'Sunny' };
  },
  { description: 'Get the weather for a location' }
);

const client = new ChatClient({
  provider: 'openai',
  model: 'gpt-4o',
  tools: registry
});

Automatic Execution

When you send a message that requires a tool, ChatClient automatically:

  1. Detects the tool call request from the LLM.
  2. Executes the matching function in your registry.
  3. Sends the result back to the LLM.
  4. Returns the final natural language response to you.
typescript
// The model will call get_weather("London") behind the scenes
const response = await client.chat('What is the weather in London?');
console.log(response.content); 
// "It is currently 72°F and Sunny in London."

Released under the MIT License.