[Story-751] Add agents schema foundation

Story 751Epic 749๐Ÿ”— Chain of CustodyAgent Platform6 files ยท +792/โˆ’2

PR #186 ยท pramaan-io/pramaan-functions ยท merged 2026-05-20

How it flows

sequenceDiagram
  autonumber
  participant mig as Migration 0044
  participant lib as Shared lib
  participant set as Settings
  participant tst as Tests
  mig->>lib: schema + RLS + partitions + seeds
  set->>lib: agents bucket name
  lib->>lib: expose SQLAlchemy Core metadata
  lib->>lib: offload_if_large โ†’ inline or S3
  lib->>lib: fetch_offloaded โ†’ return
  tst-->>lib: verify round-trip

8e7a6b5c4d3f_0044_agents_schema_foundation.py ยท +433 โ€” new methods

Methodin โ†’ outwhat it does
_create_monthly_partitions(table_name, timestamp_column) โ†’ None
_drop_monthly_partitions(table_name) โ†’ None
_enable_firm_rls(table_name) โ†’ None

What changed, file by file

Alembic migration that creates the agents schema with foundation tables, RLS policies, monthly partitions, runtime grants, and MatterChatAgent tool registry seeds (per PR body).

new methodsignature
_create_monthly_partitions(table_name, timestamp_column) โ†’ None
_drop_monthly_partitions(table_name) โ†’ None
_enable_firm_rls(table_name) โ†’ None
_enable_registry_rls() โ†’ None
_disable_rls(table_name) โ†’ None
upgrade() โ†’ None
downgrade() โ†’ None
New fields: revision : strdown_revision : str | Sequence[str] | Nonebranch_labels : str | Sequence[str] | Nonedepends_on : str | Sequence[str] | None

Shared helper module with offload_if_large and fetch_offloaded that decides between inline DB storage and S3 bucket offload for agent payloads (per PR body).

new methodsignature
_s3_client(settings) โ†’ Any
_object_key(firm_id, run_id, kind, sha256, created_at) โ†’ str
offload_if_large(content, threshold_bytes, firm_id, run_id, kind, settings, s3_client) โ†’ tuple[Stor
fetch_offloaded(storage_mode, s3_key, inline_content, settings, s3_client) โ†’ str

Settings module that adds the agents bucket name field and a resolver for the pramaan-agents-{env} S3 bucket (per PR body).

new methodsignature
resolved_agents_bucket_name() โ†’ str
New fields: agents_bucket_name : str | None

Kya fail ho sakta hai

targeted ruff clean
targeted mypy clean
new s3_offload unit tests pass
import smoke passes
pre-existing DB state not this PR's scope
missing role / fixtures not introduced here

Files changed (6)

Fileยฑ
alembic/env.py+4 โˆ’2
alembic/versions/8e7a6b5c4d3f_0044_agents_schema_foundation.py โ˜…+433
src/shared/agents_db_models.py โ˜…+112
src/shared/s3_offload.py โ˜…+114
src/shared/settings.py+12
tests/unit/shared/test_s3_offload.py+117