Kagent is an intelligent agent system built around the Codex protocol. It provides a CLI, backend services, a controller, and a web UI. The codebase is organized as a Rust workspace, and the frontend is built with Next.js and managed via bun.
kagent-cli: CLI entrypoint.kagent-api-server: REST API service.kagent-codex-server: Codex protocol server.kagent-controller: Sandbox/Pod controller.kagent-core: Core business logic.kagent-config: Configuration definitions and loading.kagent-sandbox: Sandbox management.kagent-sandbox-type: Sandbox type definitions.kagent-assembler: File fetching and assembly inside containers.kagent-db: Database access layer.kagent-db-migration: Database migrations.kagent-observability: Observability and telemetry.kagent-etl: ETL-related components.kagent-event: Event-related components.kagent-git: Git-related components.kagent-util: Shared utilities.kagent-ui: Web UI.codex/,codex-utils/: Codex protocol implementation and utilities.
- Rust (see
rust-toolchain.tomlfor the pinned version) - bun (see
kagent-ui/package.jsonfor the version) - Postgres (used by the API server and migrations)
Kagent loads configuration from the following locations (low to high priority):
${KAGENT_HOME:-~/.kagent}/config.toml.kagent/config.tomlwithin the repo (searched upwards to the project root)
Example configuration:
[api_server]
addr = "127.0.0.1:8080"
auto_migrate = true
[database]
url = "postgres://user:pass@127.0.0.1:5432/kagent"cargo run -p kagent-cli -- codex-server
cargo run -p kagent-cli -- api-server
cargo run -p kagent-cli -- controller
cargo run -p kagent-cli -- db migrateCommon environment variables:
KAGENT_CODEX_PORT: Port used by the API server to connect to the Codex server (default8080).KAGENT_POLL_INTERVAL_SECS: Controller polling interval in seconds (default10).KAGENT_HOME: Custom config directory.
Show all CLI commands:
cargo run -p kagent-cli -- --helpcd kagent-ui
bun install
bun devOpen http://localhost:3000 in your browser.
kagent-ui/lib/codex-app-server is a generated directory and should not be edited manually. Regenerate after protocol changes:
cargo run --bin codex -- app-server generate-ts -o kagent-ui/lib/codex-app-serverThis project is licensed under the Apache License 2.0 - see the LICENSE file for details.
- After modifying Rust code, ensure
cargo checksucceeds for the workspace. - For the frontend, use
bun lintas needed.