Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
50998de
feat(core): add typed application state to the session contract
blove Nov 18, 2026
bf1780d
feat(ag-ui): type the session's state and publish it in the core view
blove Nov 18, 2026
3894f08
feat(ag-ui): make the session a core AgentSession
blove Nov 18, 2026
016a123
test(ag-ui): expect core fields on the session snapshot in the packag…
blove Nov 18, 2026
72675d9
feat(core): add interrupts, resume and child agents to the session co…
blove Nov 19, 2026
d666233
feat(langgraph): answer interrupts by id through the core resume command
blove Nov 19, 2026
50984f8
test(native-conversation): send the unmatched-id diagnostic through t…
blove Nov 19, 2026
9812d7c
Merge remote-tracking branch 'origin/main' into blove/ag-ui-typed-ses…
blove Nov 19, 2026
84473df
Merge remote-tracking branch 'origin/main' into HEAD
blove Nov 19, 2026
f43223d
Merge remote-tracking branch 'origin/main' into blove/core-interrupts…
blove Nov 19, 2026
a73307f
Merge remote-tracking branch 'origin/main' into blove/core-interrupts…
blove Nov 19, 2026
a9376fc
Merge remote-tracking branch 'origin/main' into blove/core-interrupts…
blove Nov 19, 2026
ca50ac4
Merge the final head of #1658 into blove/ag-ui-session-is-agent-session
blove Nov 19, 2026
1e81b58
Merge the squash of #1658 into blove/ag-ui-session-is-agent-session (…
blove Nov 19, 2026
2d3100d
Merge remote-tracking branch 'origin/main' into blove/ag-ui-session-i…
blove Nov 19, 2026
ef1042c
Merge branch 'blove/core-interrupts-subagents' into blove/ag-ui-core-…
blove Nov 19, 2026
6815ffd
Merge remote-tracking branch 'origin/main' into HEAD
blove Nov 19, 2026
d31ac51
docs(ag-ui): the candidate emits the core session, not a view
blove Nov 19, 2026
1b4a8f8
feat(ag-ui): answer interrupts through the core resume command and pu…
blove Nov 19, 2026
f015faf
Merge the final head of #1659 into blove/ag-ui-core-resume
blove Nov 19, 2026
251be93
Merge the squash of #1659 into blove/ag-ui-core-resume (already merge…
blove Nov 19, 2026
51833c0
Merge remote-tracking branch 'origin/main' into blove/ag-ui-core-resume
blove Nov 19, 2026
0b3b702
test(parity): list the AG-UI child projection in the reviewed candida…
blove Nov 19, 2026
6409626
feat(ag-ui): keep earlier child agents, continue a paused child, and …
blove Nov 19, 2026
eb7dec8
test(cockpit): answer the Strands fixture's pauses through the core r…
blove Nov 20, 2026
49ea704
Merge branch 'blove/ag-ui-core-resume' into blove/ag-ui-child-agents
blove Nov 20, 2026
9b74ebf
Merge the squash of #1677 into blove/ag-ui-child-agents (already merg…
blove Nov 20, 2026
fc70877
Keep the canonical demo bundle budget from main (#1679)
blove Nov 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cockpit/ag-ui/subagents/react/src/children.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ export function observeChildren(
const cards = new Map(previous.map((card) => [card.id, card]));
let unsupported = false;
try {
// Cards follow the current run; children of earlier runs are history.
const children = snapshot.subagents.filter((child) => !child.earlier);
if (
cards.size !== previous.length ||
previous.length > 100 ||
snapshot.subagents.length > 30
children.length > 30
)
throw new Error();
const attributed = new Set(
snapshot.subagents.map((child) => child.started.subagentRunId)
children.map((child) => child.started.subagentRunId)
);
if (
snapshot.transcript.some(
Expand All @@ -68,7 +70,7 @@ export function observeChildren(
)
throw new Error();
const seen = new Set<string>();
for (const child of snapshot.subagents) {
for (const child of children) {
const started = child.started;
const id = started.subagentRunId,
callId = started.parentToolCallId;
Expand Down
2 changes: 1 addition & 1 deletion cockpit/ag-ui/subagents/react/src/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function confirmParent(
if (!valid()) return;
const run = snapshot.run,
transcript = snapshot.transcript,
children = snapshot.subagents;
children = snapshot.subagents.filter((child) => !child.earlier);
if (
!valid() ||
snapshot.status !== 'idle' ||
Expand Down
27 changes: 17 additions & 10 deletions libs/ag-ui/src/runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,23 @@ const session = createSession({ threadId, url });
is sent. Each entry is the protocol's interrupt, so it has the core `id`,
`reason`, `message` and `toolCallId` and any other field the backend sent. It
is absent when nothing is waiting, and for a pause this session cannot answer.
- `subagents` lists the current run's children as core child agents: `id`,
`name`, `description`, `toolCallId`, `parentId`, `status`, and the child's own
`messages` and `toolCalls`, which the root lists do not repeat. The protocol
evidence stays on each child as `started` and `terminal`. A child with
finished evidence is `complete`, one with error evidence is `error` and
carries its message, and one with neither is `running` while the root run is
going and `unknown` after it. A child keeps its reference until its evidence,
status or records change. Children of earlier runs are bare evidence in
`earlierSubagents`. Records are matched by run id, so a later child that
reuses an id also lists the earlier child's records.
- `subagents` lists every child the session knows as a core child agent:
children of earlier root runs first, marked `earlier`, then the current run's,
each in start order. A child has `id`, `name`, `description`, `toolCallId`,
`parentId`, `status`, and its own `messages` and `toolCalls`, which the root
lists do not repeat. The protocol evidence stays on each child as `started`
and `terminal`. `earlierSubagents` still holds the earlier children's bare
evidence.
- Error evidence is `error` and carries its message. Finished evidence is
`complete`, unless the child finished `suspended`: it paused and can
continue, so it is `running` in its own run and while a later run is going,
and `unknown` once a later run ends without continuing it. A child with no
ending is `running` while the root run is going and `unknown` after it.
- A child lists the records attributed to its run id within its own run. A
child that starts again after pausing continues: it is one child, and keeps
the records from before the pause. Any other child that reuses a run id
replaces the earlier one and starts with none of its records.
- A child keeps its reference until its evidence, status or records change.
- Every publication notifies subscribers, including one that changes only
protocol evidence such as a decision or a child.
- `submit` takes text, or `{ message, state? }` with a state patch.
Expand Down
7 changes: 4 additions & 3 deletions libs/ag-ui/src/runtime/agent-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ export type SessionSnapshot<TState = unknown> = Omit<
*/
readonly interrupts?: readonly SessionInterrupt[];
/**
* The current root run's children, each with its own messages and tool
* calls and the protocol evidence it was read from. Children of earlier
* runs are in `earlierSubagents`.
* Every child agent the session knows, each with its own messages and
* tool calls and the protocol evidence it was read from: children of
* earlier root runs first, marked `earlier`, then the current run's.
* `earlierSubagents` still holds the earlier children's bare evidence.
*/
readonly subagents: readonly SessionSubagent[];
/**
Expand Down
96 changes: 96 additions & 0 deletions libs/ag-ui/src/runtime/child-projection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,102 @@ describe('core interrupts and child agents on the AG-UI snapshot', () => {
}
});

it('keeps a paused child running and continues it with its records after resume', async () => {
const fixture = bindingFixture();
try {
const run = fixture.session.submit('Book it');
const exchange = await fixture.started();
const paused = fixture.changed(
(snapshot) => snapshot.subagents[0]?.terminal !== undefined
);
exchange.emit({
type: 'SUBAGENT_STARTED',
subagentRunId: 'child',
name: 'booker',
});
exchange.emit({
type: 'TEXT_MESSAGE_START',
messageId: 'before',
role: 'assistant',
subagentRunId: 'child',
});
exchange.emit({
type: 'TEXT_MESSAGE_CONTENT',
messageId: 'before',
delta: 'Need approval',
});
exchange.emit({ type: 'TEXT_MESSAGE_END', messageId: 'before' });
exchange.emit({
type: 'SUBAGENT_FINISHED',
subagentRunId: 'child',
outcome: { type: 'suspended', interruptIds: ['approval'] },
});
await paused;
exchange.emit({
type: 'RUN_FINISHED',
threadId: exchange.body.threadId,
runId: exchange.body.runId,
outcome: {
type: 'interrupt',
interrupts: [{ id: 'approval', reason: 'approve' }],
},
});
await expect(run).resolves.toBe('paused');
// Paused is not finished: the child can continue.
expect(fixture.session.getSnapshot().subagents[0].status).toBe('running');

const resumed = fixture.session.resume([
{ interruptId: 'approval', status: 'resolved' },
]);
const next = await fixture.started(1);
// Between the answer and the child's restart it is history, still going.
expect(fixture.session.getSnapshot().subagents).toMatchObject([
{ id: 'child', status: 'running', earlier: true },
]);
const continued = fixture.changed(
(snapshot) =>
snapshot.subagents.length === 1 &&
snapshot.subagents[0].messages.length === 2
);
next.emit({
type: 'SUBAGENT_STARTED',
subagentRunId: 'child',
name: 'booker',
});
next.emit({
type: 'TEXT_MESSAGE_START',
messageId: 'after',
role: 'assistant',
subagentRunId: 'child',
});
next.emit({
type: 'TEXT_MESSAGE_CONTENT',
messageId: 'after',
delta: 'Booked',
});
next.emit({ type: 'TEXT_MESSAGE_END', messageId: 'after' });
// One child, not two, and it keeps what it said before the pause.
const child = (await continued).subagents[0];
expect(child).not.toHaveProperty('earlier');
expect(child.messages.map((message) => message.content)).toEqual([
'Need approval',
'Booked',
]);
next.emit({ type: 'SUBAGENT_FINISHED', subagentRunId: 'child' });
next.emit({
type: 'RUN_FINISHED',
threadId: next.body.threadId,
runId: next.body.runId,
});
await expect(resumed).resolves.toBe('success');
expect(fixture.session.getSnapshot().subagents[0].status).toBe(
'complete'
);
} finally {
await fixture.cleanup();
}
});

it('lists pending interrupts until an answer is sent, and answers them by id', async () => {
const fixture = bindingFixture();
try {
Expand Down
122 changes: 92 additions & 30 deletions libs/ag-ui/src/runtime/child-projection.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import type { AgentSubagent, Message, ToolCall } from '@threadplane/core';
import { projectMessages, projectToolCalls } from './message-projection.js';
import type { Observation } from './session-observation.js';
import type { SubagentObservation } from './subagents.js';
import {
currentFrom,
earlierSpan,
suspended,
type ChildSpan,
type SubagentObservation,
} from './subagents.js';
import type { Transcript } from './transcript.js';

type TranscriptRecord = Transcript[number];

/**
* One child of the current root run: the core child, with the protocol
* evidence it was read from. `messages` and `toolCalls` are the child's own
* and are not repeated in the root snapshot's. They are every transcript record
* attributed to the child's run id, so a later child that reuses an id also
* lists the earlier child's records.
* One child agent: the core child, with the protocol evidence it was read
* from. `messages` and `toolCalls` are the child's own and are not repeated in
* the root snapshot's.
*/
export type SessionSubagent = AgentSubagent & SubagentObservation;
export type SessionSubagent = AgentSubagent &
SubagentObservation & {
/** Set on a child that settled in an earlier root run or came with the thread. */
readonly earlier?: true;
};

/** A child's records read as a root transcript, so the root selectors apply. */
const unattributed = new WeakMap<TranscriptRecord, TranscriptRecord>();
Expand All @@ -29,12 +37,23 @@ function asRoot(record: TranscriptRecord): TranscriptRecord {
return known;
}

/**
* - Error evidence is `error`, and finished evidence is `complete`, unless the
* child finished `suspended`: it paused and can continue, so it is `running`
* in its own run and while a later run is going, and `unknown` once a later
* run ends without continuing it.
* - A child with no ending is `running` while the root run is going and
* `unknown` after it.
*/
function status(
evidence: SubagentObservation,
running: boolean
running: boolean,
earlier: boolean
): AgentSubagent['status'] {
if (evidence.terminal)
return evidence.terminal.type === 'SUBAGENT_ERROR' ? 'error' : 'complete';
const terminal = evidence.terminal;
if (terminal?.type === 'SUBAGENT_ERROR') return 'error';
if (terminal && !suspended(evidence)) return 'complete';
if (terminal) return running || !earlier ? 'running' : 'unknown';
return running ? 'running' : 'unknown';
}

Expand All @@ -43,35 +62,57 @@ const noMessages: readonly Message[] = Object.freeze([]);
const noCalls: readonly ToolCall[] = Object.freeze([]);

/**
* The current run's children as core children. Each keeps its reference, and
* the list keeps its own, until that child's evidence, status or transcript
* changes. `previous` is the list this function returned last.
* Every child the session knows as a core child: those of earlier root runs
* first, then the current run's, each list in start order. A current child
* replaces an earlier one with the same run ID.
*
* A child lists the records attributed to its run ID within its own run. A
* child that starts again after pausing continues, and keeps the records from
* before the pause; any other child that reuses an ID starts with none.
*
* Each child keeps its reference, and the list keeps its own, until that
* child's evidence, status or records change. `previous` is the list this
* function returned last.
*/
export function projectSubagents(
native: Observation,
previous: readonly SessionSubagent[] = none
): readonly SessionSubagent[] {
if (!native.subagents.length) return previous.length ? none : previous;
const records = new Map<string, TranscriptRecord[]>();
for (const record of native.transcript) {
const child = (record as { subagentRunId?: unknown }).subagentRunId;
if (typeof child !== 'string') continue;
const own = records.get(child);
if (own) own.push(asRoot(record));
else records.set(child, [asRoot(record)]);
}
const prior = new Map(previous.map((child) => [child.id, child]));
const current = native.subagents;
const replaced = new Set(current.map((c) => c.started.subagentRunId));
const earlier = (native.earlierSubagents ?? []).filter(
(child) => !replaced.has(child.started.subagentRunId)
);
if (!current.length && !earlier.length)
return previous.length ? none : previous;
const running = native.status === 'running';
let changed = previous.length !== native.subagents.length;
const children = native.subagents.map((evidence, index) => {
const transcript = native.transcript;
const prior = new Map(previous.map((child) => [child.id, child]));
let changed = previous.length !== earlier.length + current.length;
const project = (
evidence: SubagentObservation,
span: ChildSpan,
isEarlier: boolean,
index: number
): SessionSubagent => {
const { started, terminal } = evidence;
const id = started.subagentRunId;
const records: TranscriptRecord[] = [];
const end = Math.min(span.to ?? transcript.length, transcript.length);
for (let position = span.from; position < end; position++) {
const record = transcript[position];
if ((record as { subagentRunId?: unknown }).subagentRunId === id)
records.push(asRoot(record));
}
const before = prior.get(id);
const state = status(evidence, running);
// A child with terminal evidence streams nothing further.
const state = status(evidence, running, isEarlier);
// Only a child of the run that is going can still be streaming.
const view = {
status: state === 'running' ? ('running' as const) : ('idle' as const),
transcript: Object.freeze(records.get(id) ?? []) as Transcript,
status:
state === 'running' && running && !terminal
? ('running' as const)
: ('idle' as const),
transcript: Object.freeze(records) as Transcript,
reasoningDurations: native.reasoningDurations,
};
const messages = projectMessages(view, before?.messages ?? noMessages);
Expand All @@ -81,6 +122,7 @@ export function projectSubagents(
before.started === started &&
before.terminal === terminal &&
before.status === state &&
before.earlier === (isEarlier || undefined) &&
before.messages === messages &&
before.toolCalls === toolCalls
) {
Expand All @@ -107,7 +149,27 @@ export function projectSubagents(
typeof terminal.message === 'string' && { error: terminal.message }),
started,
...(terminal && { terminal }),
...(isEarlier && { earlier: true as const }),
}) as SessionSubagent;
});
};
const children = [
...earlier.map((child, index) =>
project(child, earlierSpan(child), true, index)
),
...current.map((child, index) =>
project(
child,
{
from: currentFrom(
child.started.subagentRunId,
current,
native.earlierSubagents
),
},
false,
earlier.length + index
)
),
];
return changed ? Object.freeze(children) : previous;
}
Loading
Loading