Skip to content

feat: start a root chat as an agent type through the API - #185

Merged
ibetitsmike merged 27 commits into
mainfrom
mike/agent-usage-1b-root-agent-type-api
Nov 11, 2026
Merged

ibetitsmike merged 27 commits into
mainfrom
mike/agent-usage-1b-root-agent-type-api

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

Xum opened this PR on behalf of @ibetitsmike.

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-definitions experiment, POST /api/v2/chats takes an optional agent_type:

  • Values: general, explore, or a personal, organization or project definition that spawn_agent would offer the chat, by the same bare or qualified name.
  • Model and effort: the definition's model and reasoning effort apply unless the request sets model_config_id or reasoning_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 sets chats.last_reasoning_effort through the existing InsertChatMessages update (no new query). When the organization has no usable default model, a request with agent_type still starts on the definition's model; it gets the usual 400 only if the definition has no model either.
  • Errors (400, Invalid agent_type. with the reason in detail): 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, and agent_type without the experiment.
  • Read side: the chat list, GET /chats/{chat} and the created watch event report a root's agent_type from its chat_subagents row. GetChatSubagentTypesByChatIDs now includes rows of roots. Roots without a row are unchanged, and child chats report their type as before.
  • Docs: the pstack adapter doc describes agent_type on 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 and typesGenerated.ts add the field.

Tests: TestForkCreateChatAgentType creates roots as a personal definition (checks the stored row and tool policy, the definition's model and high effort on the first message, the prompt marker, agent_type on get and list, no children), with an explicit model (the request's model wins), as explore, without a type (no row), and without content (the idle chat keeps effort high). 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. TestForkCreateChatAgentTypeExperimentOff checks 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, plus go vet, go build and gofmt. forkdb/generate.sh output matches the hand-spliced query code.

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.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum commented on behalf of @ibetitsmike.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T11:17:54.262170Z 5608b94 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread coderd/fork_chat_root_agent.go Resolved
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.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum commented on behalf of @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 183af8f2a2

ℹ️ 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.
…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
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum commented on behalf of @ibetitsmike.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread coderd/exp_chats.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum commented on behalf of @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 96dc1c9a10

ℹ️ 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".

@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum commented on behalf of @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: f97f6cecdb

ℹ️ 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".

Base automatically changed from mike/agent-usage-1-root-agent-type to main November 11, 2026 10:48
@ibetitsmike
ibetitsmike marked this pull request as ready for review November 11, 2026 11:02

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread coderd/exp_chats.go Resolved
Comment thread coderd/fork_chat_root_agent.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum commented on behalf of @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 5608b94961

ℹ️ 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".

@ibetitsmike
ibetitsmike merged commit 5ec99fb into main Nov 11, 2026
9 checks passed
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum merged this PR on behalf of @ibetitsmike.

Merged as a squash of head 5608b94961 on main 5e28d8f266.

  • CI: fork-ci run 43010114727 green on the exact head, which contains main 5e28d8f266.
  • Codex: receipt 6794391907 on 5608b94961 ("Didn't find any major issues"). 0 unresolved threads.
  • UAT: covered by the w10-agents stack run (8/8) on the f080e0a769 superset. Per file, this PR's non-docs code diff is identical to the verified f97f6cecdb, apart from the Chat.agent_type comment and its generated copies. The pstack adapter changes are the source-line re-pins that feat(coderd/x/chatd): start a root chat as an agent type #184 made necessary.

@ibetitsmike
ibetitsmike deleted the mike/agent-usage-1b-root-agent-type-api branch November 11, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant