How bcg-x-official/agentkit works
Project Type and Purpose
• AgentKit is a full-stack application designed to help developers rapidly build production-grade “chat-based” agent apps. Its purpose is to provide a modular framework built upon FastAPI (backend) and Next.js (frontend) that integrates GenAI tools, task scheduling (with Celery/Redis), SQL and vector databases, and a flexible agent routing mechanism.
• The README emphasizes key areas such as reliability, modular agent architecture, configurable action plans, and a responsive UI.
File Structure
• Notice the clearly separated directories for the backend and frontend which confirms the full-stack nature.
• In the “backend” directory, observe:
• The use of Dockerfiles, Alembic migrations, and configuration files (YAMLs) that configure the agent, extraction tools, and other settings.
• A modular structure under “app” (including subdirectories like “api”, “config”, “core”, “db”, “services”, and “schemas”) which suggests an MVC-like and layered design.
• Specific modules for agent functionalities such as service subdirectories under “chat_agent” – including helpers, tools, and router agents – which point to a highly decoupled design for handling agent logic.
• Utilities for database operations, streaming responses, and error handling.
• In the “frontend” directory, observe:
• A Next.js and React stack with directories for pages, components, stores, hooks, and API client code.
• Configuration for ESLint, TailwindCSS, and testing (cypress, jest) which indicates good separation of concerns on the UI side.
• Directories indicating integration with authentication (NextAuth) and layout components intended for a reactive chat interface.
a. Main Components:
• Frontend: Built with Next.js (including pages, components, API client) that renders the reactive chat UI.
• Backend API: FastAPI application organized into versioned endpoints (e.g., v1 endpoints for chat, SQL queries, statistics). It handles authentication, routing, and integrates with the agent logic.
• Agent Services: These include the meta agent, chat agent, and associated tooling (such as PDF, SQL, image generation tools). Represent these as subcomponents within the backend’s “services” and “tools” modules.
• Database Layer: SQL databases (including the provided Chinook.db) and possibly a vector database integration for document ingestion.
• Task Queue: Use of Celery (with modules under backend/app/app/core/celery.py) with Redis for asynchronous and long-running tasks.
• Configuration and External Services: YAML config files (for agents, tools, extraction) indicate that the system is highly configurable. Also note external authentication (NextAuth) interfacing between frontend and backend.
b. Relationships and Interactions:
• The Frontend calls the Backend API endpoints to fetch and send chat queries.
• The API endpoints invoke the Agent Services (e.g., meta agent selects an appropriate action plan and routes the request to specific tool modules).
• The Agent Tools might interact in parallel (as described in the README’s "How it works" section) to retrieve data from databases or external services.
• Data storage and persistence are handled by the Database Layer; additional asynchronous processing is handled via the Task Queue (Celery/Redis) for long-running tasks.
• Use Docker-compose to manage deployment and inter-container communications among these components.
c. Architectural Patterns and Technologies:
• Separation of frontend and backend layers, with clear API boundaries.
• Modular, layered design in the backend, with configuration-driven agent and tool management.
• Use of asynchronous processing (Celery) to scale the agent’s pipeline.
• Leveraging containerization (Dockerfiles and docker-compose) for replicable deployment.
• Technologies: Next.js, FastAPI, Celery/Redis, Postgres (with pgvector), LangChain, NextAuth among others.