LangChain Integration
← DocsThree patterns for using Wikitopia's knowledge graph in LangChain agents.
Pattern 1 — LangChain Tool (simplest)
Wrap the Wikitopia REST API as a LangChain Tool. Works with any LLM.
from langchain.tools import Tool
import requests
API_URL = "https://api.wikitopia.org"
def search_wikitopia(query: str) -> str:
"""Search for verified facts about AI tools, models, and companies."""
res = requests.get(f"{API_URL}/v1/search",
params={"q": query, "mode": "hybrid", "limit": 5})
entities = res.json().get("results", [])
return "\n".join([
f"{e['canonical_name']} ({e['entity_type']}): "
f"{e.get('description', 'No description')[:120]}"
for e in entities
]) or "No results found."
def get_entity(name: str) -> str:
"""Get detailed info about a specific AI entity."""
res = requests.get(f"{API_URL}/v1/entities/{name}")
if res.status_code == 404:
return f"Entity '{name}' not found."
e = res.json()
props = e.get("properties", {})
lines = [f"# {e['canonical_name']} ({e['entity_type']})"]
if e.get("description"):
lines.append(e["description"])
for key in ["developed_by", "license_type", "founded_year", "primary_use_case"]:
if props.get(key):
lines.append(f"{key}: {props[key]}")
lines.append(f"Claims: {e.get('claim_count', 0)}")
return "\n".join(lines)
wikitopia_search = Tool(
name="WikitopiaSearch",
description="Search Wikitopia for verified facts about AI tools, "
"models, frameworks, and companies. Input: search query string.",
func=search_wikitopia,
)
wikitopia_entity = Tool(
name="WikitopiaEntity",
description="Get detailed profile of a specific AI entity by name. "
"Input: entity name like 'LangChain' or 'OpenAI'.",
func=get_entity,
)Usage with an agent
from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="gpt-4o-mini")
agent = initialize_agent(
tools=[wikitopia_search, wikitopia_entity],
llm=llm,
agent=AgentType.OPENAI_FUNCTIONS,
verbose=True,
)
result = agent.run("Compare the top 3 open-source vector databases")
print(result)Pattern 2 — Community Package (coming soon)
# pip install langchain-wikitopia (in development)
from langchain_wikitopia import WikitopiaSearchTool, WikitopiaEntityTool
tools = [
WikitopiaSearchTool(), # Wraps /v1/search
WikitopiaEntityTool(), # Wraps /v1/entities/:name
]A dedicated langchain-wikitopia package is in development with built-in caching, type-safe outputs, and async support. Watch the repo for updates.
Pattern 3 — MCP via LangChain
Use the Wikitopia MCP server with Claude or any MCP-compatible model.
# Install the MCP server globally
npx wikitopia-mcp
# Or add to claude_desktop_config.json:
{
"mcpServers": {
"wikitopia": {
"command": "npx",
"args": ["-y", "wikitopia-mcp"]
}
}
}The MCP server provides 8 tools including wikitopia_search, wikitopia_get_entity, wikitopia_compare, and wikitopia_explore_ecosystem.
See also
- API Playground — test endpoints interactively
- LlamaIndex integration
- Vercel AI SDK integration
- OpenAI Functions integration
- Full API documentation