add-python-module
Add an endpoint, module or setting to the Python AI service (apps/ai) and call it from the API. Use when the user wants new AI, model, retrieval or data-science functionality, or anything written in P
SKILL.md.claude/skills/add-python-module/SKILL.md
GitHubAdd to the Python service
apps/ai is FastAPI plus a BullMQ worker; only apps/api calls it, through the generated
client in packages/ai-client. docs/python-services.md describes the service.
- Models. Request and response models in
apps/ai/app/schemas.py, every field constrained (Field(min_length=…, max_length=…),Literal[...]). They becomeapps/ai/openapi.jsonand the TypeScript types. - Logic. A module in
apps/ai/app/(likesummaries.pyordocuments.py). Data access only throughtenant(org_id)fromapp/db/session.py; models through Pydantic AI, so budgets andAI_MODELapply. - Route. In
apps/ai/app/main.py, withoperation_id="<name>"(the generated client's function name) andCallerDep(the API's signed token). Errors areAppError("<CODE>", status, params)with a code frompackages/contracts/src/errors.ts. Blocking work in a plaindef; I/O inasync def. - Settings. A field in
apps/ai/app/settings.pywithalias="<ENV_NAME>", and the variable in.env.exampleanddocs/environment.md. bun run gen: regeneratesapps/ai/openapi.jsonandpackages/ai-client/src/generated/.- Call it. Add a method to
createAiClientinpackages/ai-client/src/index.ts(wraps the generated function withunwrap), then use it fromapps/api/src/modules/ai/ai.service.tsbehind a contract procedure (add-feature skill). Keep the API's input limits equal to the Pydantic ones; add the pair toapps/api/src/modules/ai/limits.test.ts. - Tests. Pure tests in
apps/ai/tests/test_units.py(run bybun run test); anything needing Postgres or Redis inapps/ai/tests/test_service.py(pytestmark = pytest.mark.integration, run bybun run test:integration).bun run lintruns ruff andbun run check-typesruns basedpyright on it.
Background work for the service: the add-job skill (Python section).
Finish with the verify skill, then the python-reviewer agent, the security-reviewer
agent for a new route (a new entry point), and the reviewer agent for the API side.