Skip to main content

Tool Calling with Mielto

Enable your AI agents to interact with Mielto’s API endpoints directly through tool calling (function calling). This allows LLMs to search collections, manage memories, and access knowledge bases autonomously.

Architecture Overview

When using tool calling with Mielto:
  • OpenAI Client: Handles LLM chat completions and tool call requests
  • Mielto Client: Executes the actual API calls to Mielto endpoints (collections, memories, etc.) when tools are invoked
The LLM receives tool definitions and decides when to call them. When a tool is requested, your application executes the corresponding Mielto API call and returns the result to the LLM.

What is Tool Calling?

Tool calling allows LLMs to request execution of specific functions during a conversation. When you define Mielto endpoints as tools, the LLM can:
  • Search your knowledge collections
  • Retrieve user memories
  • Create new memories
  • List available collections
  • And more - all without manual intervention

Step 1: Define Mielto Endpoints as Tools

Define your tools using OpenAI’s function calling format. Here are common Mielto endpoints as tools:

Step 2: Implement Tool Execution Functions

Create functions that execute the actual API calls when tools are invoked:

Step 3: Use Tools in Chat Completions

Now integrate tool calling into your chat completions. The OpenAI client handles LLM interactions, while tool execution functions call Mielto’s API endpoints:
Here’s a complete example that combines everything:

Best Practices

Tool Selection: Only include tools that are relevant to your use case. Too many tools can confuse the model.
Error Handling: Always implement proper error handling for tool execution. If a tool fails, include the error message in the tool response so the LLM can handle it appropriately.
API Keys: Never expose your Mielto API key in client-side code. Always execute tool calls server-side.

Next Steps