This file provides guidance to Codex (Codex.ai/code) when working with code in this repository.
Cognix is a Hermes Agent-based multi-agent collaboration platform built in Python. It provides:
- A custom Agent runtime (Hermes Core) with tool calling, memory, and event system
- Multi-agent orchestration (Sequential, Parallel, Router, Loop patterns)
- Scheduled task / API scheduling (cron, interval, one-shot)
- JSON-RPC 2.0 inter-service communication
- Skills system (local directory + remote marketplace)
- CLI interface (Typer) + REST/WebSocket API (FastAPI)
- OAuth2 authentication (Google, GitHub) with JWT tokens and API keys
- RBAC permissions (admin, user, viewer roles)
- Language: Python 3.11+
- Web Backend: FastAPI + Uvicorn
- Web Frontend: React 18 + Vite + TypeScript + Tailwind CSS
- CLI: Typer + Rich
- Database: SQLite (dev) / PostgreSQL (prod) via SQLAlchemy + Alembic
- Scheduler: APScheduler
- LLM: LiteLLM (unified interface for OpenAI/Anthropic/local models)
- Config: Pydantic Settings (env prefix:
COGNIX_)
# Activate virtual environment
source .venv/bin/activate
# Web UI (development)
cd web && npm install && npm run dev # Starts on http://localhost:5173
cd web && npm run build # Production build
# Run CLI
cognix --help
cognix version
cognix init ./my-project
# Run API server
cognix server start --port 8000 --reload
# Agent management
cognix agent create --name my-agent --model gpt-4o
cognix agent list
cognix agent chat my-agent "Hello"
# Task management
cognix task add --name "daily-report" --cron "0 9 * * *" --agent reporter
cognix task list
# Skills
cognix skill list
cognix skill search "web search"
cognix skill install web_search
cognix skill create my-skill
# RPC
cognix rpc call agent.list
cognix rpc call agent.chat --params '{"agent_id":"test","message":"hi"}'
# Tests
pytest tests/ -v
pytest tests/unit/ -v --cov=cognix
# Linting
ruff check cognix/
ruff format cognix/
# Type checking
mypy cognix/- agent.py -
Agentclass: the fundamental runtime entity. Has tools, memory, state machine (IDLE/RUNNING/WAITING/ERROR). Handles LLM call + tool-call loops. - tool.py -
Toolclass +@tooldecorator. Tools are async callables with JSON Schema parameters. Export OpenAI function-calling format. - events.py -
EventBusasync pub/sub. Well-known events inEventsclass (agent., tool., task., skill., workflow.*). - memory.py -
MemoryBackendABC withInMemoryBackendimplementation. TTL support. - context.py -
Contextcarries conversation state (messages, variables, metadata) through agent execution. - registry.py -
AgentRegistrycentral registry for agent instances.
Multi-agent patterns: Sequential, Parallel, Router, Loop. YAML workflow DSL with Jinja2 templating.
APScheduler-based task engine. Supports cron/interval/one-shot schedules. Task types: agent_call, rpc_call, http_webhook, skill_exec, workflow.
JSON-RPC 2.0 server/client. Methods registered via @rpc_method decorator. Supports HTTP and WebSocket transport.
Skills are packages with skill.yaml manifest + handler.py entrypoint. Local directory + remote marketplace.
FastAPI app with REST endpoints at /api/v1/* and JSON-RPC at /rpc. Lifespan manages DB init/close.
Typer app with sub-command groups: agent, task, skill, workflow, rpc, server.
OAuth2 authentication with Google and GitHub providers. JWT tokens for sessions, bcrypt-hashed API keys for programmatic access. RBAC with admin/user/viewer roles. FastAPI dependencies: get_current_user, require_admin, require_permission("perm").
Stripe-based subscription billing. Plans: Free, Starter ($29/mo), Pro ($99/mo), Enterprise (custom). Usage tracking for api_calls, tokens, agent_runs. Webhook handlers for subscription lifecycle events.
React 18 SPA with Vite, TypeScript, Tailwind CSS. Pages: Dashboard, Agents (list + chat), Tasks, Skills, Billing, Settings. Auth via JWT stored in Zustand. API proxy to backend on port 8000.
SQLAlchemy async models: UserModel, APIKeyModel, AgentModel, ScheduledTaskModel, TaskRunModel, SkillModel. SQLite default, PostgreSQL in production.
- Agent = stateful runtime instance, not a stateless function
- Tool vs Skill: Tool is atomic; Skill is Tool + config + dependencies
- Event-driven: modules decoupled via EventBus
- Progressive storage: SQLite for dev (zero config), PostgreSQL for prod (change connection string only)
- LLM abstraction: LiteLLM provides unified interface; Agent falls back to echo if litellm not configured
Environment variables use COGNIX_ prefix with __ for nesting:
COGNIX_DEBUG=trueCOGNIX_DATABASE__URL=postgresql+asyncpg://...COGNIX_DEFAULT_MODEL=gpt-4oCOGNIX_LLM_API_KEY=sk-...COGNIX_SERVER__PORT=8000COGNIX_AUTH__SECRET_KEY=your-secret-keyCOGNIX_AUTH__GOOGLE_CLIENT_ID=...COGNIX_AUTH__GOOGLE_CLIENT_SECRET=...COGNIX_AUTH__GITHUB_CLIENT_ID=...COGNIX_AUTH__GITHUB_CLIENT_SECRET=...COGNIX_BILLING__STRIPE_SECRET_KEY=sk_...COGNIX_BILLING__STRIPE_WEBHOOK_SECRET=whsec_...COGNIX_BILLING__STRIPE_PRICE_STARTER=price_...COGNIX_BILLING__STRIPE_PRICE_PRO=price_...
All API endpoints (except /health, /, /docs) require authentication via:
- JWT Bearer token:
Authorization: Bearer <jwt> - API Key:
X-API-Key: cnx_xxxxx
OAuth2 login flow:
GET /auth/login/googleor/auth/login/github- redirects to providerGET /auth/callback/{provider}?code=...- exchanges code for JWT- Frontend stores JWT and uses it for subsequent requests
API key management:
POST /auth/api-keys- create new key (returns full key once)GET /auth/api-keys- list keysDELETE /auth/api-keys/{id}- revoke key
Subscription management endpoints:
GET /billing/plans- list available plansGET /billing/subscription- current subscriptionPOST /billing/checkout- create Stripe Checkout sessionPOST /billing/portal- create Customer Portal sessionGET /billing/usage- current usage statsPOST /billing/webhook- Stripe webhook handler