Push live updates to the UI while agent runs execute

Engine-side writes - hires, delegated tasks, chat messages, run state -
only reached the renderer after a run finished: the queue worker sent
one snapshot-changed at the end, and nothing fired at claim time, so
the window sat frozen for the minutes a CEO run takes unless the user
reloaded by hand. The execution service now takes a notifyDataChanged
callback, the agent loop fires it after every tool-bearing iteration,
and the worker announces the claim itself, so the UI follows the
company working in real time.
This commit is contained in:
ZacharyZhang-NY committed 2026-06-09 21:51:29 -04:00
1 parent 921c5b4456
commit de9e6a9fa3
5 files changed
+33 -10

No files matched your search

@@ -80,14 +80,21 @@ describe("agent run loop (real tool dispatch)", () => {
{ text: "Team staffed, work delegated, plan written.", toolCalls: [] },
];
let toolResultNotifications = 0;
const result = await runAgentLoop(
{ providers: fakeProvider(script), tools: { db: connection.db, organization, chat: new ChatService(connection.db) } },
{
providers: fakeProvider(script),
tools: { db: connection.db, organization, chat: new ChatService(connection.db) },
onToolResults: () => { toolResultNotifications += 1; },
},
{ orgId, providerId, workspaceId, instructions: "You are the CEO.", initialUserTurn: "Start the company.", toolContext },
);
expect(result.iterations).toBe(4);
expect(result.toolCallCount).toBe(5);
expect(result.finalText).toContain("Team staffed");
// The UI is told about new data after every tool-bearing iteration, not only at the end.
expect(toolResultNotifications).toBe(3);
const agentNames = (connection.db.prepare("select name from agents where org_id = ? order by name").all(orgId) as Array<{ name: string }>).map((r) => r.name);
expect(agentNames).toEqual(["Alex Rivera", "CEO", "Sam Lee"]);