Try the live demo at copilotkit.tako.com to see the integration in action.
Architecture Overview
Prerequisites
- Node.js 18+ and Python 3.11+
- API keys:
| Name | Purpose |
|---|---|
OPENAI_API_KEY | LLM for agent reasoning |
TAVILY_API_KEY | Web search |
TAKO_API_TOKEN | Tako data visualizations |
TAKO_MCP_URL | MCP server endpoint (default: https://mcp.tako.com) |
1. Set up the project
.env.local:
2. Define the MCP client
Create a client to communicate with Tako’s MCP server for knowledge search:mcp_integration.py
3. Create the knowledge search function
Use the MCP client to search Tako’s knowledge base:mcp_integration.py
4. Get iframe HTML for charts
Retrieve embeddable iframe HTML for Tako visualizations:mcp_integration.py
5. Define the LangGraph agent state
Define the state that flows through your agent workflow:state.py
6. Create the search node
Build a LangGraph node that searches both Tako and web sources in parallel:search.py
7. Build the LangGraph workflow
Compose nodes into a complete agent workflow:agent.py
8. Expose the agent via FastAPI
Create an endpoint that CopilotKit can connect to:main.py
9. Connect the React frontend
Use CopilotKit hooks to connect your UI to the LangGraph agent:Main.tsx
10. Wrap the app with CopilotKit
Configure the CopilotKit provider to connect to your agent backend:page.tsx
app/api/copilotkit/route.ts
Run the application
- Frontend: http://localhost:3000
- Agent: http://localhost:2024
- “Compare NVIDIA and AMD revenue over the last 5 years”
- “What are the trends in global military spending?”
- “How has inflation affected rent prices in major US cities?”
Key concepts
| Concept | Description |
|---|---|
| MCP Integration | Tako exposes data via Model Context Protocol for structured access |
| Parallel Search | Web and Tako searches run concurrently for faster results |
| Iframe Embedding | Charts are embedded as responsive iframes with resize handling |
| State Sync | CopilotKit’s useCoAgent keeps frontend and agent state synchronized |
| LangGraph Workflow | Nodes handle chat, search, and report generation in a directed graph |