feat(agents): hosted agents that answer @handle mentions on pull requests
- A person mentions @handle on a pull request. refs starts a run on a queue that reads the diff, the files and the code map, and posts one comment. - @reviewer is built in. Namespaces and repositories add their own agents, and a repository agent replaces a shared or built-in agent with the same handle. - An agent runs GLM-5.3 on Workers AI, or a model from Anthropic, OpenAI or OpenRouter through AI Gateway with the agent's own API key.
3 decisions
A hosted agent that uses a provider model pays with the API key stored on the agent, not with the key of the person who mentions it.
Why
- The owner chose this when asked
- An admin sets up the agent once, and every member can use it without a key of their own
If this changes later
A change moves keys from agents to people, and every admin must ask members to add their own keys.
Paths considered
- Chosen
- Each person stores a key, and the run uses the key of the person who mentions the agent
Touches
agents.ts0036_hosted_agents.sql
A repository agent replaces a namespace agent or a built-in agent that has the same handle, in that repository only.
Why
- Admins can change @reviewer for one repository without changing it for the whole namespace
- One handle always means one agent in a repository, so a mention is never ambiguous
If this changes later
Repositories that customized an agent lose their copy, and their admins must set it up again.
Touches
agents.ts
refs seals agent API keys with the CI secrets master key, CI_SECRETS_KEY, scoped to each agent.
Why
- The server already has this key and envelope encryption for CI secrets
- The scope is part of the ciphertext, so a sealed key copied to another agent does not open
If this changes later
A new master key means every admin must save each agent key again.
Paths considered
- Chosen
- A separate master key for agent keys
Touches
agents.tsmodels.ts