Mango is an AI agent that turns natural language into MongoDB queries. Plug in any LLM, connect your database, and start asking questions in seconds.
$ pip install mango-ai[anthropic]
Then: mango demo
Ask questions in plain English. Mango translates them into accurate MQL queries using the LLM of your choice — Claude, GPT, Gemini, or any Ollama model.
"Find all users who signed up in the last 30 days and have made at least 3 orders"
db.users.find({
createdAt: {
$gte: new Date(Date.now() - 30*24*60*60*1000)
},
orderCount: { $gte: 3 }
})
Load verified examples with mango train. Every successful query is auto-saved. Similar questions get faster, more accurate answers over time.
Every query is validated before reaching the database. Collection names, field names, and operators are checked against the live schema first.
When a query fails with a fixable error, Mango injects the error back into context and retries automatically — up to 2 times before giving up.
Swap LLM providers, memory backends, and tools without changing your agent code. Everything is built on abstract interfaces — swap in minutes.
See every tool call in real time via Server-Sent Events. Know exactly what queries are being executed and why — no black boxes.
Only find, aggregate, count, and distinct. Write operations are rejected at the tool level — no accidental mutations, ever.
Mango automatically introspects your collections, inferring field types, indexes, and references from sampled documents — no configuration needed.
Gold-standard verified examples are injected first. The LLM uses them directly — no schema exploration needed.
Auto-saved past interactions are retrieved and injected as additional few-shot examples into the prompt.
Only the schema portions relevant to the current query are selected and injected — not the full database schema.
The LLM analyzes the question and selects which tools to invoke — thinking, not just parsing.
Before each run_mql call, the current schema is automatically re-injected so the LLM always has accurate field names and types at query time.
Every query is validated against the live schema — collection names, fields, and operators — before running.
Tools run queries against MongoDB and return structured results.
If a tool fails with a fixable error, the error is injected back and the LLM corrects the query automatically (max 2 retries).
The final response is streamed back to the caller via SSE — real-time, no waiting.
The successful interaction is automatically saved for future similar questions — the agent learns.
mango-ai[anthropic]
mango-ai[openai]
mango-ai[gemini]
mango-ai[ollama]
from mango import MangoAgent
from mango.tools import (
ToolRegistry,
ListCollectionsTool,
SearchCollectionsTool,
DescribeCollectionTool,
CollectionStatsTool,
RunMQLTool,
SaveTextMemoryTool,
)
from mango.servers.fastapi import MangoFastAPIServer
from mango.integrations.anthropic import AnthropicLlmService
from mango.integrations.mongodb import MongoRunner
from mango.integrations.chromadb import ChromaAgentMemory
# Configure your LLM
llm = AnthropicLlmService(
model="claude-sonnet-4-6",
api_key="YOUR_API_KEY",
)
# Configure your database
db = MongoRunner()
db.connect("mongodb://localhost:27017/mydb")
# Configure your agent memory
agent_memory = ChromaAgentMemory(
persist_dir="./chroma_db",
)
# Create your agent
agent = MangoAgent(
llm_service=llm,
tool_registry=tools,
db=db,
agent_memory=agent_memory,
introspect=False
)
# Run the server
server = MangoFastAPIServer(agent)
server.run() # http://localhost:8000
Every feature is built for real use — not a demo. MQL validation, auto-retry, memory, schema introspection, SSE streaming — the things that make it safe to run in production.