Repository navigation
feat(coderd/x/chatd): start a root chat as an agent type - #184
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.
|
@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: de975cba0d
ℹ️ 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.
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.
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 011af9df4d
ℹ️ 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
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 011af9df4d
ℹ️ 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".
…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.
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8e10deccd1
ℹ️ 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. 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". |
|
@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". |
Merged as a squash of head
|
Part of #187 (U1, start a chat as an agent). First of two stacked PRs; the API comes in the next one.
spawn_agentcan start a child as a built-in type or a custom agent definition, but a root chat always ran as the default agent. Behind thefork-agent-definitionsexperiment, chatd can now create a root chat as an agent type:ResolveRootAgentresolves the type the wayspawn_agentdoes, fromgeneral,exploreand the owner's personal, organization and project definitions, with the same bare and qualified names. The type match, the tier merge and the reasoning-effort check are factored out offork_agent_definitions.go, so spawn and the root share them. Workspace definitions are refused, because a chat reads them only after its workspace agent connects, which is after the chat is created. Other built-in types (computer_use) are refused too.CreateOptions.RootAgentappends the definition's body after the chat's system prompt, sets the explore mode for an explore base type, and stores a depth 0chat_subagentsrow with the definition's tool policy in the insert transaction.customAgentToolPolicyOfChatloads the policy for any chat with a row, so it holds for such a root from its first turn. With the experiment on, each root turn makes one indexed lookup.explore,readonly: true, or atools/disallowed_toolslist without the spawn tools) drops the subagent guidance block. It uses the same rule as spawn:keepsOrchestrationToolsis factored out ofchildGetsOrchestrationPrompt.list_templates/create_workspace) gets only the base detached-workspace text, and an attached root whose policy removesexecute,read_fileorwrite_filegets a limited attached text that points at the tools it has.explore-base definition whosedisallowed_toolsremoved all five Explore tools (and had no MCP tools) could callwrite_fileandedit_files. Explore roots now drop blocked tools the same way (the Explore filter afterfilterToolsForTurninturn_environment.go) and are left with no tools. Upstream has no API that creates Explore roots, so only fork root agents are affected.CreateChatrefusesRootAgenttogether withParentChatID, so a child never gets a depth 0 row.<acp-subagents>prompt now follows the tools that the custom agent policy keeps, for roots and children alike.parent_chat_idorroot_chat_id(CountActiveSubagentsForCapacityrequiresparent_chat_id IS NOT NULL), the chat list returns roots byparent_chat_id IS NULLand children by parent, and the row's only cascade is its ownON DELETE CASCADEonchat_id.Tests:
TestForkRootAgentcreates a root as a personalreadonly: truedefinition and checks the prompt (definition body appended, no orchestration block, the rest of the default prompt kept) and the turn's tools (executekept,write_fileandspawn_agentremoved). With a depth limit of 1 and one live subagent per family, a spawn from that root still gets depth 1, the root isn't counted as live, and the second spawn hits the limit. It also checks that a readonly root gets neitheracp_spawn_agentnor the ACP guidance, that a policy keepingacp_spawn_agentwithoutacp_wait_agentgets no ACP guidance, the tailored workspace texts, that a removed dynamic tool is in neitherenv.Toolsnorenv.DynamicToolNames, that an Explore-base root disallowing all five Explore tools has nowrite_file, and thatCreateChatrejects a root agent type for a child. Deliberate breaks (roots skip the policy, no orchestration strip) fail it. Two upstream turn test store wrappers inchatd_test.go(panicOnInTxDB,overrideReadFailStore) getForkUnwrap/ForkWrap, the dbmetrics pattern, because root turns now read fork queries andforkdb.Fromrefuses unknown wrappers. The API PR coversexploreand the error cases.Checks: targeted
./coderd/x/chatd/tests (TestForkRootAgent|TestCustomAgentToolPolicy|TestForkAgentDefinition|TestNestedSubagent|TestSubagent|TestSpawn) pass, plusgo vet,go buildandgofmt.coderd/x/chatd/ARCHITECTURE.mdgets threeTODO(ibetitsmike)notes for the root agent behavior, per the chatd docs rule. The pstack adapter doc and its source line references are updated in the next PR, which adds the API.