Skip to content

feat: add experimental agents support#22290

Merged
johnstcn merged 150 commits intomainfrom
agents
Feb 27, 2026
Merged

feat: add experimental agents support#22290
johnstcn merged 150 commits intomainfrom
agents

Conversation

@kylecarbs
Copy link
Member

@kylecarbs kylecarbs commented Feb 24, 2026

feat: add AI chat system with agent tools and chat UI

Introduce the chatd subsystem and Agents UI for AI-powered chat
within Coder workspaces.

  • Add chatd package with chat loop, message compaction, prompt
    management, and LLM provider integration (OpenAI, Anthropic)
  • Add agent tools: create workspace, list/read templates, read/write/
    edit files, execute commands
  • Add chat API endpoints with streaming, message editing, and
    durable reconnection
  • Add database schema and migrations for chats, chat messages, chat
    providers, and chat model configs
  • Add RBAC policies and dbauthz enforcement for chat resources
  • Add Agents UI pages with conversation timeline, queued messages
    list, diff viewer, and model configuration panel
  • Add comprehensive test coverage including coderd integration tests,
    chatd unit tests, and Storybook stories
  • Gate feature behind experiments flag

This commit adds the database schema and backend API infrastructure for the
AI Agents (Chats) feature. The feature allows users to interact with AI
coding agents that run in their workspaces.

Database Schema:
- Added 'chats' table with status tracking, workspace association, and
  multi-replica locking fields (worker_id, started_at)
- Added 'chat_messages' table for conversation history storage
- Added 'chat_status' enum for tracking chat processing state

Backend API (coderd/chats.go):
- GET /api/v2/chats - List user's chats
- POST /api/v2/chats - Create new chat
- GET /api/v2/chats/{chat} - Get chat with messages
- DELETE /api/v2/chats/{chat} - Delete chat
- POST /api/v2/chats/{chat}/messages - Add message to chat

Multi-Replica Safety (Milestone 2):
- AcquireChat: Uses FOR UPDATE SKIP LOCKED to safely acquire pending chats
- UpdateChatStatus: Update status with worker tracking
- GetStaleChats: Find abandoned chats for recovery

RBAC:
- Added 'chat' resource type with create/read/update/delete actions
- Chat owners have full control over their chats

The frontend components and chat processing loop will be added in
subsequent commits.
This commit completes the full implementation of the AI Agents page feature,
which allows users to interact with AI coding agents in their workspaces.

Milestone 3 - Chat Processing Loop:
- Added coderd/chats/processor.go with background chat processor
- Polls for pending chats using FOR UPDATE SKIP LOCKED
- Recovers stale chats on startup
- Integrated into coderd startup

Milestone 4 - Frontend Chat UI:
- Added AgentsPage at /agents with sidebar and chat area
- AgentsSidebar component for listing chats
- AgentDetail component for viewing chat messages
- Added API query helpers in site/src/api/queries/chats.ts
- Added TypeScript types for Chat, ChatMessage, etc.
- Added navigation link to navbar

Milestone 5 - Git State Tracking:
- Added chat_git_changes table via migration 000415
- API endpoint GET /chats/{chat}/git-changes
- SDK types and client methods for git changes

Milestone 6 - Polish & Testing:
- FilesChangedPanel component for showing file changes
- Updated AgentDetail with sidebar layout for files
- Added coderd/chats_test.go with comprehensive test suite

All backend and frontend components build successfully.
ChatMessage.Content and ChatMessage.ToolCalls are nullable JSONB columns.
Using json.RawMessage caused 'invalid input syntax for type json' errors
when inserting NULL values. Switch to pqtype.NullRawMessage which properly
handles SQL NULL for JSONB columns.
Add authorization test cases for all chat database methods:
- AcquireChat, GetStaleChats (system-level ResourceChat assertions)
- GetChatByID, GetChatsByOwnerID (fetch/fetchWithPostFilter)
- GetChatMessageByID, GetChatMessagesByChatID, GetChatGitChangesByChatID
  (parent chat read authorization)
- InsertChat (insert with owner)
- InsertChatMessage, InsertChatGitChange (parent chat update)
- UpdateChatByID, UpdateChatStatus (fetch + update)
- DeleteChatByID, DeleteChatMessagesByChatID (fetch + delete)
- DeleteChatGitChangesByChatID (fetch + update)
querier.go was accidentally deleted from the working tree. Restored it
from git (it contains the sqlcQuerier interface needed by db.go).

Removed duplicate ChatGitChange struct from chats.go since it is already
defined in models.go.
The project uses react-router v7, which exports directly from
"react-router". The "react-router-dom" package is not installed.
The project uses dayjs, not date-fns. Replace formatDistanceToNow
with the existing relativeTime helper from utils/time.
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conditional approval pending some final code cleanup and last-minute smoke test

@hugodutka hugodutka force-pushed the agents branch 2 times, most recently from 47edc60 to 996f17c Compare February 27, 2026 10:41
@kylecarbs kylecarbs marked this pull request as ready for review February 27, 2026 16:12
@kylecarbs kylecarbs requested a review from Emyrk as a code owner February 27, 2026 16:12
@coder-tasks
Copy link
Contributor

coder-tasks bot commented Feb 27, 2026

Documentation Check

New Documentation Needed

  • docs/ai-coder/agents.md (or similar path) — Document the new built-in AI chat/Agents feature: how to enable via --experiments=agents, how to configure AI providers (Anthropic, OpenAI, Azure, AWS Bedrock, Google, OpenAI Compatible, OpenRouter, Vercel AI Gateway) through the admin panel, and how to use the /agents chat UI including sub-agent capabilities and context compression.
  • docs/ai-coder/agents.md — The ChatModelAdminPanel UI (providers, models, behavior tabs) needs admin-facing documentation explaining how to configure providers and models per deployment.
  • docs/manifest.json — Add the new Agents page to the navigation structure once it's created.

Notes

  • Auto-generated CLI docs (docs/reference/cli/server.md) include the --experiments flag which covers enabling agents. ✅
  • The new /api/v2/chats/* endpoints still have no Swagger/OpenAPI annotations, so they won't appear in the auto-generated API reference. Annotations should be added before GA.
  • The feature is gated behind ExperimentAgents (not in ExperimentsSafe yet), so documentation may be intentionally deferred — but should land before the experiment is promoted.
  • PR scope has grown significantly since last review: sub-agent support, context compression, external auth integration, and a full ChatModelAdminPanel admin configuration UI were added.

Automated review via Coder Tasks

@johnstcn johnstcn merged commit edee917 into main Feb 27, 2026
34 checks passed
@johnstcn johnstcn deleted the agents branch February 27, 2026 16:51
@github-actions github-actions bot locked and limited conversation to collaborators Feb 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants