Repository navigation
Closed
Labels
complexity-lowComplexity: low (board points 1-3)priority-p1Critical pathtype-featureNew functionality
Description
Summary
When a new agent is created, automatically assign it to a subscription using round-robin distribution across all registered subscriptions. This removes the manual step of assigning subscriptions after agent creation.
Current Behavior
Agents are created with ANTHROPIC_API_KEY (platform API key). Subscriptions must be manually assigned afterwards via Settings UI or MCP tool.
Desired Behavior
On agent creation:
- Query all registered subscriptions
- Pick the one with fewest assigned agents (round-robin). On tie, pick first alphabetically.
- Set
CLAUDE_CODE_OAUTH_TOKENenv var on the container (instead ofANTHROPIC_API_KEY) - Persist the assignment in
agent_ownership.subscription_id - If no subscriptions exist, fall back to current behavior (platform API key)
System agents (trinity-system) are excluded from auto-assignment.
Implementation Notes
Files to modify
src/backend/db/subscriptions.py— Addget_least_used_subscription()method (SQL: LEFT JOIN + GROUP BY + ORDER BY count ASC, name ASC)src/backend/database.py— Expose via delegatesrc/backend/services/agent_service/crud.py— Look up subscription before buildingenv_vars(~line 280), setCLAUDE_CODE_OAUTH_TOKENinstead ofANTHROPIC_API_KEY, then persist assignment afterregister_agent_owner()
Key constraint
The subscription lookup and token injection must happen before container creation (line 337+) since env vars are set at container creation time. The DB assignment must happen after register_agent_owner() (line 489) since it updates the agent_ownership row.
Edge cases
- No subscriptions registered → skip, use platform API key
- Token decryption fails → fall back to platform API key, log warning
- All subscriptions have equal agent count → pick first alphabetically
- Subscription deleted later → existing cascade-clear behavior handles this
Verification
- Register a subscription in Settings
- Create a new agent → auth status should show
"subscription" docker exec agent-{name} env | grep CLAUDE_CODE_OAUTH_TOKEN→ setdocker exec agent-{name} env | grep ANTHROPIC_API_KEY→ not set- Register second subscription, create 2 more agents → verify round-robin
- Create with no subscriptions → falls back to API key
Metadata
Metadata
Assignees
Labels
complexity-lowComplexity: low (board points 1-3)priority-p1Critical pathtype-featureNew functionality
Activity
feat: Auto-assign subscription to new agents via round-robin (Ability…
docs: Add auto-assign subscription flow to feature docs (Abilityai#74)
feat: Auto-assign subscription to new agents (round-robin) (Abilityai#74
merge: integrate upstream/main into feature branch
merge: resolve changelog conflict with upstream/main
merge: Resolve conflicts with upstream/main — changelog and feature-f…
merge: Resolve conflicts with upstream/main (docs only)
fix(subscriptions): auto-switch ranks alternatives by cached headroom…
fix(subscriptions): registering a subscription or deleting the instan…
Release: v0.9.5 (#2872)
feat(evaluations): the run's judge and hand-off on the execution page…
feat(evaluations): the run's judge and hand-off on the execution page…
feat(evaluations): the run's judge and hand-off on the execution page…
feat(evaluations): the run's judge and hand-off on the execution page…
feat(evaluations): the run's judge and hand-off on the execution page…
feat(evaluations): the run's judge and hand-off on the execution page…
feat(evaluations): the run's judge and hand-off on the execution page…
feat(evaluations): the run's judge and hand-off on the execution page…
feat(evaluations): the run's judge and hand-off on the execution page…