foundation-service
foundation-service is the hosted control and execution service for Agent Foundation. The initial service skeleton provides FastAPI process lifecycle, async SQLAlchemy infrastructure, Alembic migrations, shared pretty/JSON logging through converge-logging, local PostgreSQL and Redis, and one container image for all deployment roles.
What Is Ready
foundation-service servestarts FastAPI withall,control, orexecutionrole selection./healthzis process liveness;/readyzverifies database access.- One lifespan-owned async engine and session factory are shared by the process.
- Service HTTP integrations and ASGI tests use
httpx2. short_session()andtransaction()provide short database scopes with bounded cancellation cleanup.- Alembic uses service metadata, a dedicated unpooled sync connection, bounded PostgreSQL timeouts, and a session advisory lock.
- Local PostgreSQL 17 and Redis 7 are defined in
dev/compose.yaml. make db-migrategenerates revisions from a disposable database inside the local PostgreSQL service.- The production image runs as non-root and selects
all,control, orexecutionat runtime.
Business APIs, durable models, schedulers, queues, and execution workers are intentionally not stubbed. Add them as end-to-end capabilities rather than placeholder abstractions.
Local Development
Start PostgreSQL and Redis, apply migrations, and run the service:
make dev
make dev runs the setup and upgrade steps. Use make setup or make db-upgrade separately when only that operation is needed.
The default endpoints are:
http://127.0.0.1:8000/healthz
http://127.0.0.1:8000/readyz
Stop local infrastructure and remove its volumes when a clean database is needed:
make dev-down
Add an ORM Model
-
Add a model under
converge_foundation_service/db/models/using the sharedBase. -
Import the model from
db/models/__init__.pyso Alembic metadata includes it. -
Generate a revision from a disposable database:
make db-migrate msg="add conversation table"
-
Review
upgrade()anddowngrade()for names, constraints, indexes, locks, rolling compatibility, and rerun behavior. -
Apply and verify it locally:
make db-upgrade make db-check make test
The generator starts local PostgreSQL if necessary, creates an isolated temporary database, replays all existing revisions, autogenerates the model diff, formats the new file, and drops the temporary database in finally. It never compares models with the normal development database.
Do not create revision files manually. The empty versions/.gitkeep is intentional until the first durable model is accepted.
Database Usage
Import shared infrastructure from converge_foundation_service.db:
async with transaction(session_factory) as session:
session.add(record)
A transaction covers one database unit of work. Do not hold it across HTTP calls, model or tool execution, queue waits, sleeps, background tasks, or streaming responses. Repositories may flush; the application service owns the transaction boundary.
Streaming routes must finish database-backed authentication and initial reads before constructing the response. Pass immutable values to the generator and open a fresh short session only for a bounded read or write.
Commands
make setup
make dev
make dev-down
make db-migrate msg="description"
make db-upgrade
make db-downgrade
make db-current
make db-check
make db-history
make image-foundation-service
The underlying CLI is also available through uv run foundation-service --help.
Configuration
All settings use the FOUNDATION_ prefix. See the root .env.example for a local template.
| Setting | Default | Purpose |
|---|---|---|
FOUNDATION_ROLE |
all |
all, control, or execution process role |
FOUNDATION_AUTO_MIGRATE |
false |
Allow a migration-owning container to upgrade before serve |
FOUNDATION_DATABASE_CONNECT_TIMEOUT_SECONDS |
10 |
Maximum PostgreSQL connection establishment time |
FOUNDATION_DATABASE_STATEMENT_TIMEOUT_SECONDS |
30 |
Maximum normal application statement duration |
FOUNDATION_DATABASE_READINESS_TIMEOUT_SECONDS |
3 |
Maximum readiness database check duration |
FOUNDATION_MIGRATION_ADVISORY_LOCK_TIMEOUT_SECONDS |
900 |
Maximum wait to serialize migration runners |
FOUNDATION_MIGRATION_LOCK_TIMEOUT_SECONDS |
3 |
Maximum DDL lock wait |
FOUNDATION_MIGRATION_STATEMENT_TIMEOUT_SECONDS |
900 |
Maximum duration of a migration statement |
FOUNDATION_MIGRATION_IDLE_TRANSACTION_TIMEOUT_SECONDS |
30 |
Maximum idle time in a migration transaction |
FOUNDATION_LOG_FORMAT |
pretty |
Rich-backed pretty locally or json when deployed |
Database and Redis URLs are intentionally omitted from the table because they may contain credentials; use .env.example for their local forms and secret-backed deployment configuration for real environments.
Container Roles and Migrations
Build the shared image from the root Dockerfile:
make image-foundation-service
The image installs Debian's CA bundle, verifies it during build, and sets SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt for httpx2. Keep that setting unless a replacement path provides the complete deployment trust set.
The image defaults to FOUNDATION_AUTO_MIGRATE=true for all and control; PostgreSQL advisory locking serializes concurrent rollout replicas. Set it to false when a dedicated migration job owns schema changes. Configure the container port through FOUNDATION_PORT so the service and healthcheck use the same value. Startup behavior is fail-closed:
executionnever changes schema and only checks that all Alembic heads are applied;allandcontrolrunupgrade headwhen auto migration is enabled;- otherwise the process performs the same non-mutating head check;
- a failed migration or compatibility check prevents the service from starting.
A dedicated singleton migration job with auto migration disabled on normal replicas is preferred for distributed production deployments.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file converge_foundation_service-0.0.2.tar.gz.
File metadata
- Download URL: converge_foundation_service-0.0.2.tar.gz
- Upload date:
- Size: 16.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9112a1f047eb47f9d39fe0a28cb3c99df9d026d7f86218cd4de3513984375d40
|
|
| MD5 |
d24313a342b5412b2d520c255ac3d8ff
|
|
| BLAKE2b-256 |
e73881ea4f650a92bc6b879f939e62a6379067ea13fd01569485d5f002e8ae18
|
File details
Details for the file converge_foundation_service-0.0.2-py3-none-any.whl.
File metadata
- Download URL: converge_foundation_service-0.0.2-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd571d8c4f90480db1b2e86baf292a2c9828b33fe90eec53070370fd8f778853
|
|
| MD5 |
f4c8723907170c7a6598e603296ee085
|
|
| BLAKE2b-256 |
15824cb0235af6b00b882f9d284ed34830d25a1f025ba0ef9d7820aef7df77ca
|