Skip to content
refs

feat(agents): hosted agents that answer @handle mentions on pull requests

Aman Kumarcommitted Dec 3, 2026a162787parent 798ae52

- 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

  1. Chosen
  2. Each person stores a key, and the run uses the key of the person who mentions the agent

Touches

  • agents.ts
  • 0036_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

  1. Chosen
  2. A separate master key for agent keys

Touches

  • agents.ts
  • models.ts
18 files changed · +695 −9
apps/backend/agent-runs.ts+261 −0
apps/backend/agents.ts+164 −0
apps/backend/auth.ts+1 −1
apps/backend/contract/handles.ts+15 −0
apps/backend/contract/index.ts+1 −0
apps/backend/contract/views.ts+15 −0
apps/backend/handles/pull.ts+4 −2
apps/backend/handles/refs.ts+6 −0
apps/backend/handles/repo.ts+6 −0
apps/backend/index.ts+1 −0
apps/backend/mentions.ts+7 −1
apps/backend/models.ts+79 −0
apps/backend/test/agent-runs.test.ts+34 −0
apps/backend/test/hosted-agents.test.ts+73 −0
migrations/0036_hosted_agents.sql+17 −0
worker-configuration.d.ts+0 −0

File too large to display

workers/main.ts+4 −3
wrangler.jsonc+7 −2