Cocoagent is a full-stack AgentOS workspace for building, operating, and governing AI agents. The repository contains the FastAPI backend, Vue control plane, PostgreSQL schema migrations, Docker packaging, OpenAPI contract generation, and process gates in one place.
Core stack:
- Backend: Python 3.12+, FastAPI, Pydantic Settings, psycopg, optional LangGraph runtime.
- Frontend: Vue 3, TypeScript, Element Plus, Pinia, Vue Router, Vite.
- Storage: PostgreSQL 15 with pgvector.
- Packaging: Docker Compose and a multi-stage production image that builds the frontend and serves it from the backend.
- Unified AI chat and runtime entrypoint under
/ai/agent. - Agent configuration console for creating and managing Agent definitions.
- Telegram conversation entrypoint:
- Bot connection management from the UI.
- Default source-to-Agent binding.
- Local long polling mode for development and private deployments.
- Production webhook mode for public HTTPS deployments.
- Runtime status display including current mode, webhook URL, polling offset, and last error.
- Creating a Telegram connection from the UI automatically enables local long polling.
- LLM provider configuration and provider health/testing workflow.
- Skill management and tool/policy control surfaces.
- Approval center and runtime governance workflows.
- Learning and operations control-plane views.
- OpenAPI contract export plus generated frontend types.
- A01/A34/A35/A36 process gates for route drift, release readiness, and architecture/governance constraints.
cocoagent-python/src/cocoagent/main.py wires the main FastAPI application and registers these API areas:
/api/auth/api/ai/api/ai/unified/api/agent/runtime/api/agent-control/api/approvals/api/agent/approvals/api/integrations/telegram/api/skills- MCP and plugin governance endpoints from
cocoagent.api.mcp
The production image exposes the backend on container port 3099 and serves the built frontend from /app/public.
Main frontend routes live in frontend/src/router/modules/ai.ts.
The visible control-plane menu currently includes:
- Unified chat:
/ai/agent - Tools and policy:
/ai/tools-policy - LLM providers:
/ai/providers - Skill management:
/ai/skills - Agent configuration:
/ai/agents - Telegram integration:
/ai/integrations/telegram - Learning control:
/ai/agent/control-plane/learning-evolution - Operations dashboard:
/ai/agent/control-plane/operations
All frontend HTTP access must go through frontend/src/api/*.
- Frontend:
View/Store -> frontend/src/api/* -> Backend API. - Backend:
API -> Service -> DAO/Repository/DB. - Public API changes must update OpenAPI and generated frontend types in the same change set.
- Database behavior changes must be backed by SQL migrations and tests.
The root docker-compose.yml uses the published image ghcr.io/btnalit/cocoagent-x:latest.
cp .env.example .env
# Edit at least:
# - PG_PASSWORD
# - JWT_SECRET and INTERNAL_API_KEY if you do not want the entrypoint to generate them
docker compose pull
docker compose up -d
docker compose ps
docker compose logs -f cocoagentDefault root compose ports:
- Web UI and API:
http://localhost:8080 - Health check:
http://localhost:8080/api/health - PostgreSQL:
localhost:5432 - Syslog UDP:
514 - SNMP Trap UDP:
162
Important note for LLM provider variables:
- The root compose file is a minimal prebuilt-image deployment file. It passes database, secrets, and runtime flags into the container.
- If you run AI chat in that compose file, add the provider variables you need under
services.cocoagent.environmentor use the source-build compose below, which already forwards provider variables such asAI_PROVIDER,GEMINI_API_KEY,OPENAI_API_KEY,CLAUDE_API_KEY, andDEEPSEEK_API_KEY. Add other provider keys there if you use them.
Use cocoagent-python/docker-compose.yml when you want Docker to build the image from this checkout:
cp .env.example .env
docker compose -f cocoagent-python/docker-compose.yml up --build -dThis path builds the frontend with Node 20, installs the Python backend, copies the frontend dist into /app/public, and then starts Uvicorn inside the production image.
Prerequisites:
- Python 3.12+
- Node 20.x
- Docker with Compose
Install dependencies:
npm --prefix frontend install
cd cocoagent-python
pip install -e ".[dev]"
cd ..Start PostgreSQL:
docker compose up -d postgresRun backend and frontend in separate terminals:
npm run dev:backend
npm run dev:frontendLocal URLs:
- Frontend dev server:
http://127.0.0.1:5173 - Backend API:
http://127.0.0.1:3099 - Health:
http://127.0.0.1:3099/api/health
Telegram is configured from the frontend at /ai/integrations/telegram.
Typical local setup:
- Create a bot in BotFather and copy the Bot token.
- Open Telegram integration in Cocoagent.
- Create a Bot connection. The UI stores the token as write-only data and automatically enables local long polling.
- Create or select an Agent and save the default binding.
- Send a message to the bot in Telegram.
Local long polling:
- Does not require a public HTTPS URL.
- Uses Telegram
getUpdates. - Is the default path for local/private deployments after creating a connection in the UI.
- Controlled by
TELEGRAM_POLLING_RUNNER_ENABLED,TELEGRAM_POLLING_INTERVAL_SECONDS,TELEGRAM_POLLING_TIMEOUT_SECONDS, andTELEGRAM_POLLING_LIMIT.
Production webhook mode:
- Requires a public HTTPS base URL that reaches the Cocoagent backend.
- The UI can register/delete the Telegram webhook for a connection.
- The backend receives updates at
/api/integrations/telegram/webhook. - Webhook and long polling are mutually exclusive for the same bot.
Useful Telegram environment variables:
TELEGRAM_ALLOWED_USERSTELEGRAM_GROUP_ALLOWED_CHATSTELEGRAM_REQUIRE_MENTIONTELEGRAM_BOT_USERNAMETELEGRAM_REPLY_PARSE_MODETELEGRAM_WEBHOOK_SECRET
Real Telegram end-to-end validation still requires a real BotFather token and a Telegram client.
Reference files:
- Root deployment example:
.env.example - Backend-focused example:
cocoagent-python/.env.example
Common variables:
APP_ENVPORTDATABASE_URLorPG_USER/PG_PASSWORD/PG_HOST/PG_PORT/PG_DATABASEJWT_SECRETINTERNAL_API_KEYAI_PROVIDER- Provider keys such as
GEMINI_API_KEY,OPENAI_API_KEY,QWEN_API_KEY,ZHIPU_API_KEY CORS_ORIGINSHARNESS_RUNTIME_ENABLEDSUBAGENT_DISPATCH_ENABLEDAGENT_REACT_STATE_MACHINE_ENABLEDLANGGRAPH_RUNTIME_ENABLEDLANGGRAPH_POSTGRES_CHECKPOINTER_ENABLED
Production secret behavior:
cocoagent-python/docker-entrypoint.shgeneratesJWT_SECRETandINTERNAL_API_KEYin production when they are empty or weak.- Generated values are persisted to
/app/data/runtime-secrets.envin thecocoagent-datavolume.
Migrations run during backend startup through:
cocoagent-python/src/cocoagent/bootstrap/startup_pipeline.pycocoagent-python/src/cocoagent/data/migrations/runner.py
SQL files live under:
cocoagent-python/src/cocoagent/data/migrations/*.sql
Treat the migration directory as the source of truth. Recent migrations include AgentOS persistence, runtime state versions, memory assets, governance ledgers, action audit hash chains, and Telegram connection/webhook/polling tables.
In non-development environments, migration failure blocks startup.
Run these from the repository root unless noted otherwise.
OpenAPI contract:
npm run contract:sync
npm run contract:checkFrontend:
npm --prefix frontend run test
npm run lint
npm run buildBackend:
python cocoagent-python/scripts/run_backend_tests.pyProcess gates:
python cocoagent-python/scripts/a36_global_process_hard_constraints_runner.py --profile lite
python cocoagent-python/scripts/a35_process_hard_constraints_runner.py --profile lite
python cocoagent-python/scripts/a34_release_go_nogo_runner.py --profile liteRoot shortcuts:
npm run gate:lite
npm run ci:liteFor larger or release-bound changes, use the stricter profiles required by the current task and process rules.
cocoagent/
├── cocoagent-python/
│ ├── src/cocoagent/
│ │ ├── api/
│ │ ├── bootstrap/
│ │ ├── data/
│ │ │ └── migrations/
│ │ ├── services/
│ │ ├── main.py
│ │ └── settings.py
│ ├── scripts/
│ ├── tests/
│ ├── Dockerfile
│ ├── docker-compose.yml
│ └── pyproject.toml
├── frontend/
│ ├── openapi/
│ ├── src/
│ │ ├── api/
│ │ ├── router/
│ │ ├── stores/
│ │ └── views/
│ └── package.json
├── docker/
├── docker-compose.yml
├── package.json
├── .env.example
└── README.zh-CN.md
Apache License 2.0. See LICENSE.