From 975bf136e3c0bdd25a9556561ecade8cd837d658 Mon Sep 17 00:00:00 2001 From: Badcuban <108198679+badcuban@users.noreply.github.com> Date: Mon, 23 Nov 2026 04:20:15 -0500 Subject: [PATCH] feat: agents can direct each other without per-message limits Agents could make 3 requests of each other in a room, and start 5 threads and send them 10 messages (10 and 20 in the lead chat), before they had to wait for the user to write. A lead agent directing a team for hours stopped at the first limit. The counts are gone, the way T3 Code works: room asks, reviews, hand-offs and invites, thread starts and sends, and lead chat passes are no longer counted or refused for volume. Stop, the approval settings, 5 threads per call, 3 side answers at once and the lead pass ceiling stay. The counter fields stay in the schema so older clients still decode a thread, and the `limit` outcome leaves the room and thread tool results. Tool descriptions, the lead role text, the app guide and the design docs say so. docs/design/agent-autonomy-no-limits.md also holds the plan for nesting threads to any depth and the review findings that keep it unbuilt for now. --- apps/server/src/guide/topics.ts | 6 +- apps/server/src/mcp/roomToolHandlers.test.ts | 8 -- apps/server/src/mcp/roomTools.ts | 5 +- .../server/src/mcp/threadToolHandlers.test.ts | 20 --- apps/server/src/mcp/threadToolHandlers.ts | 15 +-- apps/server/src/mcp/threadTools.ts | 8 +- .../orchestration/agentRequestDecisions.ts | 9 +- .../src/orchestration/childThreadDecisions.ts | 13 +- .../orchestration/decider.projectLead.test.ts | 1 - .../src/orchestration/decider.rooms.test.ts | 27 +--- apps/server/src/orchestration/decider.ts | 33 ++--- .../src/provider/agentContextBudget.json | 2 +- apps/web/src/store.test.ts | 9 +- docs/design/agent-autonomy-no-limits.md | 124 ++++++++++++++++++ docs/design/child-threads.md | 23 ++-- docs/design/lead-chat.md | 15 +-- docs/design/rooms-agent-invites.md | 6 +- docs/design/rooms-slice-2.md | 26 ++-- packages/contracts/src/orchestration.ts | 46 +++---- packages/shared/src/childThreads.test.ts | 52 +++----- packages/shared/src/childThreads.ts | 79 ++--------- packages/shared/src/projectLead.ts | 4 +- packages/shared/src/roomAgentRequests.ts | 57 ++------ 23 files changed, 247 insertions(+), 341 deletions(-) create mode 100644 docs/design/agent-autonomy-no-limits.md diff --git a/apps/server/src/guide/topics.ts b/apps/server/src/guide/topics.ts index 606b35fcf..ba7edec7c 100644 --- a/apps/server/src/guide/topics.ts +++ b/apps/server/src/guide/topics.ts @@ -91,7 +91,7 @@ Some agents lack a level; they run at the next safer one they have, and the comp You add and remove agents at the top of the model button's panel in the composer: one pill per agent, the picked one being who your next message goes to (typing @ and picking an agent does the same). The model and effort under the pills are that agent's. -Only one agent works at a time, in the same checkout. Agents in a room can ask each other a question on the side, ask for an independent review of the changes, or hand the next turn to another agent. Up to three agents can answer on the side at once, one answer each, so you can ask a second agent while the first is still answering, and an agent can ask two or three for a review of the same changes in one go. +Only one agent works at a time, in the same checkout. Agents in a room can ask each other a question on the side, ask for an independent review of the changes, or hand the next turn to another agent. Up to three agents can answer on the side at once, one answer each, so you can ask a second agent while the first is still answering, and an agent can ask two or three for a review of the same changes in one go. Agents can ask and hand off to each other as often as the work needs, without you writing in between; Stop ends the back and forth. Whether the thread's agent may bring in another model on its own is {place:threads.agentInvites}: Off, Ask me first (a card asks you each time), or Without asking. Bringing in another provider's model spends that provider's quota.`, }, @@ -113,7 +113,7 @@ Once a thread it started has finished, the agent can wrap it up itself (thread_w A thread that keeps working after its answer went back (a check-back woke it, or a reviewer it asked replied) doesn't wake the parent. Its latest reply is passed to the parent's agent at that agent's next turn, and the thread then wraps up by itself. A thread the agent stops with thread_stop wraps up by itself too. -{place:threads.agentThreads} decides this: Off, Ask me first (a card in the chat lists the threads and you decide), or Automatic. The same setting covers agents creating or changing scheduled tasks. An agent may start at most 5 threads and send 10 messages to them per message you send. +{place:threads.agentThreads} decides this: Off, Ask me first (a card in the chat lists the threads and you decide), or Automatic. The same setting covers agents creating or changing scheduled tasks. There's no limit on how many threads an agent starts or how many messages it sends them, so an agent can keep a team of threads going for hours without you writing. Stop on the parent stops its agent and its threads' answers coming back, but the threads keep working; "Stop N working threads" in the parent's menu stops them too. A started thread works in a worktree of its own; in a project without git it shares the project's folder. With {place:threads.agentThreadsShareWorktrees} on, an agent can instead put a thread in a checkout that already exists: its own, or that of a thread it started. The new thread sees the files as they are there, uncommitted changes included, which suits a reviewer for work another thread just finished. An agent can also move an idle thread into such a checkout with a message, and the thread keeps its conversation. The thread the checkout belongs to must not be working at that moment. No worktree or branch is made and the project's setup script does not run. The two threads then share one set of files, so only one should work at a time. The thread's row under the message box reads Shared worktree. This works on one computer only, and not for threads an outside agent starts. @@ -151,7 +151,7 @@ The lead's row sits at the top of the sidebar with a crown, says Lead where the The Threads tab in the right sidebar shows the project's threads on every computer you can see, grouped as Needs you, Ready for review, Working, Landing, Idle and Done. Open it from the sidebar's list of panels or its + menu, on any thread of the project. A thread you wrapped up goes under Done (for 7 days, closed until you open it) unless its pull request is still open, which keeps it under Ready for review or Landing. Ready for review says what the pull request waits on, as the Pull requests page does. Click a row to open the thread, or right-click it for the thread's menu. The top line counts what needs you and what's working, with a Lead chat link when you're on another thread. -The lead's agent is told its role at the start of every turn, and when you give it a goal. It may start 10 threads and send 20 messages to them per message you send, instead of 5 and 10. It needs {place:threads.agentThreads} to be on, and an agent that can't use the thread tools says so. General chats, a thread another thread still owns, and threads from another computer or an outside agent can't be the lead.`, +The lead's agent is told its role at the start of every turn, and when you give it a goal. It needs {place:threads.agentThreads} to be on, and an agent that can't use the thread tools says so. General chats, a thread another thread still owns, and threads from another computer or an outside agent can't be the lead.`, }, { id: "linking-computers", diff --git a/apps/server/src/mcp/roomToolHandlers.test.ts b/apps/server/src/mcp/roomToolHandlers.test.ts index eda0aa0c8..2b7d09ae2 100644 --- a/apps/server/src/mcp/roomToolHandlers.test.ts +++ b/apps/server/src/mcp/roomToolHandlers.test.ts @@ -326,13 +326,6 @@ describe("room_ask", () => { }), outcome: "busy", }, - // The agents used their requests. - { - thread: makeThread({ - agentRequests: { ...EMPTY_AGENT_REQUEST_STATE, requestsSinceUser: 3 }, - }), - outcome: "limit", - }, // The user pressed Stop. { thread: makeThread({ agentRequests: { ...EMPTY_AGENT_REQUEST_STATE, hold: true } }), @@ -846,7 +839,6 @@ describe("room_hand_off", () => { makeThread({ agentRequests: { ...EMPTY_AGENT_REQUEST_STATE, - requestsSinceUser: 1, open: [ { requestId: submit!.requestId, diff --git a/apps/server/src/mcp/roomTools.ts b/apps/server/src/mcp/roomTools.ts index 81908f3cb..35076bbc5 100644 --- a/apps/server/src/mcp/roomTools.ts +++ b/apps/server/src/mcp/roomTools.ts @@ -48,7 +48,6 @@ const RequestOutcome = Schema.Literals([ "stopped", "timeout", "busy", - "limit", "refused", ]); @@ -80,7 +79,7 @@ export const RoomAnswerResult = Schema.Struct({ export type RoomAnswerResult = typeof RoomAnswerResult.Type; export const RoomHandOffResult = Schema.Struct({ - outcome: Schema.Literals(["queued", "failed", "busy", "limit", "refused"]), + outcome: Schema.Literals(["queued", "failed", "busy", "refused"]), detail: Schema.optional(Schema.String), agent: Schema.optional(AgentLabel), requestId: Schema.optional(Schema.String), @@ -190,7 +189,7 @@ export const RoomInviteResult = Schema.Struct({ * (invites need no approval here). Either way its review comes back to you * as a message (into your turn if you are still working), if it runs. */ - outcome: Schema.Literals(["asked_user", "started", "failed", "busy", "limit", "refused"]), + outcome: Schema.Literals(["asked_user", "started", "failed", "busy", "refused"]), detail: Schema.optional(Schema.String), agent: Schema.optional(AgentLabel), /** The reasoning level it reviews at, when the invite named one. */ diff --git a/apps/server/src/mcp/threadToolHandlers.test.ts b/apps/server/src/mcp/threadToolHandlers.test.ts index 2ffe79a58..3979a1553 100644 --- a/apps/server/src/mcp/threadToolHandlers.test.ts +++ b/apps/server/src/mcp/threadToolHandlers.test.ts @@ -247,7 +247,6 @@ const makeTools = (options: { childRequests: { ...caller.childRequests, open: [...caller.childRequests.open, ...open], - startsSinceUser: caller.childRequests.startsSinceUser + open.length, }, }; } @@ -475,25 +474,6 @@ describe("thread_start", () => { }), ); - it.effect("refuses past the per-message limit, counting what was already asked", () => - Effect.gen(function* () { - const tools = yield* makeTools({ - caller: makeThread({ - childRequests: { ...EMPTY_CHILD_REQUEST_STATE, startsSinceUser: 4 }, - }), - }); - const result = yield* tools.handlers.thread_start(mainCaller(), { - threads: [ - { title: "One", prompt: "First." }, - { title: "Two", prompt: "Second." }, - ], - }); - - expect(result.outcome).toBe("limit"); - expect(tools.dispatched).toHaveLength(0); - }), - ); - it.effect("refuses agents billed per use or unable to plan when the caller plans", () => Effect.gen(function* () { const tools = yield* makeTools({ caller: makeThread({ interactionMode: "plan" }) }); diff --git a/apps/server/src/mcp/threadToolHandlers.ts b/apps/server/src/mcp/threadToolHandlers.ts index 3bb6e3e08..543a6a7d9 100644 --- a/apps/server/src/mcp/threadToolHandlers.ts +++ b/apps/server/src/mcp/threadToolHandlers.ts @@ -1029,7 +1029,6 @@ export function makeThreadToolHandlers(deps: ThreadToolDeps) { from: from(scope), callerTurnId, count: specs.length, - isLead: yield* isLeadThread(current), }); if (refusal !== null) { return ruleOutcome(refusal) satisfies ThreadStartResult; @@ -1340,7 +1339,6 @@ export function makeThreadToolHandlers(deps: ThreadToolDeps) { from: from(scope), callerTurnId, count: specs.length, - isLead: yield* isLeadThread(current), }); if (refusal !== null) { return ruleOutcome(refusal) satisfies ThreadStartResult; @@ -1856,16 +1854,11 @@ export function makeThreadToolHandlers(deps: ThreadToolDeps) { const refusal = childSendRefusal(caller, child ?? null, { from: from(scope), callerTurnId, - isLead: yield* isLeadThread(caller), }); if (refusal !== null) { return { outcome: - refusal.outcome === "not_allowed" - ? ("not_yours" as const) - : refusal.outcome === "limit" - ? ("limit" as const) - : ("refused" as const), + refusal.outcome === "not_allowed" ? ("not_yours" as const) : ("refused" as const), detail: refusal.detail, } satisfies ThreadSendResult; } @@ -1996,11 +1989,7 @@ export function makeThreadToolHandlers(deps: ThreadToolDeps) { if (refusal !== null || target === undefined) { return { outcome: - refusal?.outcome === "limit" - ? ("limit" as const) - : refusal?.outcome === "not_allowed" - ? ("not_yours" as const) - : ("refused" as const), + refusal?.outcome === "not_allowed" ? ("not_yours" as const) : ("refused" as const), detail: refusal?.detail ?? NOT_FOUND, threadId: targetId, } satisfies ThreadSendResult; diff --git a/apps/server/src/mcp/threadTools.ts b/apps/server/src/mcp/threadTools.ts index 1e6d4d4f3..d92e8ba72 100644 --- a/apps/server/src/mcp/threadTools.ts +++ b/apps/server/src/mcp/threadTools.ts @@ -14,12 +14,9 @@ import { AgentThreadReadResult, AgentThreadStatusWord, AgentThreadSummary, - CHILD_THREAD_SEND_LIMIT, - CHILD_THREAD_START_LIMIT, CHILD_THREADS_PER_CALL, RuntimeMode, } from "@threadlines/contracts"; -import { LEAD_THREAD_SEND_LIMIT, LEAD_THREAD_START_LIMIT } from "@threadlines/shared/childThreads"; import * as Schema from "effect/Schema"; import { Tool, Toolkit } from "effect/ai"; import { loadedOnDemand } from "./toolLoading.ts"; @@ -86,7 +83,6 @@ export const ThreadStartResult = Schema.Struct({ "started", "asked_user", "off", - "limit", "not_allowed", "unavailable_agent", "refused", @@ -136,7 +132,6 @@ export const ThreadSendResult = Schema.Struct({ "sent", "queued", "not_yours", - "limit", "off", "not_allowed", "refused", @@ -268,7 +263,7 @@ export const ThreadStartTool = loadedOnDemand( Tool.make("thread_start", { description: "Start new threads in this project to work in parallel. Each gets its own agent session and its own git worktree off your current commit (in a project without git they share the project folder). Give each a short `title` and a self-contained `prompt`: the new thread sees none of this conversation, only its prompt. `agent` picks a model from thread_agents; leave it out to use your own model and reasoning. Unless the user asked for a model or reasoning, prefer your own model or one already in this room (thread_agents' `room`), here or on another computer: a thread on a room agent's model runs at the reasoning the user set for that agent. `agent.reasoning` sets a level instead. Threads get your current access and interaction modes, never more; `access` asks for less. `runSetup: false` skips the project's setup script, for quick research. `checkout` puts a thread in a checkout that already exists instead of a new worktree, so it sees the files as they are there, uncommitted changes included (a reviewer for work another thread just finished): no worktree or branch is made and the setup script is not run. It shares that folder with the thread it belongs to, so have only one of them work at a time. `computer` starts them on another linked computer (a name or id from thread_agents' `computers`) in its copy of this project: from your branch when you pushed it, otherwise from that computer's default branch, without your unpushed changes. With `reportBack` (default true) each thread's final reply comes back to you as a message when it finishes; with false they run on their own and nothing comes back. Returns as soon as they are recorded and does not wait for them, so don't poll: carry on, or end your turn if you have nothing else to do. " + - `At most ${CHILD_THREADS_PER_CALL} threads per call and ${CHILD_THREAD_START_LIMIT} per user message (${LEAD_THREAD_START_LIMIT} in the project's lead chat).`, + `At most ${CHILD_THREADS_PER_CALL} threads per call; make more calls for more.`, parameters: Schema.Struct({ threads: Schema.Array( Schema.Struct({ @@ -351,7 +346,6 @@ export const ThreadSendTool = loadedOnDemand( Tool.make("thread_send", { description: "Send one of your threads a message: more work, a correction or a question. If it is idle it starts on it now; if it is busy it takes it after its current turn. Its reply comes back to you as a message, like a start. Only threads you started whose replies still come back to you. `checkout` first moves an idle thread into another thread's checkout, keeping its conversation, so it reads your message there (a thread that planned the work looks at what another thread built). The project's lead chat may also pass a message to an open thread in this project that it did not start (not a room, not one another thread owns, not one the user stopped): it works on it there, and nothing comes back. " + - `At most ${CHILD_THREAD_SEND_LIMIT} messages per user message (${LEAD_THREAD_SEND_LIMIT} in the project's lead chat). ` + "Don't poll; end your turn if you have nothing else to do.", parameters: Schema.Struct({ threadId: ThreadIdParameter, diff --git a/apps/server/src/orchestration/agentRequestDecisions.ts b/apps/server/src/orchestration/agentRequestDecisions.ts index c5e5a70c8..3a05a7789 100644 --- a/apps/server/src/orchestration/agentRequestDecisions.ts +++ b/apps/server/src/orchestration/agentRequestDecisions.ts @@ -1051,19 +1051,14 @@ export function decideAgentChainStop( ]; } -/** The user wrote: the hold comes off, invites resume and the agents' count starts over. */ +/** The user wrote: the hold comes off and invites resume. */ export function resetAgentRequestsForUser( thread: OrchestrationThread, base: EventBase, createdAt: string, ): ReadonlyArray { const state = thread.agentRequests; - if ( - !state.hold && - state.requestsSinceUser === 0 && - !state.invitesPaused && - state.batchesSinceUser.length === 0 - ) { + if (!state.hold && !state.invitesPaused) { return []; } return [ diff --git a/apps/server/src/orchestration/childThreadDecisions.ts b/apps/server/src/orchestration/childThreadDecisions.ts index 458bde5d8..4dce66aa1 100644 --- a/apps/server/src/orchestration/childThreadDecisions.ts +++ b/apps/server/src/orchestration/childThreadDecisions.ts @@ -415,7 +415,6 @@ export function decideChildStart( from: command.from, callerTurnId: command.callerTurnId, count: command.children.length, - isLead: isProjectLeadThread(readModel, parent), }); if (refusal !== null) { return refuse(refusal.detail); @@ -570,13 +569,7 @@ export function decideChildSend( ): ChildThreadDecision { const remoteChild = remoteChildOf(parent.childRequests, command.childThreadId); if (remoteChild !== undefined) { - return decideRemoteChildSend( - parent, - command, - baseFor, - remoteChild, - isProjectLeadThread(readModel, parent), - ); + return decideRemoteChildSend(parent, command, baseFor, remoteChild); } if (pendingChildRequest(parent, command.childThreadId) !== undefined) { return refuse("That thread is still being set up. Send it a message once it has started."); @@ -585,7 +578,6 @@ export function decideChildSend( const refusal = childSendRefusal(parent, child, { from: command.from, callerTurnId: command.callerTurnId, - isLead: isProjectLeadThread(readModel, parent), }); if (refusal !== null || child === null) { return refuse(refusal?.detail ?? "That thread is gone."); @@ -815,7 +807,6 @@ function decideRemoteChildSend( command: CommandOf<"thread.child.send">, baseFor: ChildEventBase, remoteChild: NonNullable>, - isLead: boolean, ): ChildThreadDecision { const refusal = childSendRefusal( parent, @@ -825,7 +816,7 @@ function decideRemoteChildSend( attachedToParent: true, archivedAt: null, }, - { from: command.from, callerTurnId: command.callerTurnId, isLead }, + { from: command.from, callerTurnId: command.callerTurnId }, ); if (refusal !== null) { return refuse(refusal.detail); diff --git a/apps/server/src/orchestration/decider.projectLead.test.ts b/apps/server/src/orchestration/decider.projectLead.test.ts index d607cd584..87cfb42c4 100644 --- a/apps/server/src/orchestration/decider.projectLead.test.ts +++ b/apps/server/src/orchestration/decider.projectLead.test.ts @@ -284,7 +284,6 @@ describe("lead chat passes", () => { const lead = threadIn(passed.model, LEAD); const target = threadIn(passed.model, OTHER); expect(lead.childRequests.open).toEqual([]); - expect(lead.childRequests.sendsSinceUser).toBe(1); const message = target.messages.find((entry) => entry.id === PASS_MESSAGE); expect(message?.fromThread).toMatchObject({ threadId: LEAD, diff --git a/apps/server/src/orchestration/decider.rooms.test.ts b/apps/server/src/orchestration/decider.rooms.test.ts index 3175a08ef..811aadc64 100644 --- a/apps/server/src/orchestration/decider.rooms.test.ts +++ b/apps/server/src/orchestration/decider.rooms.test.ts @@ -26,7 +26,6 @@ import { describe, expect, it } from "vite-plus/test"; import { liveSideTurns } from "@threadlines/shared/sideTurns"; -import { resetAgentRequestsForUser } from "./agentRequestDecisions.ts"; import { decideOrchestrationCommand } from "./decider.ts"; import { createEmptyReadModel, projectEvent } from "./projector.ts"; @@ -815,13 +814,6 @@ describe("decider rooms", () => { agentRequests: { ...EMPTY_AGENT_REQUEST_STATE, hold: true }, }), ).toBe(true); - // Three requests since the user wrote, hand-offs included. - expect( - await refused(request("hand_off"), { - session: working(), - agentRequests: { ...EMPTY_AGENT_REQUEST_STATE, requestsSinceUser: 3 }, - }), - ).toBe(true); // Someone is already answering on the side. expect( await refused(request("ask"), { @@ -837,7 +829,7 @@ describe("decider rooms", () => { ).toBe(true); }); - it("runs a council: several agents review at once, counted once, each settling on its own", async () => { + it("runs a council: several agents review at once, each settling on its own", async () => { const solId = ThreadParticipantId.make("9c2d3e4f-5a6b-4c7d-8e9f-0a1b2c3d4e5f"); const grokId = ThreadParticipantId.make("0d3e4f5a-6b7c-4d8e-9f0a-1b2c3d4e5f6a"); let model = readModel({ @@ -847,8 +839,6 @@ describe("decider rooms", () => { { ...astra, id: solId, handle: "sol" }, { ...astra, id: grokId, handle: "grok" }, ], - // Two requests made already: the batch is the third and last. - agentRequests: { ...EMPTY_AGENT_REQUEST_STATE, requestsSinceUser: 2 }, }); const batchId = RoomAgentBatchId.make("batch-council"); const reviewOf = (participantId: ThreadParticipantId) => @@ -857,7 +847,6 @@ describe("decider rooms", () => { const first = reviewOf(astraId); model = await apply(model, await decideEvents(first, model)); - expect(threadOf(model).agentRequests.requestsSinceUser).toBe(3); // The first review finishes before the others are even asked. model = await apply( model, @@ -875,14 +864,12 @@ describe("decider rooms", () => { ), ); expect(live()).toEqual([]); - // The rest of the batch is neither refused by the limit nor counted again. for (const participantId of [solId, grokId]) { model = await apply(model, await decideEvents(reviewOf(participantId), model)); } expect(live()).toEqual([solId, grokId]); - expect(threadOf(model).agentRequests.requestsSinceUser).toBe(3); - // A request outside the batch waits for the user. - expect(Exit.isFailure(await decide(request("ask"), model))).toBe(true); + // Agents keep asking each other without the user writing in between. + expect(Exit.isSuccess(await decide(request("ask"), model))).toBe(true); // One answer settling leaves the other running. const [solTurn] = liveSideTurns(threadOf(model)); @@ -901,12 +888,6 @@ describe("decider rooms", () => { ), ); expect(live()).toEqual([grokId]); - // The user writing clears the count and the batch. - expect( - resetAgentRequestsForUser(threadOf(model), () => ({}) as never, now).map( - (event) => event.type, - ), - ).toEqual(["thread.agent-requests-reset"]); }); it("lets agents answer on the side side by side, one answer each and three at most", async () => { @@ -957,7 +938,6 @@ describe("decider rooms", () => { threadOf(model).messages.find((message) => message.id === handOff.message.messageId) ?.agentModels, ).toEqual(handOffStamps); - expect(threadOf(model).agentRequests.requestsSinceUser).toBe(1); // The calling turn completed (the reactor's call): the target's turn joins the queue. model = await apply( @@ -1233,7 +1213,6 @@ describe("decider rooms", () => { ...threadOf(model), session: working(), queuedFollowUps: [], - agentRequests: { ...threadOf(model).agentRequests, requestsSinceUser: 0 }, }); // The user stops it, and its answer lands before the stop does. diff --git a/apps/server/src/orchestration/decider.ts b/apps/server/src/orchestration/decider.ts index d8e5264a9..5ad269701 100644 --- a/apps/server/src/orchestration/decider.ts +++ b/apps/server/src/orchestration/decider.ts @@ -331,10 +331,9 @@ function childEventBase( } /** - * The user wrote: the per-message child thread counts start over, and a - * lead chat's pass no longer blocks starting threads. A turn Threadlines - * started for the user (`keepsPassBlock`: a continue, a restart) resets the - * counts but keeps that block (docs/design/lead-chat.md, "No fan-out"). + * The user wrote: a lead chat's pass no longer blocks starting threads. A + * turn Threadlines started for the user (`keepsPassBlock`: a continue, a + * restart) keeps that block (docs/design/lead-chat.md, "No fan-out"). */ function resetChildRequestsForUser( thread: OrchestrationThread, @@ -342,22 +341,16 @@ function resetChildRequestsForUser( createdAt: string, options?: { readonly keepsPassBlock?: boolean }, ): ReadonlyArray { - const state = thread.childRequests; - const keepsPassBlock = options?.keepsPassBlock === true; - const liftsBlock = state.passCeiling !== undefined && !keepsPassBlock; - return state.startsSinceUser === 0 && state.sendsSinceUser === 0 && !liftsBlock - ? [] - : [ - { - ...base(), - type: "thread.child-requests-reset", - payload: { - threadId: thread.id, - ...(keepsPassBlock ? { keepsPassBlock: true as const } : {}), - createdAt, - }, - }, - ]; + if (thread.childRequests.passCeiling === undefined || options?.keepsPassBlock === true) { + return []; + } + return [ + { + ...base(), + type: "thread.child-requests-reset", + payload: { threadId: thread.id, createdAt }, + }, + ]; } /** diff --git a/apps/server/src/provider/agentContextBudget.json b/apps/server/src/provider/agentContextBudget.json index 28e0c3ebc..710c1675a 100644 --- a/apps/server/src/provider/agentContextBudget.json +++ b/apps/server/src/provider/agentContextBudget.json @@ -17,5 +17,5 @@ "show_page" ], "upFrontToolDefinitionBytes": 18074, - "onDemandToolDefinitionBytes": 50760 + "onDemandToolDefinitionBytes": 50661 } diff --git a/apps/web/src/store.test.ts b/apps/web/src/store.test.ts index fbc1b10cb..3e6b694f7 100644 --- a/apps/web/src/store.test.ts +++ b/apps/web/src/store.test.ts @@ -2200,7 +2200,6 @@ describe("incremental orchestration updates", () => { }); expect(running?.agentRequests).toMatchObject({ open: [{ requestId, status: "running" }], - requestsSinceUser: 1, }); state = apply( @@ -2226,7 +2225,6 @@ describe("incremental orchestration updates", () => { open: [], hold: true, chainEpoch: 1, - requestsSinceUser: 1, }); // The outcome stays on the message, beside what the review was given. expect(stopped?.messages[0]).toMatchObject({ requestOutcome: "stopped", reviewInput }); @@ -2241,7 +2239,6 @@ describe("incremental orchestration updates", () => { expect(selectThreadByRef(state, ref)?.agentRequests).toMatchObject({ hold: false, chainEpoch: 1, - requestsSinceUser: 0, }); }); @@ -2325,9 +2322,9 @@ describe("incremental orchestration updates", () => { awaitedChildThreadCount: 1, pendingChildApproval: true, }); - expect(selectThreadByRef(state, scopeThreadRef(localEnvironmentId, parentId))).toMatchObject({ - childRequests: { startsSinceUser: 2 }, - }); + expect( + selectThreadByRef(state, scopeThreadRef(localEnvironmentId, parentId))?.childRequests?.open, + ).toHaveLength(2); // The parent's request lands in the child as another thread's message. state = apply( diff --git a/docs/design/agent-autonomy-no-limits.md b/docs/design/agent-autonomy-no-limits.md new file mode 100644 index 000000000..92f35260f --- /dev/null +++ b/docs/design/agent-autonomy-no-limits.md @@ -0,0 +1,124 @@ +# Agents work without per-message limits, and threads nest + +Status (Nov 23 2026): Part 1 is built. Part 2 is **not built**: GPT-6.2 Astra's review of rev 1 found that its delivery rule loses or misroutes answers (see "Review of Part 2, rev 1" at the end), so it needs a redesign before anyone builds it. Asked for by Will: "do it all the T3 code way, we will accept the same risks that they are taking". The goal is a lead agent that directs other agents, in a room or in threads it starts, for hours or days without the user writing. + +## What T3 Code does (pingdotgg/t3code at f1c13177d8) + +- No count, rate, depth or loop limit on agent-to-agent traffic. `delegate_task`, `t3_thread_send` and the rest run no count checks (`OrchestratorMcpService.ts:2855-2990`, `:3672-3724`). +- Children can delegate again, to any depth. Stop on a thread walks its delegated tasks recursively (`ThreadManagementService.ts:1789`, test `ThreadStop.test.ts:537`). +- Limits that stay: a child never gets more access than its parent (`delegatedTaskModes.ts`), message size (120,000 chars), batch size per call (20), one wait call blocks at most 45 s. +- Every child completion wakes its parent (`completionWake: "always"`). +- The risk they accept: two agents can message each other forever, unwatched, and spend the user's usage. The only brakes are tool wording, the user's Stop, and provider usage limits. + +We take the same risk. We do not add a loop detector: a false alarm would stop a run that has been going for days, which is the case this change is for. + +## Part 1: remove the per-message counts + +Removed, with their counters, refusals, `limit` outcomes and every text that states them: + +- Rooms: `ROOM_AGENT_REQUEST_LIMIT` (3 asks, reviews and hand-offs since the user wrote). `requestsSinceUser` and `batchesSinceUser` stop being counted or read. `roomAgentRequests.ts:61,105,163,224,275` and `agentRequestDecisions.ts:1063`. +- Threads: `CHILD_THREAD_START_LIMIT` (5), `CHILD_THREAD_SEND_LIMIT` (10), and the lead chat's 10 and 20 (`childRequestLimits`). `startsSinceUser` and `sendsSinceUser` likewise. +- Texts: room and thread tool descriptions (`roomTools.ts`, `threadTools.ts`), the lead chat's role text (`docs/design/lead-chat.md` "The role text states the lead's limits"), guide topics (`apps/server/src/guide/topics.ts`), `docs/design/rooms-slice-2.md` and `docs/design/child-threads.md`. + +Kept, because none of them caps how much agents do over time: + +- `MAX_LIVE_SIDE_TURNS = 3`: side answers running at once. More wait or are refused with "try again once one finishes". +- `CHILD_THREADS_PER_CALL = 5` per `thread_start` call. An agent makes another call. +- Prompt and title size limits, `THREAD_LIST_PROJECT_LIMIT`, `THREAD_WRAP_PER_CALL`. +- Stop: it still ends a chain for good, and agent-origin traffic still waits after Stop until the user writes (the `hold`, `chainEpoch`, `deliveryEpoch` and `queueHeldByStop` rules). +- Approval settings: "Agents can start threads" off / ask / auto, invites, and "Threads can share a checkout". +- The no-fan-out rule for work the lead chat passes on (`passCeiling`): it keeps one lead message from reaching through every thread it is passed to. That's about access, not volume. +- Outside agents' calls-per-minute limit (`outsideAgents/`): callers outside Threadlines, not agents talking to each other. +- A thread messages only threads it started (plus the lead chat's pass). T3 Code lets any thread message any thread; we keep ownership because it's how replies find their way back and how Stop knows what to stop. + +Schema: the four counter fields stay in the schema, because an older client (a phone or another computer on an earlier version) still requires them when it decodes a thread from a newer server. Nothing counts or reads them any more; stored values are left as they were. The `limit` outcome is gone from the room and thread tool results; the web still reads it in old transcripts (`apps/web/src/childThreads.ts`). `thread.child-requests-reset` now only lifts a lead pass's block, and an old event with `keepsPassBlock` changes nothing. + +## Part 2: threads nest to any depth + +### Rules that go + +Every "a thread started by another thread can't..." refusal: + +- `callerRefusal`'s `DEPTH_REFUSAL` (`packages/shared/src/childThreads.ts:74`): `thread_start`, `thread_send`, `thread_stop`, `thread_wrap` from an attached child. +- `decideChildrenStop`'s two refusals (`childThreadDecisions.ts:1814,1833`). +- `thread.create` refusing a parent that is itself an attached child (`decider.ts:1559`). +- Put back's "parent is itself an attached child" and "this thread has started threads of its own" (`childThreads.ts:286-291`). A cycle can't form: `parentThreadId` is set once at creation, and put back only re-attaches to that thread. +- The tool texts and `Depth 1` section of `child-threads.md`. + +Kept: the access ceiling (a child never gets more than its parent, checked at create and on every send, so it holds down any chain), linked computers (a thread another computer's agent started here stays fenced from thread tools, `isLinkFenced`), and the lead chat's `ownChildRefusal` for passes. + +### A middle thread answers only when its own children have + +Today a request from R to its child M settles when M's answering turn completes with no awaited background tasks. If M started threads of its own in that turn, R gets "I started G1 and G2" and goes on; G1's report later wakes only M, and M's final answer reaches R only as a late-reply note at R's next turn (`lateReplyOf`), never waking it. That breaks a lead directing a team for hours. + +New rule: **a thread's open child requests are owed work, like awaited background tasks.** One predicate `owedWorkCount(thread) = awaitedBackgroundTaskCount + open child requests that report back` replaces the background count wherever delivery reads it: + +1. `childDeliveryForTurnEnd`: M's answering turn completes with owed work → `awaiting_background` with that turn as the candidate (unchanged path, wider input). +2. A turn in M started by **a report from one of M's own children** (`fromThread.kind === "report"`, the report's `threadId` attached to M) continues R's `awaiting_background` request, exactly as a follow-up turn started by background work does today (`pendingMessageId === null`). Completed with owed work left → it becomes the new candidate. Completed with none → R's request settles `answered` with that turn's last reply. Failed or stopped → settles as today. + - A turn started by the user or by R's own `thread_send` still answers only its own message (unchanged). +3. `isQuietCandidate` also requires no open child requests, and the reactor re-checks quiet candidates when **M's child requests settle** (`thread.child-request-settled` on M), not only on M's `session-set`. That covers M's last child settling with no report (`thread_stop` by M, declined approval, separated by the user): M takes no turn, so R's request settles with the candidate. +4. Restart: an `awaiting_background` request whose candidate thread still has open child requests is **not** settled with the candidate at startup. Those child requests recover by their own rules and wake M, which continues R's request. Only background work dies with the process; child requests don't. +5. Usage-limit continue: a report turn in M that continues R's request is heldable like an answering turn (`answersHeldableRequest`), so "continue at reset" keeps R's request open instead of failing it. +6. Linked computers: the link ledger path (`LinkRequests`) uses the same `childDeliveryForTurnEnd`; a remote child is fenced from starting threads, so it never has owed child requests. No change there beyond the shared input. + +R's shell keeps showing "Waiting · N threads" from `awaitedChildThreadCount`; it counts R's own open requests, which now stay open while grandchildren work. That's the truthful state. + +### Stop, wrap, archive and delete reach the whole subtree + +Each stays one decision in the decider, so nothing slips through between steps (the failure T3 Code's bug list is full of): + +- **"Stop N working threads"** (`thread.children.stop` without ids) stops every working descendant, not just direct children: each thread's own Stop rules apply (its open requests settle `stopped`, queued reports unqueued, notes added). The menu count is the subtree's. `thread_stop` from an agent on its own child stops that child's subtree too, so a lead can end a whole branch in one call. +- **Stop on a thread itself** keeps today's rule: its requests settle, its children keep running. Changing that is a separate decision Will made (child-threads.md decision 4 covers wrap; Stop follows it). +- **Archive cascade** recurses: a settled attached descendant is archived and stamped `archivedWithParentAt`; a live one is separated, with its own subtree staying attached to it. Unarchive restores everything stamped by that archive. +- **Delete with its threads** deletes the whole attached subtree; without it, direct children are separated and keep their own subtrees. +- **Auto-wrap** already reads the parent's done state recursively (`fileInboxThreads.resolveDone`); only the "one level deep" comment changes. + +### Sidebar + +The root's family shows every attached descendant, in tree order (each child followed by its own descendants, creation order within a level), one line each, indented one step per level below the first. The summary line ("●●● 7 threads · 1 needs you") counts the whole subtree. A collapsed family still shows any descendant that needs the user, and the open one. A middle thread's row gets the same menu items a parent row has ("Stop N working threads" for its subtree). Indentation steps stop growing after level 3 so titles keep room on a phone. + +`familyParentKeyOf` stays the direct parent; a new `familyRootKeyOf` walks up attached parents (with a visited set) to pick the family a row renders under. + +### Chat + +Nothing new: a middle thread already shows "Started by " and its own "Started N threads" cards. The attached-child preamble adds one sentence when the thread may start threads: "Threads you start report back to you; your final answer goes back once they have." + +## Every surface + +- **Providers.** Thread tools already reach Codex, Claude, OpenCode and HTTP ACP agents through the room endpoint; children get them like any thread. No per-driver change. +- **Clients.** Web and desktop share the sidebar; phone gets it through the same components. +- **Contracts.** Constant and counter removals; no new wire fields (descendant walks are computed). +- **App guide.** Rooms topic and threads topic lose the limits and gain "threads can start threads". +- **Reverse states.** Stop subtree ↔ next message resumes each; archive subtree ↔ unarchive restores the stamped ones; separate ↔ put back (now allowed at any depth). + +## Tests (extend existing files) + +- `roomAgentRequests`/`agentRequestDecisions`: a fourth and a fortieth request are accepted. +- `childThreads` shared tests: starts and sends past the old limits accepted; an attached child can start, send, stop and wrap; put back allowed for a thread with its own children. +- `decider.childThreads.test.ts`: create under an attached child; subtree stop in one command; archive and unarchive of a three-level family; delete with children three levels. +- `childThreadDelivery` tests: M's answering turn with an open child request → `awaiting_background`; G's report turn in M with nothing left owed → R's request answered with that reply; with more owed → new candidate; M's last child settled without a report → quiet candidate settles; restart keeps an awaiting request whose thread still has open child requests. +- `Sidebar.logic` tests: tree order, indentation level, subtree counts, root key walk. +- Browser: the family rows render three levels; polish shot with real fonts, light and dark unchanged colours. +- Live: a throwaway stack (never `~/.threadlines/userdata`), a Claude root starts a child that starts a grandchild; the grandchild's answer reaches the root and wakes it; "Stop N working threads" on the root stops all three levels. + +## Review of Part 2, rev 1 (GPT-6.2 Astra, Nov 23 2026) + +Checked against the code; each holds. A redesign has to answer all of them. + +1. **Pending reports are owed work too.** A child's request leaves `open` when its report is queued, not when the middle thread has read it. M with G1 and G2: G2 settles while M handles G1's report on a provider that can't steer, so M's turn ends with zero open requests and R gets the G1-only answer. +2. **Downstream work needs the upstream request's identity.** R sends M a second task while the first waits on G: M's second turn sees G open and becomes a candidate too; G's report steered into it answers the wrong request. In a room the two requests can come from different agents. +3. **The session reaper (`ProviderSessionReaper.ts`, 30 minutes idle) stops an idle middle thread** whose children are still working, and `ChildThreadReactor.settleStoppedAnswers` then tells R "the user stopped" M. Runtime eviction must not read as a stop. +4. **Restart** settles R before M's queued report replays (M has zero open requests once G settled), misses a report turn that completed before the crash (recovery only matches `pendingMessageId === null` continuations), and delivers M's first turn when its `awaiting_background` update didn't commit. +5. **A room hand-off in M** goes through `thread.turn.start` without `fromThread`, so `settleCandidateBeforeUserTurn` sends R the candidate while G works. +6. **Usage-limit continue** (`isHeldByContinueAtReset`) requires `running` and the failed turn's own message; an `awaiting_background` request continued by a report turn fails at once. +7. **Reports with no local attached child** (a remote G with `environmentId`, a `neverMade` G) still start turns in M; and a queued report taken back (separate, wrap, room departure) triggers no re-check. +8. **The MCP handlers have their own depth checks** (`threadToolHandlers.ts` start, local ownership, remote send, remote stop, wrap), separate from the shared and decider rules listed above. +9. **Nesting lets a lead pass escape its ceiling** (T passes to its existing child M, which carries no pass block and starts G), and ordinary sends don't re-check the parent's current access when the user narrowed it after the child was made. +10. **Delete with its threads** would delete more than the dialog counted (`useThreadActions.ts` counts direct children only and winds down only those). +11. **Agent-issued subtree stop** returns `not_running` for an idle M whose child works (`childHasWork` ignores M's own requests), and stopping M first settles the requests used to find the rest. +12. **Late replies and moves** assume one level (`lateRepliesForAgent` returns early for an attached thread; move admission and whole-family moves refuse or flatten a middle parent). +13. **The chat's family tabs** (`familyTabs.logic.ts`) list a parent's direct children only and would disagree with a nested sidebar. + +Atomicity is fine: the engine commits one decision's events in one transaction, and `decideCommandSequence` projects each step before the next. The counter fields can go from storage, but older clients need them on the wire (kept, see Part 1). + +A simpler direction worth weighing in the redesign: T3 Code's own. Every completion of a child that isn't the user's own conversation with it wakes its parent with a report, instead of holding the parent's request open until the subtree settles. R's request settles as today; M's later answers arrive as new reports. That removes findings 1, 2, 4, 5 and 6 (no request stays open across M's turns) at the cost of R being woken more often, which is the risk Will accepted. Findings 3 and 7 to 13 remain either way. diff --git a/docs/design/child-threads.md b/docs/design/child-threads.md index 00ef231a1..01e89a298 100644 --- a/docs/design/child-threads.md +++ b/docs/design/child-threads.md @@ -127,15 +127,15 @@ hasAgentRecords || agentInvitesMode !== "off" || agentThreadsMode !== "off"; Side runtimes never get these tools: `roomToolsFor(side)` excludes them and the handler re-checks `scope.side === undefined`. Every tool answers with an `outcome` literal and never blocks on child work. -| Tool | Input | Behavior | -| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `thread_agents` | none | Ready provider instances and models a child can run on, each model with its reasoning levels. Also `yours` (the caller's model and reasoning) and, in a room, `room` (the other agents still in it, each with the reasoning the user set). Respects `agentThreads`, not invites. Excludes per-use-billed sign-ins, as invites do (`PER_USE_AUTH_TYPES`), and providers that cannot honor the caller's interaction mode. | -| `thread_start` | `threads: 1..5 × { title, prompt, agent?: { instanceId, model, reasoning?, options? }, runSetup?: boolean = true }`, `reportBack?: boolean = true` | Starts threads in the caller's project, each in its own new worktree off the caller's current branch (see Workspaces). `agent` defaults to the caller's model and reasoning. The description steers the agent to its own model or one already in the room unless the user asked otherwise. A named agent's reasoning is settled as described under Reasoning. `reportBack: false` starts them already separated, so nothing comes back. Returns `started` with `[{ threadId, title, model, reasoning? }]`, `asked_user`, `off`, `limit`, `not_allowed`, `unavailable_agent`, or `refused` (a reasoning level the model doesn't have). | -| `thread_list` | `scope?: "mine" \| "project" = "mine"` | The caller's children (attached and separated), or the project's non-archived threads (newest first, max 30). For each: id, title, status word, branch, model, attached, startedBy. | -| `thread_read` | `threadId`, `after?`, `limit? = 20` | Same project only. Recent user and assistant messages (each clipped at 4,000 chars, with a flag), status, and a `next` cursor. | -| `thread_send` | `threadId`, `message` | The caller's attached children only. If the child is idle, starts a turn. If busy, queues behind its current turn. The answer comes back like a start. Returns `sent`, `queued`, `not_yours`, or `limit`. | -| `thread_stop` | `threadId` | The caller's attached children only. Stops the child's whole session: the turn, background agents and workflows (`thread.session.stop`; the next message resumes it). The parent's requests for that child settle `stopped` without waking it. The parent's messages still queued in the child are taken back. Returns `stopped` or `not_running`. | -| `thread_wrap` | `threadIds: 1..20` | The caller's attached children only, and only finished ones. Wraps each up as the user's Wrap up does (`thread.done-override.set` with `byParentAgent`) and marks it seen; a child on a linked computer is wrapped on the parent's record (`thread.remote-child.done-override.set`) and sent on. Returns `ok` with one outcome per thread: `wrapped`, `working`, `not_yours`, `refused` or `failed`. See "Wrapped up by the parent's agent". | +| Tool | Input | Behavior | +| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `thread_agents` | none | Ready provider instances and models a child can run on, each model with its reasoning levels. Also `yours` (the caller's model and reasoning) and, in a room, `room` (the other agents still in it, each with the reasoning the user set). Respects `agentThreads`, not invites. Excludes per-use-billed sign-ins, as invites do (`PER_USE_AUTH_TYPES`), and providers that cannot honor the caller's interaction mode. | +| `thread_start` | `threads: 1..5 × { title, prompt, agent?: { instanceId, model, reasoning?, options? }, runSetup?: boolean = true }`, `reportBack?: boolean = true` | Starts threads in the caller's project, each in its own new worktree off the caller's current branch (see Workspaces). `agent` defaults to the caller's model and reasoning. The description steers the agent to its own model or one already in the room unless the user asked otherwise. A named agent's reasoning is settled as described under Reasoning. `reportBack: false` starts them already separated, so nothing comes back. Returns `started` with `[{ threadId, title, model, reasoning? }]`, `asked_user`, `off`, `not_allowed`, `unavailable_agent`, or `refused` (a reasoning level the model doesn't have). | +| `thread_list` | `scope?: "mine" \| "project" = "mine"` | The caller's children (attached and separated), or the project's non-archived threads (newest first, max 30). For each: id, title, status word, branch, model, attached, startedBy. | +| `thread_read` | `threadId`, `after?`, `limit? = 20` | Same project only. Recent user and assistant messages (each clipped at 4,000 chars, with a flag), status, and a `next` cursor. | +| `thread_send` | `threadId`, `message` | The caller's attached children only. If the child is idle, starts a turn. If busy, queues behind its current turn. The answer comes back like a start. Returns `sent`, `queued` or `not_yours`. | +| `thread_stop` | `threadId` | The caller's attached children only. Stops the child's whole session: the turn, background agents and workflows (`thread.session.stop`; the next message resumes it). The parent's requests for that child settle `stopped` without waking it. The parent's messages still queued in the child are taken back. Returns `stopped` or `not_running`. | +| `thread_wrap` | `threadIds: 1..20` | The caller's attached children only, and only finished ones. Wraps each up as the user's Wrap up does (`thread.done-override.set` with `byParentAgent`) and marks it seen; a child on a linked computer is wrapped on the parent's record (`thread.remote-child.done-override.set`) and sent on. Returns `ok` with one outcome per thread: `wrapped`, `working`, `not_yours`, `refused` or `failed`. See "Wrapped up by the parent's agent". | - **Reasoning.** A child's reasoning is settled when it is asked for (`settleChildReasoning` in childThreadAgents.ts) and saved in its launch, so replay and approval use exactly what the card showed. In order: a level named in `agent.reasoning` (id or picker label; `"default"` for the provider's own); a reasoning option passed in `agent.options`, refused if the model doesn't offer it; the level of the first agent on the same provider kind and model among the caller, the room's other agents still in it, and the user's default for new threads. The first matching agent decides: one that names no level leaves it to the provider, and a level the model doesn't offer (another computer's catalog can differ) is refused with the model's levels rather than quietly dropped. Only the reasoning follows, never other options (a fast service tier is the user's to choose); Claude's retired `ultracode` effort follows as Extra High, without the Ultracode switch it implied. Matching is by provider kind and model, so it works across computers too. The approval card shows the level beside the model. - **Depth 1.** A thread that is currently an attached child gets `not_allowed` from `thread_start`, `thread_send`, `thread_stop` and `thread_wrap`. It can still read and list. A separated child counts as top-level. @@ -266,7 +266,7 @@ Pure rules live in `packages/shared/src/childThreads.ts` (refusals, limits, fami - the setting is not off; - the caller is a main runtime inside its own turn; - the caller is not an attached child; - - the limits (counting pending approvals); + - (the per-message limits were removed in Nov 2026); - the agents are ready, not per-use billed, and can honor the caller's interaction mode. 2. **`thread.child.start` (server-only).** Records one request per child with the full `launch`, sharing a `batchId`. - `ask` mode: `awaiting_user`; the tool returns `asked_user`. @@ -335,8 +335,7 @@ If any check fails, the entry is unqueued `cancelled`. This catches answers dequ ### Limits - At most 5 threads per call. -- At most 5 started threads (pending approvals included) and 10 sends per user message. -- Counters persist in the child-request state, reset on real user submissions, and are untouched by agent-origin traffic. +- No limit on starts or sends per user message. There was one (5 starts and 10 sends); it was removed in Nov 2026 (docs/design/agent-autonomy-no-limits.md). `startsSinceUser` and `sendsSinceUser` stay in the schema for older clients and are no longer counted. - After Stop, agent-origin sends wait until the user writes. The `queueHeldByStop` rule now covers `fromThread` too. ### Stop, wrap, separate, delete, archive diff --git a/docs/design/lead-chat.md b/docs/design/lead-chat.md index bc11bbd87..66ec02b26 100644 --- a/docs/design/lead-chat.md +++ b/docs/design/lead-chat.md @@ -284,8 +284,9 @@ coordinate it. developer message in the thread's history (`thread/inject_items`) before `thread/goal/set`, so the turns it runs for the goal read it; an app-server that refuses that still gets the goal. -- **The role text states the lead's limits** (starts and sends per user message), and - so do the `thread_start` and `thread_send` descriptions. +- **The role text says the lead may start and message as many threads as the work + needs**, at most 5 threads per call. (It once stated per-message limits; those were + removed in Nov 2026, docs/design/agent-autonomy-no-limits.md.) ### Tools @@ -339,7 +340,6 @@ coordinate it. or one on another computer, is refused ("Do the work here, or tell the user, who can send it there."). The check is at send time; after that, only the user can raise a child's access. - - A pass counts against the lead's sends per user message. - What the target does with it is the target's business: the user's own queued messages go first; Stop, taking the message off the queue, revert and archive work as they do for any message, and need no word to the lead. @@ -350,10 +350,8 @@ coordinate it. holds an observation; no network call; a branch's pull request is matched on the project remote's host and whole path, never on `owner/name` alone). Every agent sees which thread is the lead. -- **Limits in a lead:** 10 starts and 20 sends per user message (5 and 10 elsewhere); - 5 per call stays. A scheduled or event run into the lead already counts as the user - writing (`thread.follow-up.submit` resets the counters), so a lead fed by an event - task keeps a budget per event, bounded by the task's own daily run limit. +- **Limits in a lead:** none per user message (there were 10 starts and 20 sends, + removed in Nov 2026); 5 threads per call stays. - **Outside agents and assistants:** the project listing they read gains optional `leadThreadId`, so "send this to the project's lead" needs no thread id from the user. - **Tool descriptions** say the lead's extra reach in one sentence each; ACP agents @@ -443,8 +441,7 @@ Absent means the whole batch. Capability `childStartSelection` gates the checkbo ### Limits -`childStartRefusal` and `childSendRefusal` take the caller's limits from one function -`childRequestLimits({ isLead })`; the constants stay as the defaults. +None per user message since Nov 2026 (docs/design/agent-autonomy-no-limits.md). ## Usage limits: pause, not failure diff --git a/docs/design/rooms-agent-invites.md b/docs/design/rooms-agent-invites.md index ce1fb08bc..9dc30679d 100644 --- a/docs/design/rooms-agent-invites.md +++ b/docs/design/rooms-agent-invites.md @@ -90,7 +90,7 @@ runtimes). ### Requests Invites reuse room agent requests (`thread.agentRequests`, JSON) with a new -kind, `invite`, so the limit (3 per user message), Stop's hold and epoch, and +kind, `invite`, so Stop's hold and epoch, and restart recovery apply: - request fields (optional in the schema): `reason`, `suggestion` ("review" | @@ -114,7 +114,7 @@ Commands: Decisions (agentRequestDecisions.ts, pure): - submit: caller holds the thread with a turn in flight; refused when paused, - held, over the limit, or another invite is awaiting the user. + held, or another invite is awaiting the user. - respond (and the auto path) revalidates everything that can change while the user thinks: the request is `awaiting_user`, the epoch is unchanged, voice is off, the caller is still in the thread. Then, in one decision: for @@ -205,7 +205,7 @@ rules for real rooms are unchanged. ## Tests (focused) -- decider: submit refusals (paused, held, limit, pending invite), each choice +- decider: submit refusals (paused, held, pending invite), each choice (events and request state), decline pauses until the user writes, invite survives the caller's turn ending, Stop cancels it. - guest: a guest-only thread is not a room (revert allowed, no room header). diff --git a/docs/design/rooms-slice-2.md b/docs/design/rooms-slice-2.md index 3ff9065d1..642ec82c1 100644 --- a/docs/design/rooms-slice-2.md +++ b/docs/design/rooms-slice-2.md @@ -29,7 +29,9 @@ on them. - Stop ends a chain for good. - The user's messages go ahead of agent requests, including ones that arrive later. - - Agents get 3 requests of each other before they have to wait for the user. + - Agents make as many requests of each other as they like. The limit of 3 + per user message was removed in Nov 2026 + (docs/design/agent-autonomy-no-limits.md). - Identity is explicit. Every side answer and every agent request has a stable id that travels with its events. Nothing is matched by "the next event from that agent" or "whoever holds the slot now". @@ -640,19 +642,13 @@ every request has a durable record from submission to its final outcome. goes away, that waiter detaches; the request is cancelled only when its last waiter leaves. To verify at build time; if the handler is not interrupted, the caller's turn ending covers it. -- **Limit: 3 agent requests (asks, reviews and hand-offs) since the user last - wrote.** - - The decider counts accepted requests in `agentRequestsSinceUser` at - submission, queued hand-offs included. The decider is sequential, so - parallel calls cannot slip past it. - - A routed reply never counts, so the return half of an accepted hand-off - always arrives. - - A fourth request returns `limit` to the calling agent, which tells the - user in its reply. The room shows no notice of its own: reaching the - limit does not mean anyone is waiting, and a standing line for it read - as nagging in normal use. +- **No request limit.** There was one (3 asks, reviews and hand-offs since the + user last wrote); it was removed in Nov 2026 so agents can work together for + hours without the user (docs/design/agent-autonomy-no-limits.md). + `requestsSinceUser` and `batchesSinceUser` stay in the schema for older + clients and are no longer counted. - The user's next submission (a message, a queued message or a side - question) resets the count and lifts the hold. + question) lifts the hold. ### Chat @@ -934,8 +930,8 @@ Room tools (PR 2): included); `tools/list` on each endpoint shows only its own tools. 24. `room_diff` rejects a revision or path shaped like an option (`--output=...`), and never runs a text conversion or external diff. -25. The limit counts queued hand-offs: four hand-offs in one turn leave the - fourth refused. +25. (Removed Nov 2026 with the request limit: four hand-offs in one turn + are all accepted.) 26. A hand-off's reply is the target's final text, not a partial buffer; a crash between the target finishing and routing still routes exactly once after restart. diff --git a/packages/contracts/src/orchestration.ts b/packages/contracts/src/orchestration.ts index 607cae2bd..d40a48470 100644 --- a/packages/contracts/src/orchestration.ts +++ b/packages/contracts/src/orchestration.ts @@ -2654,19 +2654,15 @@ export const OrchestrationAgentRequest = Schema.Struct({ }); export type OrchestrationAgentRequest = typeof OrchestrationAgentRequest.Type; -/** - * How many requests agents may make of each other before they wait for the - * user. The user's next submission resets the count. A review asked of - * several agents in one call counts once. - */ -export const ROOM_AGENT_REQUEST_LIMIT = 3; - /** * Room tools state on a thread. `hold` is set by Stop and cleared by the * user's next submission; `chainEpoch` is raised by Stop, and no request - * from an older epoch survives it; `requestsSinceUser` counts requests - * toward ROOM_AGENT_REQUEST_LIMIT; `invitesPaused` is set when the user + * from an older epoch survives it; `invitesPaused` is set when the user * declines an invite, and cleared, like `hold`, when the user next writes. + * Agents make as many requests of each other as they like + * (docs/design/agent-autonomy-no-limits.md): `requestsSinceUser` and + * `batchesSinceUser` are no longer counted or read, and stay only so older + * clients still decode a thread. */ export const OrchestrationAgentRequestState = Schema.Struct({ open: Schema.Array(OrchestrationAgentRequest), @@ -2674,11 +2670,7 @@ export const OrchestrationAgentRequestState = Schema.Struct({ chainEpoch: NonNegativeInt, requestsSinceUser: NonNegativeInt, invitesPaused: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))), - /** - * The batches (one review call for several agents) counted since the user - * last wrote: a request of a counted batch is neither counted again nor - * refused by the limit, however its siblings have settled. - */ + /** No longer counted; see above. */ batchesSinceUser: Schema.Array(RoomAgentBatchId).pipe( Schema.withDecodingDefault(Effect.succeed([])), ), @@ -3006,8 +2998,10 @@ export type ChildRequestNote = typeof ChildRequestNote.Type; /** * Child threads on the thread that started them. `deliveryEpoch` is raised by * Stop and by wrapping this thread: no answer asked for under an older epoch - * comes back. The counts are toward the per-message limits and start over - * when the user writes; pending approvals count. + * comes back. Agents start and message as many threads as they like + * (docs/design/agent-autonomy-no-limits.md): `startsSinceUser` and + * `sendsSinceUser` are no longer counted or read, and stay only so older + * clients still decode a thread. */ export const OrchestrationChildRequestState = Schema.Struct({ open: Schema.Array(OrchestrationChildRequest), @@ -3040,10 +3034,6 @@ export const EMPTY_CHILD_REQUEST_STATE: OrchestrationChildRequestState = { /** Threads one `thread_start` call may start. */ export const CHILD_THREADS_PER_CALL = 5; -/** Threads an agent may start per user message, pending approvals included. */ -export const CHILD_THREAD_START_LIMIT = 5; -/** Messages an agent may send its threads per user message. */ -export const CHILD_THREAD_SEND_LIMIT = 10; /** Notes kept for an agent's next turn; the oldest give way. */ export const CHILD_REQUEST_NOTE_LIMIT = 20; @@ -3143,7 +3133,7 @@ export const OrchestrationThread = Schema.Struct({ sideTurns: Schema.optional(Schema.Array(OrchestrationSideTurn)), /** See OrchestrationThreadShell.agentRole. */ agentRole: Schema.optional(RoomAgentRole), - /** Room tools: open agent requests, the Stop hold and the limit's count. */ + /** Room tools: open agent requests and the Stop hold. */ agentRequests: OrchestrationAgentRequestState.pipe( Schema.withDecodingDefault(Effect.succeed(EMPTY_AGENT_REQUEST_STATE)), ), @@ -3213,7 +3203,7 @@ export const OrchestrationThread = Schema.Struct({ * clears the debt (`resumed`). One that can't be used pays it (`fell_back`). */ nativeSession: Schema.optional(ThreadNativeSession), - /** Child threads this thread started: open requests, limits and notes. */ + /** Child threads this thread started: open requests and notes. */ childRequests: OrchestrationChildRequestState.pipe( Schema.withDecodingDefault(Effect.succeed(EMPTY_CHILD_REQUEST_STATE)), ), @@ -6677,13 +6667,14 @@ export const ThreadChildDeliveriesCancelledPayload = Schema.Struct({ createdAt: IsoDateTime, }); -/** The user wrote: the per-message child thread counts start over. */ +/** The user wrote: a lead chat's pass no longer blocks starting threads. */ export const ThreadChildRequestsResetPayload = Schema.Struct({ threadId: ThreadId, /** - * A turn Threadlines started for the user (a continue at the reset, after a - * restart or an account switch), not the user writing: the counts start - * over, but a pass's block on starting threads stays. + * Only on events written while agents had per-message counts: a turn + * Threadlines started for the user (a continue at the reset, after a + * restart or an account switch) reset the counts but kept a pass's block. + * Such an event now changes nothing. New events never carry it. */ keepsPassBlock: Schema.optional(Schema.Literal(true)), createdAt: IsoDateTime, @@ -6691,7 +6682,8 @@ export const ThreadChildRequestsResetPayload = Schema.Struct({ /** * The lead chat's passes (docs/design/lead-chat.md, "A pass"). On the lead: - * `sent` counts one toward its sends since the user wrote; `refused` (the + * `sent` records that one went (it once counted toward a per-message limit, + * which is gone); `refused` (the * passed message could not run, its ceiling was over) leaves `note` for the * lead's next turn. On the thread passed to: `started` (the pass started its * turn there) blocks its agents from starting threads until the user writes. diff --git a/packages/shared/src/childThreads.test.ts b/packages/shared/src/childThreads.test.ts index 3ba62fb40..8b4197d93 100644 --- a/packages/shared/src/childThreads.test.ts +++ b/packages/shared/src/childThreads.test.ts @@ -70,36 +70,23 @@ describe("childStartRefusal", () => { expect(refusal).toBeNull(); }); - it("counts threads still waiting for approval toward the per-message limit", () => { - const state = childRequestStateOn.submitted( - childRequestStateOn.submitted( - EMPTY_CHILD_REQUEST_STATE, - request({ status: "awaiting_user", requestId: ChildRequestId.make("a") }), - ), - request({ status: "awaiting_user", requestId: ChildRequestId.make("b") }), - ); + it("lets an agent keep starting and messaging threads without the user writing", () => { + // Counts a thread kept from before the per-message limits were removed. + let state = { ...EMPTY_CHILD_REQUEST_STATE, startsSinceUser: 40, sendsSinceUser: 40 }; + for (let index = 0; index < 40; index++) { + state = childRequestStateOn.submitted( + state, + request({ status: "awaiting_user", requestId: ChildRequestId.make(`r${index}`) }), + ); + } + const busy = caller({ childRequests: state }); + expect(childStartRefusal(busy, { from: PRIMARY, callerTurnId: TURN, count: 5 })).toBeNull(); expect( - childStartRefusal(caller({ childRequests: state }), { - from: PRIMARY, - callerTurnId: TURN, - count: 3, - }), - ).toBeNull(); - expect( - childStartRefusal(caller({ childRequests: state }), { - from: PRIMARY, - callerTurnId: TURN, - count: 4, - })?.outcome, - ).toBe("limit"); - // A project's lead chat gets twice the budget. - expect( - childStartRefusal(caller({ childRequests: state }), { - from: PRIMARY, - callerTurnId: TURN, - count: 4, - isLead: true, - }), + childSendRefusal( + busy, + { id: CHILD, parentThreadId: PARENT, attachedToParent: true, archivedAt: null }, + { from: PRIMARY, callerTurnId: TURN }, + ), ).toBeNull(); }); @@ -188,12 +175,9 @@ describe("childRequestStateOn", () => { expect(childRequestStateOn.notesDelivered(settled, [note.requestId]).pendingNotes).toEqual([]); }); - it("starts the counts over when the user writes, keeping open requests", () => { + it("keeps open requests when the user writes", () => { const open = childRequestStateOn.submitted(EMPTY_CHILD_REQUEST_STATE, request()); - const reset = childRequestStateOn.reset(open); - expect(reset.startsSinceUser).toBe(0); - expect(reset.open).toHaveLength(1); - expect(childRequestStateOn.reset(reset)).toBe(reset); + expect(childRequestStateOn.reset(open)).toBe(open); }); }); diff --git a/packages/shared/src/childThreads.ts b/packages/shared/src/childThreads.ts index 0084ab71d..45bb6fa1e 100644 --- a/packages/shared/src/childThreads.ts +++ b/packages/shared/src/childThreads.ts @@ -7,8 +7,6 @@ */ import { CHILD_REQUEST_NOTE_LIMIT, - CHILD_THREAD_SEND_LIMIT, - CHILD_THREAD_START_LIMIT, CHILD_THREADS_PER_CALL, type ChildRequestId, type ChildRequestNote, @@ -49,12 +47,13 @@ export interface ChildRequestCaller { } /** - * Why a call is refused: `limit` (the per-message budget is used up), - * `not_allowed` (this thread or agent may not do it), or `refused` (anything - * else, with a reason the calling agent can act on). + * Why a call is refused: `not_allowed` (this thread or agent may not do it), + * or `refused` (anything else, with a reason the calling agent can act on). + * There is no count: agents start and message as many threads as they like, + * until the user stops them (docs/design/agent-autonomy-no-limits.md). */ export interface ChildRequestRefusal { - readonly outcome: "refused" | "limit" | "not_allowed"; + readonly outcome: "refused" | "not_allowed"; readonly detail: string; } @@ -102,23 +101,6 @@ function callerRefusal( return null; } -/** Threads a project's lead chat may start, and messages it may send, per user message. */ -export const LEAD_THREAD_START_LIMIT = 10; -export const LEAD_THREAD_SEND_LIMIT = 20; - -/** - * A thread's budget for starting and messaging threads per user message. The - * project's lead chat (docs/design/lead-chat.md) gets twice the usual. - */ -export function childRequestLimits(input: { readonly isLead: boolean }): { - readonly starts: number; - readonly sends: number; -} { - return input.isLead - ? { starts: LEAD_THREAD_START_LIMIT, sends: LEAD_THREAD_SEND_LIMIT } - : { starts: CHILD_THREAD_START_LIMIT, sends: CHILD_THREAD_SEND_LIMIT }; -} - /** Why starting `count` threads is refused, or null when every rule allows it. */ export function childStartRefusal( thread: ChildRequestCaller, @@ -126,8 +108,6 @@ export function childStartRefusal( readonly from: RoomAgentRef; readonly callerTurnId: TurnId; readonly count: number; - /** The caller is its project's lead chat. */ - readonly isLead?: boolean; }, ): ChildRequestRefusal | null { const caller = callerRefusal(thread, input); @@ -151,14 +131,6 @@ export function childStartRefusal( detail: `Start between 1 and ${CHILD_THREADS_PER_CALL} threads at a time.`, }; } - const used = thread.childRequests.startsSinceUser; - const limit = childRequestLimits({ isLead: input.isLead === true }).starts; - if (used + input.count > limit) { - return { - outcome: "limit", - detail: `${input.isLead === true ? "The lead chat" : "Agents"} can start ${limit} threads per user message, and ${used} were already asked for since the user last wrote, so these were not started. Say so in your reply, and wait for the user before starting more.`, - }; - } return null; } @@ -180,8 +152,6 @@ export function childSendRefusal( input: { readonly from: RoomAgentRef; readonly callerTurnId: TurnId; - /** The caller is its project's lead chat. */ - readonly isLead?: boolean; }, ): ChildRequestRefusal | null { const caller = callerRefusal(thread, input); @@ -216,13 +186,6 @@ export function childSendRefusal( }; } } - const limit = childRequestLimits({ isLead: input.isLead === true }).sends; - if (thread.childRequests.sendsSinceUser >= limit) { - return { - outcome: "limit", - detail: `${input.isLead === true ? "The lead chat" : "Agents"} can send ${limit} messages to their threads per user message, and that many were sent since the user last wrote, so this one was not. Say so in your reply, and wait for the user before sending more.`, - }; - } return null; } @@ -418,13 +381,6 @@ export function leadPassRefusal( detail: "That thread's last turn failed. It takes work again once the user writes there.", }; } - const limit = childRequestLimits({ isLead: true }).sends; - if (lead.childRequests.sendsSinceUser >= limit) { - return { - outcome: "limit", - detail: `The lead chat can send ${limit} messages to threads per user message, and that many were sent since the user last wrote, so this one was not. Say so in your reply, and wait for the user before sending more.`, - }; - } return null; } @@ -623,13 +579,7 @@ export const childRequestStateOn = { ): OrchestrationChildRequestState => state.open.some((entry) => entry.requestId === request.requestId) ? state - : { - ...state, - open: [...state.open, request], - ...(request.kind === "start" - ? { startsSinceUser: state.startsSinceUser + 1 } - : { sendsSinceUser: state.sendsSinceUser + 1 }), - }, + : { ...state, open: [...state.open, request] }, updated: ( state: OrchestrationChildRequestState, update: { @@ -755,24 +705,20 @@ export const childRequestStateOn = { ): OrchestrationChildRequestState => state.deliveryEpoch === deliveryEpoch ? state : { ...state, deliveryEpoch }, /** - * The user wrote (or, with `keepsPassBlock`, Threadlines started a turn for - * them): the per-message counts start over, and unless kept, a pass's - * block on starting threads lifts. + * The user wrote: a pass's block on starting threads lifts. With + * `keepsPassBlock` (a turn Threadlines started for them, recorded before + * agents could message threads freely) nothing changes. */ reset: ( state: OrchestrationChildRequestState, options?: { readonly keepsPassBlock?: boolean | undefined }, ): OrchestrationChildRequestState => { const liftsBlock = state.passCeiling !== undefined && options?.keepsPassBlock !== true; - if (state.startsSinceUser === 0 && state.sendsSinceUser === 0 && !liftsBlock) { + if (!liftsBlock) { return state; } const { passCeiling: _block, ...rest } = state; - return { - ...(liftsBlock ? rest : state), - startsSinceUser: 0, - sendsSinceUser: 0, - }; + return rest; }, /** The lead chat's passes (`thread.lead-pass-recorded`); see its payload. */ leadPass: ( @@ -784,9 +730,8 @@ export const childRequestStateOn = { }, ): OrchestrationChildRequestState => { switch (pass.kind) { - case "sent": - return { ...state, sendsSinceUser: state.sendsSinceUser + 1 }; // Its mark is on the message, not on the thread's requests. + case "sent": case "not-run": return state; case "started": { diff --git a/packages/shared/src/projectLead.ts b/packages/shared/src/projectLead.ts index 6223b3d66..8fd56313e 100644 --- a/packages/shared/src/projectLead.ts +++ b/packages/shared/src/projectLead.ts @@ -5,8 +5,6 @@ */ import { CHILD_THREADS_PER_CALL, type ProjectId, type ThreadId } from "@threadlines/contracts"; -import { LEAD_THREAD_SEND_LIMIT, LEAD_THREAD_START_LIMIT } from "./childThreads.ts"; - /** What the lead rules read from a project. */ export interface LeadProject { readonly id: ProjectId; @@ -93,7 +91,7 @@ export function leadRoleText(projectTitle: string): string { "- Say in a line or two what went where. When a report comes back, tell the user what finished and what needs them. Do not repeat the report.", "- Threads you started report back by themselves. Do not poll them. A thread you did not start does not report back: the user sees its answer there.", "- Rules the user gives you for the whole project belong in a project note, so the threads you start get them.", - `- Here you may start ${LEAD_THREAD_START_LIMIT} threads (at most ${CHILD_THREADS_PER_CALL} per call) and send ${LEAD_THREAD_SEND_LIMIT} messages per user message.`, + `- Start as many threads and send as many messages as the work needs, at most ${CHILD_THREADS_PER_CALL} threads per call.`, ].join("\n"); } diff --git a/packages/shared/src/roomAgentRequests.ts b/packages/shared/src/roomAgentRequests.ts index faf2b3c8e..f1eeba0de 100644 --- a/packages/shared/src/roomAgentRequests.ts +++ b/packages/shared/src/roomAgentRequests.ts @@ -13,7 +13,6 @@ import { type RoomAgentRef, type RoomAgentRequestKind, type RoomAgentRequestOutcome, - ROOM_AGENT_REQUEST_LIMIT, type ThreadParticipantId, type TurnId, } from "@threadlines/contracts"; @@ -37,30 +36,22 @@ export interface AgentRequestInput { readonly to: RoomAgentRef; readonly callerTurnId: TurnId; readonly chainEpoch: number; - /** A review asked of several agents in one call (counts once toward the limit). */ + /** A review asked of several agents in one call. */ readonly batchId?: RoomAgentBatchId | undefined; } /** * Why a request is refused: `busy` (its agent is already answering on the - * side, or the most side answers run at once), - * `limit` (agents have used their requests until the user writes), or - * `refused` (anything else, with a reason the calling agent can act on). + * side, or the most side answers run at once), or `refused` (anything else, + * with a reason the calling agent can act on). There is no count: agents make + * as many requests of each other as they like, until the user stops them + * (docs/design/agent-autonomy-no-limits.md). */ export interface AgentRequestRefusal { - readonly outcome: "refused" | "busy" | "limit"; + readonly outcome: "refused" | "busy"; readonly detail: string; } -/** - * The room shows no notice when agents reach the limit, so the calling - * agent's reply is where the user learns a request was not made. - */ -const LIMIT_REFUSAL: AgentRequestRefusal = { - outcome: "limit", - detail: `Agents have made ${ROOM_AGENT_REQUEST_LIMIT} requests since the user last wrote, so this one was not made. Say so in your reply, and wait for the user to write before asking again.`, -}; - const sameAgent = (left: RoomAgentRef, right: RoomAgentRef) => (left.participantId ?? null) === (right.participantId ?? null); @@ -100,11 +91,6 @@ export function agentRequestRefusal( if (target !== null && !present.some((participant) => participant.id === target)) { return { outcome: "refused", detail: "That agent is not in this room." }; } - // A batch already counted is not counted, or refused, again. - const counted = input.batchId !== undefined && state.batchesSinceUser.includes(input.batchId); - if (!counted && state.requestsSinceUser >= ROOM_AGENT_REQUEST_LIMIT) { - return LIMIT_REFUSAL; - } if (input.kind !== "hand_off") { const busy = sideTurnStartRefusal(thread, input.to.participantId ?? null); if (busy !== null) return { outcome: "busy", detail: busy }; @@ -119,8 +105,8 @@ export interface AgentInviteInput { } /** - * Why an invite is refused, or null. The same holder, turn, Stop and limit - * rules as other requests; besides those, a declined invite silences invites + * Why an invite is refused, or null. The same holder, turn and Stop rules as + * other requests; besides those, a declined invite silences invites * until the user writes, and only one invite waits for the user at a time. * A side answer running is no reason: an accepted invite waits its turn. */ @@ -160,9 +146,6 @@ export function agentInviteRefusal( detail: "An invite is already waiting for the user. Wait for the user's answer.", }; } - if (state.requestsSinceUser >= ROOM_AGENT_REQUEST_LIMIT) { - return LIMIT_REFUSAL; - } if (thread.voiceActive === true) { return { outcome: "refused", detail: "Voice is on. Agents cannot invite others while it is." }; } @@ -216,16 +199,7 @@ export const agentRequestStateOn = { ): OrchestrationAgentRequestState => state.open.some((entry) => entry.requestId === request.requestId) ? state - : request.batchId !== undefined && state.batchesSinceUser.includes(request.batchId) - ? { ...state, open: [...state.open, request] } - : { - ...state, - open: [...state.open, request], - requestsSinceUser: state.requestsSinceUser + 1, - ...(request.batchId !== undefined - ? { batchesSinceUser: [...state.batchesSinceUser, request.batchId] } - : {}), - }, + : { ...state, open: [...state.open, request] }, updated: ( state: OrchestrationAgentRequestState, update: { @@ -271,18 +245,7 @@ export const agentRequestStateOn = { ): OrchestrationAgentRequestState => state.hold && state.chainEpoch === chainEpoch ? state : { ...state, hold: true, chainEpoch }, reset: (state: OrchestrationAgentRequestState): OrchestrationAgentRequestState => - !state.hold && - state.requestsSinceUser === 0 && - !state.invitesPaused && - state.batchesSinceUser.length === 0 - ? state - : { - ...state, - hold: false, - requestsSinceUser: 0, - invitesPaused: false, - batchesSinceUser: [], - }, + !state.hold && !state.invitesPaused ? state : { ...state, hold: false, invitesPaused: false }, }; /**