Skip to content

ComposioHQ/data-analyst-agent

Repository files navigation

Data Analyst Agent

Data Analyst Agent Demo

Start building with Composio Documentation

GitHub Twitter LinkedIn Discord

A Data Analyst AI Agent with multi-framework support, supported by tool router via Composio, and persistent chat history. Built for connecting to multiple data sources like Hubspot, Attio, Google Sheets and analyzing data, generating insights, and creating visualizations through natural language conversations.

Features

  • Multi-Framework Support: Choose from Vercel AI SDK, LangChain, OpenAI Agents SDK, or Claude Agents SDK
  • Multi-Model Support: Works with OpenAI (GPT-4o, GPT-4o Mini, GPT-5.2), Anthropic (Claude Opus 4.5, Sonnet 4.5, Haiku 4.5), and Google models
  • Tool Integration: Seamless integration with external tools via Composio Tool Router
  • Chat History: Persistent conversation history with database storage
  • Authentication: Secure authentication flow with NextAuth v5 and Composio
  • Database: PostgreSQL with Drizzle ORM for reliable data persistence
  • Modern UI: Beautiful chat interface with dark mode, live previews, and responsive design
  • Rate Limiting: Built-in rate limiting for API protection
  • Security: Request validation, environment validation, and secure auth flows

Tech Stack

  • Framework: Next.js 16 (App Router)
  • Language: TypeScript
  • Database: PostgreSQL
  • ORM: Drizzle ORM
  • Auth: NextAuth.js (Auth.js v5)
  • AI Frameworks:
    • Vercel AI SDK (with MCP support)
    • LangChain (with MultiServerMCPClient)
    • OpenAI Agents SDK
    • Claude Agents SDK
  • Tool Integration: Composio Tool Router
  • Styling: Tailwind CSS
  • Validation: Zod (Env vars & Schema)
  • Testing: Vitest
  • Linting: ESLint + Prettier

Getting Started

1. Prerequisites

  • Node.js 18+
  • PostgreSQL database (local or cloud like Neon/Supabase)

2. Environment Setup

Create a .env file in the root directory:

# Database
DATABASE_URL="postgres://user:pass@localhost:5432/data_analyst_agent"

# NextAuth
AUTH_SECRET="your_generated_secret" # generate with `npx auth secret` or `openssl rand -base64 32`
AUTH_URL="http://localhost:3000" # Deployment URL

# Composio (Tools & Auth)
COMPOSIO_API_KEY="your_composio_api_key"
AUTH_CONFIG_ID="your_auth_config_id" # From Composio Dashboard at platform.composio.dev

# AI Providers (At least one required)
OPENAI_API_KEY="sk-..."
ANTHROPIC_API_KEY="sk-..."
GEMINI_API_KEY="sk-..."

3. Installation

npm install

4. Database Setup

Push the schema to your database (for local dev):

npm run db:push

For production migrations:

npm run db:generate
npm run db:migrate

5. Run Development Server

npm run dev

Open http://localhost:3000.

Architecture

Authentication Flow

  1. User clicks "Sign in with Composio".
  2. App generates a unique userId and calls the Composio link API.
  3. User authenticates with the external provider (e.g., Google/GitHub).
  4. Composio redirects back to /auth/callback.
  5. App verifies the userId and creates a NextAuth session.

AI & Tools

The application supports four different AI frameworks, allowing you to choose the best one for your use case:

  1. Vercel AI SDK (default): Uses streamText with MCP client for tool integration
  2. LangChain: Uses MultiServerMCPClient with React Agent
  3. OpenAI Agents SDK: Native OpenAI agent framework
  4. Claude Agents SDK: Native Anthropic agent framework

Tools are executed via Composio MCP on the server (app/api/chat/route.ts). The system automatically routes to the appropriate framework handler based on your selection. Rate limiting (10 requests per minute) is applied per user session.

Chat History

Conversations are automatically saved to the database with full message history. Each chat session can be resumed, deleted, or managed through the sidebar interface. Messages include both text content and structured parts (tool calls, images, etc.).

Database Scripts

Drizzle commands require DATABASE_URL to be set. Either export it or prefix the command:

# Option 1: Export in shell
export DATABASE_URL="postgres://..."
npm run db:push

# Option 2: Inline
DATABASE_URL="postgres://..." npm run db:push
  • npm run db:push: Push schema changes directly (prototyping only).
  • npm run db:generate: Generate SQL migration files (production).
  • npm run db:migrate: Apply migration files to the DB.
  • npm run db:studio: Open Drizzle Studio to view data.

Deployment

  1. Build: npm run build
  2. Environment: Ensure all .env variables are set in your provider (Vercel/Railway).
  3. Database: Run npm run db:migrate during the build process or as a post-deploy step.

Available Scripts

  • npm run dev: Start development server
  • npm run build: Build for production
  • npm run start: Start production server
  • npm run lint: Run ESLint
  • npm run format: Format code with Prettier
  • npm run format:check: Check code formatting
  • npm run test: Run tests with Vitest
  • npm run test:watch: Run tests in watch mode
  • npm run db:push: Push schema changes to database (development)
  • npm run db:generate: Generate migration files (production)
  • npm run db:migrate: Apply migrations to database
  • npm run db:studio: Open Drizzle Studio for database management

Contributing

  1. Fork the repository.
  2. Create a feature branch.
  3. Commit your changes.
  4. Push to the branch.
  5. Open a Pull Request.

Composio

This project uses Composio for tool integrations and authentication.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published