Repository navigation
feat: start a root chat as an agent type through the API - #185
Conversation
ResolveRootAgent resolves an agent type for a new root chat the way spawn_agent does, from the built-in general and explore types and the owner's personal, organization and project definitions. Workspace definitions are not pinned when a chat is created, so they are refused. CreateChat takes the result in CreateOptions.RootAgent. It appends the definition's prompt, sets the base type's mode, drops the orchestration guidance when the type cannot spawn, and stores a depth 0 chat_subagents row with the definition's tool policy in the insert transaction. customAgentToolPolicyOfChat now loads the policy for any chat with a row, so the policy holds for such a root from its first turn. The depth 0 row counts toward no subagent limit: every count selects children by parent_chat_id or root_chat_id.
POST /chats takes agent_type, which starts the chat as general, explore,
or a personal, organization or project agent definition, behind the
fork-agent-definitions experiment. The definition's model and reasoning
effort apply unless the request sets model_config_id or reasoning_effort.
Unknown, unreadable and workspace-only types fail with 400, and so does
agent_type without the experiment.
The chat list, GET /chats/{chat} and the created watch event report the
root's agent_type from its chat_subagents row. Roots without a row are
unchanged.
|
@codex review
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 245cf85b14
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Root turns now read their tool policy with forkdb.From when fork-agent-definitions is on, so a database.Store wrapper that a turn runs through must forward ForkUnwrap and ForkWrap like dbmetrics does. Without them TestProcessChatPanicRecovery failed its turn before the first model call.
…ge-1b-root-agent-type-api
buildTurnEnvironment decided whether to add the ACP subagent guidance from the tools before the custom agent policy filtered them, so a root or child whose policy drops acp_spawn_agent still got the guidance. It now checks the tools that the policy keeps. CreateChat also refuses a RootAgent for a chat with a parent, so a child cannot get a depth 0 chat_subagents row.
…ge-1b-root-agent-type-api
…ge-1b-root-agent-type-api
|
@codex review
|
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…n its policy Show the ACP guidance only when the policy keeps every ACP tool, drop dynamic tool names whose tools the policy removed, and leave out the create_workspace advice for a detached root that cannot create a workspace.
…ge-1b-root-agent-type-api # Conflicts: # coderd/x/chatd/fork_root_agent.go
…ge-1b-root-agent-type-api # Conflicts: # coderd/x/chatd/fork_root_agent.go
…ge-1b-root-agent-type-api # Conflicts: # docs/fork/pstack-adapter.md
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c25a4529e4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…ge-1b-root-agent-type-api
|
@codex review
|
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…ge-1b-root-agent-type-api # Conflicts: # docs/fork/pstack-adapter.md
|
@codex review
|
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…oot-agent-type-api # Conflicts: # coderd/x/chatd/fork_root_agent.go # docs/fork/pstack-adapter.md
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c5fd6542bb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review
|
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Merged as a squash of head
|
Part of #187 (U1, start a chat as an agent). Stacked on #184, which adds the chatd side; review only the commits after the merges of #184.
Behind the
fork-agent-definitionsexperiment,POST /api/v2/chatstakes an optionalagent_type:general,explore, or a personal, organization or project definition thatspawn_agentwould offer the chat, by the same bare or qualified name.model_config_idorreasoning_effort. A definition model replaces the chat's model and drops the replaced model's default effort. A chat created without a message keeps the definition's effort for its first turn: it is stored on the last starting system message, which setschats.last_reasoning_effortthrough the existingInsertChatMessagesupdate (no new query). When the organization has no usable default model, a request withagent_typestill starts on the definition's model; it gets the usual 400 only if the definition has no model either.Invalid agent_type.with the reason indetail): unknown names (the detail lists the valid types), definitions the owner can't read, workspace definitions (Coder reads a chat's workspace definitions only after its workspace agent connects),computer_use, andagent_typewithout the experiment.GET /chats/{chat}and thecreatedwatch event report a root'sagent_typefrom itschat_subagentsrow.GetChatSubagentTypesByChatIDsnow includes rows of roots. Roots without a row are unchanged, and child chats report their type as before.agent_typeon create, and its source line references follow the lines feat(coderd/x/chatd): start a root chat as an agent type #184 and this PR shift. The generated apidoc, API reference andtypesGenerated.tsadd the field.Tests:
TestForkCreateChatAgentTypecreates roots as a personal definition (checks the stored row and tool policy, the definition's model andhigheffort on the first message, the prompt marker,agent_typeon get and list, no children), with an explicit model (the request's model wins), asexplore, without a type (no row), and without content (the idle chat keeps efforthigh). The list shows every one as a root with no children. Table cases cover unknown, workspace-qualified, workspace-only,computer_use, and an organization definition not shared with a member.TestForkCreateChatAgentTypeExperimentOffchecks the 400 without the experiment. A deliberate break (the list query back to children only) fails the test.Checks: targeted
./coderd/tests (TestForkCreateChatAgentType|TestForkChatAgentType|TestPostChats|TestListAgents) and the chatd tests from #184 pass on this head, plusgo vet,go buildandgofmt.forkdb/generate.shoutput matches the hand-spliced query code.