How shlomoc/open-ag-ui-canvas works
Project Type and Purpose
• This is a full-stack, agent-driven UI demo showcasing three “canvases” (Research, Planner, Haiku) built on the AGUI protocol.
• The backend (“agent/”) is a Python FastAPI service exposing multiple agent endpoints (Research via LangGraph, Planner via CrewAI, CopilotKit).
• The frontend (“frontend/”) is a Next.js/React application that hosts three distinct canvas UIs and a Mastra agent server for the Haiku Canvas.
File-Structure Analysis
• Top level:
• agent/ → Python FastAPI app (main.py, planner_crew.py, research_langgraph.py, researchState.py)
• frontend/ → Next.js 13 app folder with sub-routes for each canvas, components/, hooks/, lib/, styles/, plus a Mastra agent server script (dev:agent).
• Frontend routing:
• /crewai, /langgraph, /mastra → each folder under app/ corresponds to a canvas page.
• API route at app/api/copilotkit/route.ts proxies CopilotKit calls.
• Config & deps:
• frontend/.env for OPENAI_API_KEY, REMOTE_ACTION_URL (Python agent), NEXT_PUBLIC_REMOTE_ACTION_URL_MASTRA (Mastra).
• agent/.env for Python agent keys.
• No persistent database; state is managed in memory or delegated to agents.
Key Components
A. Frontend UI Layer (Next.js/React)
• Research Canvas UI
• Planner Canvas UI
• Haiku Canvas UI
B. Frontend Agent Server (Mastra)
• Runs via pnpm run dev:agent
• Exposes HTTP endpoint on port 4111
• Implements Mastra-based Haiku Agent
C. Backend Agent Server (FastAPI)
• Exposes HTTP endpoints (e.g. /copilotkit, /research, /planner) on port 8000
• Modules:
– research_langgraph.py (LangGraph research agent)
– planner_crew.py (CrewAI planner agent)
– researchState.py (internal state management)
• Integrations: OpenAI API, Tavily API, CopilotKit Python SDK
D. External Services
• OpenAI API
• Tavily API
• (Possibly other AGUI-protocol services)
Relationships and Data Flows
• User interacts with a Canvas UI in the browser.
• Canvas UI → HTTP call to:
• Python FastAPI agent (REMOTE_ACTION_URL=http://0.0.0.0:8000/copilotkit) for Research & Planner canvases.
• Mastra agent server (NEXT_PUBLIC_REMOTE_ACTION_URL_MASTRA=http://localhost:4111) for Haiku canvas.
• Agent server receives request → invokes respective agent module → calls external APIs (OpenAI/Tavily) → returns response to frontend.
• Frontend renders AI suggestions, updates workspace state, and displays progress indicators.
Architectural Patterns & Principles
• Clear separation of concerns: UI layer vs. agent logic vs. third-party integrations.
• Micro-service-like pattern: two independent agent services (FastAPI + Mastra) behind API gateways.
• Component-driven UI: shared React components and hooks for state, theming, responsive behavior.
• Plug-in agent architecture: each canvas wires to a specific agent implementation following the AGUI protocol.
Detailed Component Breakdown (to include
• Frontend →
• app/crewai, app/langgraph, app/mastra pages
• components/* (agent-selector, workspace, layout)
• api/copilotkit route
• Backend FastAPI →
• main.py (app entrypoint)
• planner_crew.py (CrewAI)
• research_langgraph.py (LangGraph)
• Mastra Agent →
• Mastra AGUI framework in frontend/src/mastra
• agents/, tools/ subfolders