|
1 | | -# Cube D3 Agent Platform Integration Examples |
| 1 | +# Cube AI Agent Integration Examples |
2 | 2 |
|
3 | | -This repository contains a collection of examples demonstrating how to integrate the Cube D3 agent platform into your applications using the Chat API. |
| 3 | +This repository contains a collection of examples demonstrating how to integrate Cube AI Agents into your applications using the Chat API and advanced workflow orchestration. |
4 | 4 |
|
5 | 5 | ## Overview |
6 | 6 |
|
7 | | -Cube D3 is a powerful agent platform that enables you to build AI-powered data applications. This repository showcases practical integration patterns and implementations. |
| 7 | +Cube AI Agents enable you to build intelligent, data-driven applications with natural language interfaces. This repository showcases practical integration patterns from simple chat interfaces to complex multi-step workflows. |
| 8 | + |
| 9 | +## Repository Structure |
| 10 | + |
| 11 | +``` |
| 12 | +d3_examples/ |
| 13 | +├── shared/ # Shared utilities |
| 14 | +│ └── cube-agent-client/ # Reusable Cube Agent client library |
| 15 | +├── chat-api/ # Simple chat API example |
| 16 | +├── langgraph-analytics/ # LangGraph workflow example |
| 17 | +└── react-app/ # React application example |
| 18 | +``` |
8 | 19 |
|
9 | 20 | ## Examples |
10 | 21 |
|
11 | | -### 1. Chat API |
12 | | -[Node.js example](chat-api/) for using the Cube Chat API with streaming responses. |
| 22 | +### 1. Cube Agent Client Library |
| 23 | + |
| 24 | +**Location**: [shared/cube-agent-client/](shared/cube-agent-client/) |
| 25 | + |
| 26 | +A reusable Node.js client library for interacting with Cube AI Agents. Provides a clean API for session management, authentication, and streaming chat interactions. |
| 27 | + |
| 28 | +**Features**: |
| 29 | +- Simple `chat()` and `streamChat()` methods |
| 30 | +- Automatic session/token management |
| 31 | +- Detailed responses with thinking and tool calls |
| 32 | +- Support for Cube Cloud |
| 33 | + |
| 34 | +**Quick Start**: |
| 35 | +```javascript |
| 36 | +import { CubeAgentClient } from '../shared/cube-agent-client/index.js'; |
| 37 | + |
| 38 | +const client = new CubeAgentClient({ |
| 39 | + tenantName: 'your-tenant', |
| 40 | + agentId: 1, |
| 41 | + apiKey: 'your-api-key' |
| 42 | +}); |
| 43 | + |
| 44 | +const response = await client.chat('What is the total revenue?'); |
| 45 | +``` |
| 46 | + |
| 47 | +### 2. Chat API |
| 48 | + |
| 49 | +**Location**: [chat-api/](chat-api/) |
| 50 | + |
| 51 | +A simple Node.js example for using the Cube Chat API with streaming responses. Great starting point for understanding the basics of Cube AI Agent integration. |
| 52 | + |
| 53 | +**Features**: |
| 54 | +- Session generation and token authentication |
| 55 | +- Streaming chat responses |
| 56 | +- Real-time display of assistant messages, thinking process, and tool calls |
| 57 | + |
| 58 | +**Quick Start**: |
| 59 | +```bash |
| 60 | +cd chat-api |
| 61 | +CUBE_TENANT_NAME=xxx CUBE_AGENT_ID=yyy CUBE_API_KEY=zzz node chat.js "Your question" |
| 62 | +``` |
| 63 | + |
| 64 | +### 3. LangGraph Analytics Workflow |
| 65 | + |
| 66 | +**Location**: [langgraph-analytics/](langgraph-analytics/) |
| 67 | + |
| 68 | +An advanced example demonstrating stateful analytics workflows using **LangGraph.js** and Cube AI Agents. Shows how to build complex, multi-step data analysis workflows with state management, retry logic, and conditional routing. |
| 69 | + |
| 70 | +**Features**: |
| 71 | +- Graph-based workflow orchestration |
| 72 | +- Stateful execution with persistent memory |
| 73 | +- Automatic retry logic for failed queries |
| 74 | +- Question classification and intelligent routing |
| 75 | +- Multi-step analysis pipeline: Classify → Query → Analyze → Insights |
| 76 | + |
| 77 | +**Workflow**: |
| 78 | +``` |
| 79 | +START → Classify Question → Query Cube → Analyze Results → Generate Insights → END |
| 80 | + ↓ (retry on error) |
| 81 | + Query Cube |
| 82 | +``` |
| 83 | + |
| 84 | +**Quick Start**: |
| 85 | +```bash |
| 86 | +cd langgraph-analytics |
| 87 | +npm install |
| 88 | +npm start "What are the top 10 customers by revenue?" |
| 89 | +``` |
| 90 | + |
| 91 | +**Why LangGraph?**: |
| 92 | +LangGraph.js enables cyclic graphs with loops and state management, unlike linear chains in LangChain.js. Perfect for building sophisticated AI agents with complex control flow. |
| 93 | + |
| 94 | +### 4. React App |
| 95 | + |
| 96 | +**Location**: [react-app/](react-app/) |
13 | 97 |
|
14 | | -### 2. D3 React App |
15 | | -[Next.js React application](d3-react-app/) that demonstrates integration with the D3 AI Agent API for streaming chat functionality. |
| 98 | +A Next.js React application demonstrating how to integrate Cube AI Agents into a modern web application with streaming chat functionality. |
| 99 | + |
| 100 | +**Features**: |
| 101 | +- React-based chat interface |
| 102 | +- Streaming responses with real-time updates |
| 103 | +- UI components for displaying agent responses |
16 | 104 |
|
17 | 105 | ## Getting Started |
18 | 106 |
|
19 | | -Each example directory contains its own README with detailed setup instructions and usage examples. |
| 107 | +### Prerequisites |
| 108 | + |
| 109 | +- Node.js 20+ |
| 110 | +- Access to Cube Cloud |
| 111 | +- Cube AI Agent configured |
| 112 | + |
| 113 | +### Environment Variables |
| 114 | + |
| 115 | +All examples support the following environment variables: |
| 116 | + |
| 117 | +```bash |
| 118 | +# Required |
| 119 | +CUBE_TENANT_NAME=your-tenant-name |
| 120 | +CUBE_AGENT_ID=1 |
| 121 | +CUBE_API_KEY=your-api-key |
| 122 | + |
| 123 | +# Optional (for custom deployments) |
| 124 | +CUBE_API_URL=https://your-custom-domain.com |
| 125 | +AI_ENGINEER_URL=https://your-ai-engineer-url.com |
| 126 | +``` |
| 127 | + |
| 128 | +## Example Progression |
| 129 | + |
| 130 | +We recommend exploring the examples in this order: |
| 131 | + |
| 132 | +1. **Start with [chat-api/](chat-api/)** - Learn the basics of Cube AI Agent integration |
| 133 | +2. **Review [shared/cube-agent-client/](shared/cube-agent-client/)** - Understand the reusable client library |
| 134 | +3. **Explore [langgraph-analytics/](langgraph-analytics/)** - Build complex workflows with state management |
| 135 | +4. **Check out [react-app/](react-app/)** - Integrate into a React application |
| 136 | + |
| 137 | +## Use Cases |
| 138 | + |
| 139 | +### Simple Chat Interface |
| 140 | +Use the **chat-api** or **cube-agent-client** examples for: |
| 141 | +- Basic Q&A interfaces |
| 142 | +- Simple data queries |
| 143 | +- Prototyping and testing |
| 144 | + |
| 145 | +### Complex Workflows |
| 146 | +Use the **langgraph-analytics** example for: |
| 147 | +- Multi-step data analysis pipelines |
| 148 | +- Stateful conversations with memory |
| 149 | +- Conditional logic and branching |
| 150 | +- Retry mechanisms and error handling |
| 151 | +- Business process automation |
| 152 | + |
| 153 | +### Web Applications |
| 154 | +Use the **react-app** example for: |
| 155 | +- Interactive dashboards |
| 156 | +- BI copilots |
| 157 | +- Embedded analytics |
| 158 | +- Customer-facing data apps |
20 | 159 |
|
21 | 160 | ## API Documentation |
22 | 161 |
|
23 | | -Full documentation: https://docs.cube.dev/embed/api/chat |
| 162 | +- [Cube Chat API](https://docs.cube.dev/embed/api/chat) |
| 163 | +- [LangGraph.js Documentation](https://langchain-ai.github.io/langgraphjs/) |
| 164 | + |
| 165 | +## Architecture |
| 166 | + |
| 167 | +### High-Level Flow |
| 168 | + |
| 169 | +``` |
| 170 | +User Question |
| 171 | + ↓ |
| 172 | +[Chat API / LangGraph Workflow] |
| 173 | + ↓ |
| 174 | +Cube Agent Client Library |
| 175 | + ↓ |
| 176 | +1. Generate Session (Cube API) |
| 177 | +2. Get Auth Token (Cube API) |
| 178 | +3. Stream Chat (AI Engineer API) |
| 179 | + ↓ |
| 180 | +Cube AI Agent |
| 181 | + ↓ |
| 182 | +Response (with thinking, tool calls, results) |
| 183 | +``` |
| 184 | + |
| 185 | +### Components |
| 186 | + |
| 187 | +- **Cube Agent Client**: Handles authentication and communication |
| 188 | +- **LangGraph Workflow**: Orchestrates multi-step analysis |
| 189 | +- **Cube AI Agent**: Processes queries and generates insights |
| 190 | +- **Tool Calls**: Agent can query data sources, perform calculations, etc. |
| 191 | + |
| 192 | +## Contributing |
| 193 | + |
| 194 | +Each example directory contains its own README with detailed setup instructions and usage examples. Feel free to extend these examples for your specific use cases. |
| 195 | + |
| 196 | +## License |
| 197 | + |
| 198 | +MIT |
0 commit comments