This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Agentex is a comprehensive platform for building and deploying intelligent agents. This repository contains:
- agentex/ - Backend services (FastAPI + Temporal workflows)
- agentex-ui/ - Developer UI for interacting with agents
The platform integrates with the separate agentex-python SDK for creating and running agents.
- Python 3.12+ (required for agentex-sdk)
- Docker and Docker Compose
- Node.js (for frontend)
- uv (Python package manager)
Terminal 1 - Backend:
cd agentex/
make dev # Starts Docker services and backendTerminal 2 - Frontend:
cd agentex-ui/
npm install
npm run dev # Starts Next.js dev serverTerminal 3 - Agent Development:
export ENVIRONMENT=development
agentex init # Create a new agent
cd your-agent-name/
agentex agents run --manifest manifest.yamlWhen running make dev in agentex/, the following services start:
- Port 5003: FastAPI backend server
- Port 5432: PostgreSQL (application database)
- Port 5433: PostgreSQL (Temporal database)
- Port 6379: Redis (streams and caching)
- Port 27017: MongoDB (document storage)
- Port 7233: Temporal server
- Port 8080: Temporal Web UI
All services are networked via agentex-network bridge network.
# Setup and installation
make install # Install dependencies with uv
make install-dev # Install with dev dependencies (includes pre-commit)
make clean # Clean venv and lock files
# Development server
make dev # Start all Docker services
make dev-stop # Stop Docker services
make dev-wipe # Stop services and wipe volumes
# Database migrations
make migration NAME="description" # Create new Alembic migration
make apply-migrations # Apply pending migrations
# Testing
make test # Run all tests
make test FILE=tests/unit/ # Run unit tests
make test FILE=tests/unit/test_foo.py # Run specific test file
make test NAME=crud # Run tests matching pattern
make test-unit # Unit tests shortcut
make test-integration # Integration tests shortcut
make test-cov # Run with coverage report
make test-docker-check # Verify Docker setup for tests
# Documentation
make serve-docs # Serve MkDocs on localhost:8001
make build-docs # Build documentation
# Deployment
make docker-build # Build production Docker imagenpm install # Install npm dependencies
npm run dev # Next.js dev server with Turbopack
npm run build # Build production bundle
npm run typecheck # TypeScript type checking
npm run lint # Run ESLint
npm run format # Run Prettier formatting
npm test # Run tests# Always set this first
export ENVIRONMENT=development
# Agent management
agentex init # Create new agent
agentex agents run --manifest manifest.yaml # Run agent locally (dev)
agentex agents list # List all agents
agentex agents build --manifest manifest.yaml --push # Build & push image
agentex agents deploy --manifest manifest.yaml # Deploy to staging
# Package management (if using uv in agent)
agentex uv sync # Sync dependencies
agentex uv add requests # Add new dependency
# Other utilities
agentex tasks list # View agent tasks
agentex secrets create # Manage secretsThe backend (agentex/src/) follows a clean architecture with strict layer separation:
src/
├── api/ # FastAPI routes, middleware, request/response schemas
│ ├── routes/ # API endpoints (agents, tasks, messages, spans, etc.)
│ ├── schemas/ # Pydantic request/response models
│ ├── authentication_middleware.py
│ └── app.py # FastAPI application setup
├── domain/ # Business logic (framework-agnostic)
│ ├── entities/ # Core domain models
│ ├── repositories/ # Data access interfaces
│ ├── services/ # Domain services
│ └── use_cases/ # Application use cases
├── adapters/ # External integrations
│ ├── crud_store/ # Database adapters (PostgreSQL, MongoDB)
│ ├── streams/ # Redis stream adapter
│ ├── authentication/ # Auth proxy adapter
│ └── authorization/ # Authz proxy adapter
├── config/ # Configuration and dependencies
│ ├── dependencies.py # Singleton for global dependencies (DB, Temporal, Redis)
│ └── mongodb_indexes.py
└── utils/ # Shared utilities
Key principles:
- Domain layer has no dependencies on frameworks or adapters
- API layer handles HTTP concerns, delegates to use cases
- Adapters implement ports defined in domain layer
- Dependencies flow inward (API → Domain ← Adapters)
- FastAPI: Web framework with automatic OpenAPI docs at
/swaggerand/api - Temporal: Workflow orchestration for long-running agent tasks
- PostgreSQL: Primary relational database (SQLAlchemy + Alembic migrations)
- MongoDB: Document storage for flexible schemas
- Redis: Streams for real-time communication and caching
- Docker: Containerization and local development
Global dependencies are managed via a Singleton pattern in src/config/dependencies.py:
GlobalDependencies: Singleton holding connections to Temporal, databases, Redis, etc.- FastAPI dependencies use
Annotatedtypes (e.g.,DDatabaseAsyncReadWriteEngine) - Connection pools are configured with appropriate sizes for concurrency
- Startup/shutdown lifecycle managed in
app.pylifespan context
Tests are organized by type and use different strategies:
Unit Tests (tests/unit/):
- Fast, isolated tests using mocks
- Test domain logic, repositories, services
- Marked with
@pytest.mark.unit
Integration Tests (tests/integration/):
- Test with real dependencies using testcontainers
- Postgres, Redis, MongoDB containers spun up automatically
- Test API endpoints end-to-end
- Marked with
@pytest.mark.integration
Test Runner (scripts/run_tests.py):
- Automatically detects Docker environment
- Handles testcontainer setup
- Smart dependency installation
- Run via
make testwith various options
- Authentication: Custom
AgentexAuthMiddlewareverifies requests via external auth service - Authorization: Domain service (
authorization_service.py) checks permissions - API Keys: Agent-specific keys stored in PostgreSQL (
agent_api_keystable) - Principal Context: User/agent identity passed through request context
- Agents: Autonomous entities that execute tasks, managed via ACP protocol
- Tasks: Work units with lifecycle states (pending → running → completed/failed)
- Messages: Communication between system and agents (stored in MongoDB)
- Spans: Execution traces for observability (OpenTelemetry-style)
- Events: Domain events for async communication
- States: Key-value state storage for agents
- Deployment History: Track agent deployment versions and changes
- Framework: Next.js 15 with React 19 and App Router
- Styling: Tailwind CSS with Radix UI components
- State: React hooks and context
- Forms: React Hook Form with Zod validation
- UI Components: Custom components built on Radix primitives
For local development, always set:
export ENVIRONMENT=developmentBackend services read from:
DATABASE_URL: PostgreSQL connection stringTEMPORAL_ADDRESS: Temporal server addressREDIS_URL: Redis connection stringMONGODB_URI: MongoDB connection stringMONGODB_DATABASE_NAME: MongoDB database name
Check agentex/docker-compose.yml for default values.
Always create migrations when changing models:
- Modify SQLAlchemy models in
database/models/ - Run
make migration NAME="description"fromagentex/ - Review generated migration in
database/migrations/versions/ - Apply with
make apply-migrations
Migrations run automatically during make dev startup.
If you have local Redis running, it conflicts with Docker Redis on port 6379:
# macOS
brew services stop redis
# Linux
sudo systemctl stop redis-server- Access Temporal UI at http://localhost:8080
- Workflows are defined using temporalio Python SDK
- Task queues are used to route work to agents
- Workflow state persists across service restarts
- Swagger UI: http://localhost:5003/swagger (interactive)
- ReDoc: http://localhost:5003/api (readable)
- OpenAPI spec: http://localhost:5003/openapi.json
- Define domain entity in
src/domain/entities/ - Create repository interface in
src/domain/repositories/ - Implement repository in
src/adapters/crud_store/ - Create use case in
src/domain/use_cases/ - Define request/response schemas in
src/api/schemas/ - Create route in
src/api/routes/ - Register router in
src/api/app.py - Write tests in
tests/unit/andtests/integration/
- Create SQLAlchemy model in
database/models/ - Generate migration:
make migration NAME="add_table_name" - Review and edit migration file if needed
- Apply migration:
make apply-migrations
- Define indexes in
src/config/mongodb_indexes.py - Create entity in
src/domain/entities/ - Implement CRUD operations in
src/adapters/crud_store/adapter_mongodb.py - Indexes are created automatically on startup
This repository contains two main components:
- Backend:
agentex/src/,agentex/database/,agentex/tests/ - Frontend:
agentex-ui/