Skip to content

Decision: should the chat API choose, follow or show the project agent a chat answers as? #5380

Open

Description

@yannickmonney

Summary

Since #5361 and #5364 (train 8d37319dc), a chat filed in a project answers as one of the project's agents when its owner chose one in the app, and a new chat in the app starts with the project's default chat agent. The REST chat API stayed as it was. It creates every chat with the built-in assistant and refuses an agent in the body, and its reads never say which agent answered. A send over the API to a chat whose owner chose an agent in the app answers as that agent. #5361 left these out ("Not part of this issue"); the API reference says so since 2472e545c. Part of epic #5371.

What the repository says today (train a32fb1586)

  • Create: the body is strict, with title only. A project chat is created with chatAgentId: null, so it answers as the assistant whatever the project's default is (services/platform/backend/rest/v1-threads.ts:591-628).
  • Send: every turn reads the conversation's agent from its root, sends over the API included (services/platform/backend/domains/chat/service.ts:163-169).
  • Reads: a message carries model and providerSlug, never the agent (v1-threads.ts:235-261). The integration lane refuses agentSlug, agentId and projectAgentId on create, and checks that a thread read has no agentSlug (services/platform/backend/rest/project-agents-check.ts:458-485).
  • Rules: CHAT-R14 (services/platform/backend/domains/chat/spec.md:197-207), CHAT-R41 to CHAT-R43, PROJ-R26.
  • Docs: docs/en/develop/api-reference.md (the turn paragraph and "Respect thread scope and access"), and the OpenAPI descriptions in services/platform/scripts/openapi/spec.ts.

What it means for an integration

  • A script that creates a chat in a project gets the assistant. A person who starts a chat there in the app gets the project's default agent.
  • A script that continues a chat a person set up in the app gets that agent's replies, and the API does not tell it so.

Constraints

  • A field added to a read, or accepted on create, moves the contract fingerprint and so needs a new contract version (services/platform/scripts/openapi/fingerprint.ts).
  • CHAT-R43: only a chat's owner chooses who answers, and only among the project's own agents.
  • CHAT-R41: an agent's runtime, connectors, platform tools, secrets and repository access never reach a chat, whatever the door.

Options (no preference)

  1. Keep it as it is (documented).
  2. Show it: add the agent (id and name) to thread and message reads.
  3. Follow the project: a project chat the API creates starts with the project's default chat agent, as in the app.
  4. Choose it: accept an agentId on create, and a way to change it, checked as CHAT-R43 checks the app.

Questions

  • Do integrations want the agent's instructions, or is the assistant the stable behavior scripts rely on?
  • Which API key kinds (personal, team, project, organization) may choose an agent, and whose chat is it then?

Related

Activity

  1. added
    priority: low
    needs discussion
    improvement
    service: platform
    on Nov 5, 2026
  2. yannickmonney commented on Nov 14, 2026

    @yannickmonney
    ContributorAuthor

    Decision

    The chat API reaches full parity with the app in three steps: show who answers, then let integrations choose it, then follow the project's default. Option 1 (keep it as it is) is rejected.

    Rule

    • Show: thread reads carry agent: {id, name} | null, the agent the conversation answers as now, resolved from its root. A deleted agent or a moved chat reads correctly. Replies a project agent wrote carry agent: {id, name} from the reply's own record (its name at the time). The project read gains defaultChatAgent: {id, name} | null, so an integration can see what a new chat starts with.
    • Choose: POST …/threads and PATCH …/threads/{id} accept an optional agentId: string | null (null = the built-in assistant). It goes through the domain's existing checks (createThread, setConversationAgent on the root), so CHAT-R43 holds unchanged: only one of the URL project's own agents is allowed. The standard agent, another project's agent, an unknown id, or any agent on an org-level chat gets 400 CHAT_AGENT_INVALID and nothing changes. setConversationAgent also refuses, inside its own transaction, an archived chat or project (CHAT-R16) and a sandbox chat (409 CHAT_THREAD_NOT_DIRECT). Changing the agent mid-turn is allowed: the running turn keeps its agent, and every later turn, a queued send included, answers as the new one. agentSlug and projectAgentId stay refused.
    • Follow: a project chat created without agentId starts with the project's default chat agent (PROJ-R26 / CHAT-R42), as in the app. agentId: null pins the assistant. This changes what an unchanged request does, so it is a major contract bump, shipped in a release after "choose", whose notes announce it.
    • CHAT-R41 is untouched: an agent's runtime, connectors, platform tools, secrets and repository access never reach a chat, through any door. The settings and proposal tools stay app-only.

    Answers

    • Agent instructions or a stable assistant? The assistant was never a guarantee: a chat whose owner chose an agent in the app already answers API sends as that agent, without saying so. The project's default is its editors' choice, so integrations get it by default, can see it on the project read, and send agentId: null for the plain assistant. Only id and name are exposed.
    • Which key kinds may choose, and whose chat is it? Every key kind that may create the chat: member/personal, team, project and organization keys. A REST chat always belongs to the key's acting identity and every REST read and write is filtered by owner, so the caller is always the owner. A member's key makes the member's own chat. A team, project or org key makes a chat owned by the key's identity, reachable only through that key; a project key reaches its project alone, and spending is booked under the key, the agent and the project. There is no act-as. Another user's chat stays 404.
    • Contract version? "Show" and "choose" are minor bumps. "Follow" is major, as 2.0.0 and 3.0.0 were for changed meanings.
    • Archived, sandbox or busy chats? Archived chats or projects are refused, sandbox chats get 409, and a running turn keeps its agent.

    Rationale
    Today the API can answer as an agent it never names and cannot control. That contradicts the premise that an API chat is the same chat as in the app. Every piece needed already exists: the effective-agent resolver, the per-reply agent record, the project-agents roster, and CHAT_AGENT_INVALID. The new fences go into the domain function, so nothing is duplicated and no route check can race an archive. Shipping "choose" before "follow" lets integrations pin the assistant before the default changes.

    Implementation units (base: main)

    1. REST reads show who answers (M): agent on thread and message reads, defaultChatAgent on the project read, OpenAPI, minor bump, CHAT-R14/PROJ-R26 text, project-agents-check, en/de/fr docs.
    2. Create/PATCH accept agentId (M, after 1): createThread/setConversationAgent with the archived, sandbox and turn rules in the domain transaction; tests for own, foreign, standard, unknown and org-level agents, null, PATCH on root, mid-turn, 404 for another user's chat, archived/sandbox refusals, and member/team/project keys; minor bump, docs, and notes announcing step 3.
    3. Project chats follow the default (S, after 2, in a later release): drop the forced chatAgentId: null, major bump, retire the CHAT-R14 exception, update docs and notes.
  3. added
    agent-ready
    and removed
    needs discussion
    on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyimprovementpriority: lowservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions