Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

feat(eve): name agents and show durations on the Slack task card (#4095)

Andrew Barbace1975177153
diff --git a/.changeset/slack-task-card-clarity.md b/.changeset/slack-task-card-clarity.md
new file mode 100644
index 000000000..ddd4cd730
--- /dev/null
+++ b/.changeset/slack-task-card-clarity.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+The Slack task card now shows how long each task took, as in `Done in 1m 14s: Found three incidents.` or `Failed after 3m`, and the finished plan title includes the turn's total time. A plan whose tasks are all subagent or remote agent calls names them, as in `Asking researcher and reviewer` or `Waiting on reviewer · 1 of 2 tasks done`. The card also keeps one `block_id` for the whole turn, so rows a reader expanded can stay open as the card updates. When a turn you keep messaging starts new tasks after its earlier ones settled, eve marks the earlier card finished and posts a new card instead of updating the old one further up the thread.
diff --git a/docs/channels/slack.mdx b/docs/channels/slack.mdx
index 22f6ec7bf..b6d6a6b1c 100644
--- a/docs/channels/slack.mdx
+++ b/docs/channels/slack.mdx
@@ -482,9 +482,11 @@ Each row shows:
- **Title:** the tool's [`label.start`](/docs/tools#label-tool-activity), or the tool name. An agent task shows the agent name and the first sentence of its brief (`researcher: Find the incidents behind the checkout spike`). A task the agent hands to its own copy shows the brief alone.
- **Waiting:** while the task waits on an approval, an answer, or a sign-in, the row says so, as in `Waiting for approval`. In a DM or private channel it also shows the request's prompt; elsewhere it shows only what kind of request is waiting, since `approvalChannel` can send the request to one person. The request itself posts wherever `approvalChannel` sends it, and the row goes back to working once the request resolves.
-- **How it ended:** the first sentence of the result or the agent's reply, cut to about 100 characters, `Failed` for a failure, or a line for a cancelled task that says why it stopped. A task the model cancelled with `task_cancel` shows `Stopped early since it was no longer needed` with a success check, since the model no longer needed that work. A task stopped by [cancelling the turn](#message-hooks) shows `Stopped by request`, one stopped because its turn ended shows `Stopped when the turn ended`, and one whose run stopped on its own shows `Stopped`. Those rows and failed rows never show a success check. In a DM or private channel, a failure also shows the first sentence of its error, as in `Failed: Rate limited`. Error text can carry internal details, so everywhere else, including proactive sessions without a known `audience`, shows `Failed` alone.
+- **How it ended:** the first sentence of the result or the agent's reply, cut to about 100 characters, `Failed` for a failure, or a line for a cancelled task that says why it stopped. A task the model cancelled with `task_cancel` shows `Stopped early since it was no longer needed` with a success check, since the model no longer needed that work. A task stopped by [cancelling the turn](#message-hooks) shows `Stopped by request`, one stopped because its turn ended shows `Stopped when the turn ended`, and one whose run stopped on its own shows `Stopped`. Those rows and failed rows never show a success check. In a DM or private channel, a failure also shows the first sentence of its error, as in `Failed: Rate limited`. Error text can carry internal details, so everywhere else, including proactive sessions without a known `audience`, shows `Failed` alone. A completed or failed task that ran for a second or more also shows how long it took: `Done in 1m 14s: Found three incidents.` or `Failed after 3m`.
-The plan title summarizes the turn: `Working on 2 tasks`, `1 of 2 tasks done`, `Waiting for approval`, then `Finished 2 tasks` or `Finished 3 tasks: 1 failed, 1 stopped`. Tasks the model cancelled with `task_cancel` count as finished, not stopped. A resumable task continued in a later turn appears in that turn's card.
+The plan title summarizes the turn: `Working on 2 tasks`, `1 of 2 tasks done`, `Waiting for approval`, then `Finished 2 tasks in 3m` or `Finished 3 tasks in 5m 12s: 1 failed, 1 stopped`. When every task calls a declared subagent or remote agent, and the turn calls three or fewer of them, the title names them instead of counting: `Asking researcher and reviewer`, then `Waiting on reviewer · 1 of 2 tasks done`. Tasks the model cancelled with `task_cancel` count as finished, not stopped. A resumable task continued in a later turn appears in that turn's card.
+
+A turn stays open while its tasks work, so messages you send during that time continue the same turn. When that turn starts a task after every task on its card has settled, eve marks that card finished and posts a new card for the new work, so the new tasks don't update a card further up the thread.
eve writes the card from the session's own events as they happen, and only when it changed. A failed Slack call never fails the turn: eve tries a failed write once more after a second, then again on the turn's next change. If someone deletes the card, eve posts it again on its next change. Card posts never unfurl links. Schedule sessions and sessions without a Slack thread get no card.
@@ -551,7 +553,7 @@ export default slackChannel({
- `tasks`: the tasks the turn started, each with a `title`, `status`, `blockedOn`, and `summary`. A failed task's `summary` and a blocked task's `blockedOn.label` are present only in a DM or private channel.
- `actions`: the turn's other tool calls, each with its tool `name`, `title`, `status`, and `input`. `input` is left out when its JSON is longer than 4,096 characters.
-`taskCard` is synchronous and pure: eve posts the card and updates it as the view changes. eve's default returns `null` for a turn that started no tasks. To change a row's title in every channel, give the tool a [label](/docs/tools#label-tool-activity) instead.
+`taskCard` is synchronous and pure: eve posts the card and updates it as the view changes. eve's default returns `null` for a turn that started no tasks. Its block keeps the same `block_id` for the whole turn; keep that `block_id` on a block you build in its place. To change a row's title in every channel, give the tool a [label](/docs/tools#label-tool-activity) instead.
Renderers run in the order you list them, and the first one is outermost. `onInteraction` receives clicks on buttons a renderer posts, such as the feedback buttons above.
@@ -612,7 +614,7 @@ const plan = defineSlackRenderer({
}));
const tasks = [...planRows, ...taskRows.map(({ type: _type, ...row }) => row)];
return {
- blocks: [{ type: "plan", title: "Plan", tasks }],
+ blocks: [{ type: "plan", block_id: block?.block_id, title: "Plan", tasks }],
text: `Plan: ${items.map((item) => item.title).join(", ")}`,
};
},
diff --git a/packages/eve/src/channel/task-card.ts b/packages/eve/src/channel/task-card.ts
index 7bccc8175..4a88b9f4f 100644
--- a/packages/eve/src/channel/task-card.ts
+++ b/packages/eve/src/channel/task-card.ts
@@ -290,6 +290,25 @@ function trackTurnEvent(
}
}
+/**
+ * Splits a turn's card when the turn starts a task after every task on the
+ * card settled, which happens when the turn's caller keeps talking to an open
+ * turn. The settled calls end as their own finished card; the calls still
+ * working, including the one starting, open a new card. Returns nothing while
+ * any of the card's tasks works.
+ */
+export function closeSettledTasks(
+ turn: TaskCardTurn,
+ callId: string,
+): { readonly closed: TaskCardTurn; readonly open: TaskCardTurn } | undefined {
+ const tasks = turn.calls.filter((call) => call.task !== undefined && call.callId !== callId);
+ if (tasks.length === 0 || tasks.some((call) => call.status === "working")) return undefined;
+ return {
+ closed: { calls: turn.calls.filter((call) => call.status !== "working"), ended: true },
+ open: { calls: turn.calls.filter((call) => call.status === "working"), ended: false },
+ };
+}
+
/** The view a renderer draws one turn's card from. */
export function taskCardView(
turnId: string,
diff --git a/packages/eve/src/execution/tasks/render.ts b/packages/eve/src/execution/tasks/render.ts
index 6199e1b3c..fbedec8f1 100644
--- a/packages/eve/src/execution/tasks/render.ts
+++ b/packages/eve/src/execution/tasks/render.ts
@@ -1,4 +1,5 @@
import type { TaskCancelResult, TaskWaitResult } from "#execution/tasks/calls.js";
+import { formatDuration } from "#shared/format-duration.js";
// Every string the model reads about tasks lives in this file.
@@ -278,19 +279,6 @@ function listedTaskAttributes(task: ListedTask): string {
return `id="${escapeAttribute(task.id)}" tool="${escapeAttribute(task.tool)}"`;
}
-function formatDuration(ms: number): string {
- if (ms < 1_000) return `${String(Math.max(0, Math.round(ms)))}ms`;
- const totalSeconds = Math.round(ms / 1_000);
- const hours = Math.floor(totalSeconds / 3_600);
- const minutes = Math.floor((totalSeconds % 3_600) / 60);
- const seconds = totalSeconds % 60;
- const parts: string[] = [];
- if (hours > 0) parts.push(`${String(hours)}h`);
- if (minutes > 0) parts.push(`${String(minutes)}m`);
- if (seconds > 0) parts.push(`${String(seconds)}s`);
- return parts.join(" ");
-}
-
function joinList(items: readonly string[]): string {
if (items.length <= 1) return items.join("");
return `${items.slice(0, -1).join(", ")} and ${items.at(-1)!}`;
diff --git a/packages/eve/src/public/channels/slack/task-card.test.ts b/packages/eve/src/public/channels/slack/task-card.test.ts
index 27374a620..461e8bf09 100644
--- a/packages/eve/src/public/channels/slack/task-card.test.ts
+++ b/packages/eve/src/public/channels/slack/task-card.test.ts
@@ -228,6 +228,137 @@ describe("Slack task card", () => {
expect(cardCalls()).toHaveLength(written);
});
+ it("names the agents a turn asks, times their work, and keeps one block id across updates", async () => {
+ const start = Date.parse("2026-10-01T10:00:00.000Z");
+ vi.useFakeTimers({ now: start, toFake: ["Date"] });
+ const agents = [
+ { callId: RESEARCH_CALL, name: "researcher", taskId: "researcher-7k2m9q" },
+ { callId: "call_review", name: "reviewer", taskId: "reviewer-p3x8vd" },
+ ];
+ const { cardCalls, emit } = slackThread();
+ const plan = () => (cardCalls().at(-1)!.body["blocks"] as BlockKitBlock[])[0]!;
+
+ await emit(
+ createActionsRequestedEvent({
+ actions: agents.map(({ callId, name }) => ({
+ callId,
+ input: { message: "Look into the checkout spike." },
+ kind: "tool-call" as const,
+ toolName: name,
+ })),
+ sequence: 1,
+ stepIndex: 0,
+ turnId: TURN_ID,
+ }),
+ ...agents.map(({ callId, name, taskId }) =>
+ createTaskStartedEvent({ callId, kind: "agent", name, taskId, turnId: TURN_ID }),
+ ),
+ );
+ expect(plan()).toMatchObject({ title: "Asking researcher and reviewer", type: "plan" });
+
+ vi.setSystemTime(start + 74_000);
+ await emit(
+ createTaskSettledEvent({
+ callId: RESEARCH_CALL,
+ kind: "agent",
+ name: "researcher",
+ output: { message: "Alice found three incidents. Details follow." },
+ status: "completed",
+ taskId: "researcher-7k2m9q",
+ turnId: TURN_ID,
+ }),
+ );
+ expect(plan()).toMatchObject({
+ tasks: [
+ {
+ output: {
+ elements: [{ elements: [{ text: "Done in 1m 14s: Alice found three incidents." }] }],
+ },
+ },
+ { status: "in_progress" },
+ ],
+ title: "Waiting on reviewer · 1 of 2 tasks done",
+ });
+
+ vi.setSystemTime(start + 180_000);
+ await emit(
+ createTaskSettledEvent({
+ callId: "call_review",
+ error: { message: "Bob's review timed out." },
+ kind: "agent",
+ name: "reviewer",
+ status: "failed",
+ taskId: "reviewer-p3x8vd",
+ turnId: TURN_ID,
+ }),
+ TURN_COMPLETED,
+ );
+ expect(plan()).toMatchObject({
+ tasks: [
+ {},
+ {
+ output: {
+ elements: [{ elements: [{ text: "Failed after 3m: Bob's review timed out." }] }],
+ },
+ },
+ ],
+ title: "Finished 2 tasks in 3m: 1 failed",
+ });
+
+ const blockIds = new Set(
+ cardCalls().map((call) => (call.body["blocks"] as BlockKitBlock[])[0]!["block_id"]),
+ );
+ expect([...blockIds]).toEqual([`eve_task_card_${TURN_ID}`]);
+ });
+
+ it("finishes a card and posts a new one when an open turn starts tasks after its earlier ones settled", async () => {
+ const followUp = "call_follow_up";
+ const { cardCalls, emit } = slackThread();
+ await emit(...TWO_TASKS_STARTED, ...BOTH_TASKS_SETTLED);
+ const firstCardTs = cardCalls().at(-1)!.body["ts"];
+
+ // The person keeps talking while the turn is open, and the turn starts more work.
+ await emit(
+ createActionsRequestedEvent({
+ actions: [
+ {
+ callId: followUp,
+ input: { message: "Check whether Bob's rollback fixed checkout." },
+ kind: "tool-call",
+ toolName: "researcher",
+ },
+ ],
+ presentation: {
+ [followUp]: { label: "researcher: Check whether Bob's rollback fixed checkout" },
+ },
+ sequence: 1,
+ stepIndex: 2,
+ turnId: TURN_ID,
+ }),
+ createTaskStartedEvent({
+ callId: followUp,
+ kind: "agent",
+ name: "researcher",
+ taskId: "researcher-9w4n2c",
+ turnId: TURN_ID,
+ }),
+ );
+
+ const [closed, opened] = cardCalls().slice(-2);
+ expect(closed).toMatchObject({
+ body: { blocks: [{ title: "Finished 2 tasks: 1 failed", type: "plan" }], ts: firstCardTs },
+ operation: "chat.update",
+ });
+ expect(opened!.operation).toBe("chat.postMessage");
+ expect(opened!.body["blocks"]).toEqual([
+ expect.objectContaining({
+ status: "in_progress",
+ title: "researcher: Check whether Bob's rollback fixed checkout",
+ type: "task_card",
+ }),
+ ]);
+ });
+
it("shows a failure without its error text outside private conversations", async () => {
const { cardCalls, emit } = slackThread({ state: { ...THREAD, audience: "public" } });
diff --git a/packages/eve/src/public/channels/slack/task-card.ts b/packages/eve/src/public/channels/slack/task-card.ts
index d27405bfb..cd7283a3b 100644
--- a/packages/eve/src/public/channels/slack/task-card.ts
+++ b/packages/eve/src/public/channels/slack/task-card.ts
@@ -1,6 +1,7 @@
import { createHash } from "node:crypto";
import {
+ closeSettledTasks,
taskCardView,
trackTaskCardEvent,
type TaskCardBlocker,
@@ -22,11 +23,17 @@ import type {
SlackEventContext,
} from "#public/channels/slack/slackChannel.js";
import { normalizeChannelAudience } from "#shared/channel-audience.js";
+import { formatDuration } from "#shared/format-duration.js";
+import { AGENT_TOOL_NAME } from "#tools/framework/agent-contract.js";
const log = createLogger("slack.task-card");
/** A plan block holds at most 50 tasks. */
const MAX_PLAN_ROWS = 50;
+/** A plan title names at most this many agents before it counts tasks instead. */
+const MAX_NAMED_AGENTS = 3;
+/** Shorter work says nothing useful about time, so rows leave it out. */
+const MIN_SHOWN_DURATION_MS = 1_000;
const MAX_TITLE_LENGTH = 80;
const MAX_LINE_LENGTH = 100;
/** Unfinished turns eve keeps tracking; the oldest drop first. */
@@ -46,44 +53,89 @@ interface SlackTaskObject {
/**
* eve's default task card: a `task_card` block for one task, or a `plan` block
* for several, and no card for a turn that started none. A settled task shows
- * one line about how it ended. A task the model cancelled with `task_cancel`
- * shows as done, since it no longer needed the work; a failed task, or one
- * stopped any other way, shows as an error.
+ * one line about how it ended and how long it took. A task the model cancelled
+ * with `task_cancel` shows as done, since it no longer needed the work; a
+ * failed task, or one stopped any other way, shows as an error.
*/
export function renderDefaultSlackTaskCard(view: TaskCardView): SlackTaskCard | null {
if (view.tasks.length === 0) return null;
const rows = collapseEarlierRows(view.tasks).map(toSlackTask);
const title = planTitle(view);
+ // Slack keeps the rows a reader expanded only while the block id stays the same.
+ const block_id = slackBlockId(view.turnId);
const blocks: BlockKitBlock[] =
rows.length === 1
- ? [{ type: "task_card", ...rows[0]! }]
- : [{ type: "plan", tasks: rows, title }];
+ ? [{ block_id, type: "task_card", ...rows[0]! }]
+ : [{ block_id, type: "plan", tasks: rows, title }];
const titles = view.tasks.map((task) => task.title).join(", ");
return { blocks, text: truncateMessageText(`${title}: ${titles}`) };
}
function planTitle(view: TaskCardView): string {
+ const { tasks } = view;
if (view.state === "blocked") {
- const blocker = view.tasks.find((task) => task.blockedOn !== undefined)?.blockedOn;
+ const blocker = tasks.find((task) => task.blockedOn !== undefined)?.blockedOn;
return waitingText(blocker?.kind ?? "input");
}
- const statuses = view.tasks.map((task) => task.status);
- const total = statuses.length;
+ const total = tasks.length;
+ // One task renders as a `task_card` without a plan title, so naming it there
+ // would only repeat its row title in the notification text.
+ const names = (subset: readonly TaskCardTask[]) => (total > 1 ? agentNames(subset) : undefined);
if (view.state === "working") {
- const done = statuses.filter((status) => status !== "working" && status !== "blocked").length;
- return done === 0
- ? `Working on ${countTasks(total)}`
- : `${String(done)} of ${countTasks(total)} done`;
+ const working = tasks.filter((task) => task.status === "working");
+ const done = total - working.length;
+ if (done === 0) {
+ const asking = names(tasks);
+ return asking === undefined ? `Working on ${countTasks(total)}` : `Asking ${asking}`;
+ }
+ const progress = `${String(done)} of ${countTasks(total)} done`;
+ const waitingOn = names(working);
+ return waitingOn === undefined ? progress : `Waiting on ${waitingOn} · ${progress}`;
}
- const failed = statuses.filter((status) => status === "failed").length;
- const stopped = view.tasks.filter(isInterrupted).length;
+ const failed = tasks.filter((task) => task.status === "failed").length;
+ const stopped = tasks.filter(isInterrupted).length;
const outcomes: string[] = [];
if (failed > 0) outcomes.push(`${String(failed)} failed`);
if (stopped > 0) outcomes.push(`${String(stopped)} stopped`);
- const finished = `Finished ${countTasks(total)}`;
+ const took = turnDuration(tasks);
+ const finished = `Finished ${countTasks(total)}${took === undefined ? "" : ` in ${took}`}`;
return outcomes.length === 0 ? finished : `${finished}: ${outcomes.join(", ")}`;
}
+/**
+ * `d0`, `d0 and sre`, or `d0, sre, and index` when every task is a call to a
+ * named agent. A call to the agent's own copy, a tool task, or more than three
+ * agents falls back to a count.
+ */
+function agentNames(tasks: readonly TaskCardTask[]): string | undefined {
+ if (tasks.some((task) => task.kind !== "agent" || task.name === AGENT_TOOL_NAME)) {
+ return undefined;
+ }
+ const names = [...new Set(tasks.map((task) => task.name))];
+ if (names.length === 0 || names.length > MAX_NAMED_AGENTS) return undefined;
+ if (names.length <= 2) return names.join(" and ");
+ return `${names.slice(0, -1).join(", ")}, and ${names.at(-1)!}`;
+}
+
+/** From the first task's start to the last one's end. */
+function turnDuration(tasks: readonly TaskCardTask[]): string | undefined {
+ const ends = tasks.flatMap((task) =>
+ task.settledAt === undefined ? [] : [Date.parse(task.settledAt)],
+ );
+ if (ends.length === 0) return undefined;
+ const start = Math.min(...tasks.map((task) => Date.parse(task.startedAt)));
+ return shownDuration(Math.max(...ends) - start);
+}
+
+function taskDuration(task: TaskCardTask): string | undefined {
+ if (task.settledAt === undefined) return undefined;
+ return shownDuration(Date.parse(task.settledAt) - Date.parse(task.startedAt));
+}
+
+function shownDuration(ms: number): string | undefined {
+ return Number.isFinite(ms) && ms >= MIN_SHOWN_DURATION_MS ? formatDuration(ms) : undefined;
+}
+
/** A task stopped before it finished for any reason but the model's own `task_cancel`. */
function isInterrupted(task: TaskCardTask): boolean {
return task.status === "cancelled" && task.cancelReason !== "task_cancel";
@@ -147,11 +199,17 @@ function slackStatus(task: TaskCardTask): SlackTaskStatus {
}
function outputLine(task: TaskCardTask): string | undefined {
+ const took = taskDuration(task);
switch (task.status) {
- case "completed":
- return task.summary;
- case "failed":
- return task.summary === undefined ? "Failed" : `Failed: ${task.summary}`;
+ case "completed": {
+ if (took === undefined) return task.summary;
+ const done = `Done in ${took}`;
+ return task.summary === undefined ? done : `${done}: ${task.summary}`;
+ }
+ case "failed": {
+ const failed = took === undefined ? "Failed" : `Failed after ${took}`;
+ return task.summary === undefined ? failed : `${failed}: ${task.summary}`;
+ }
case "cancelled":
return stoppedLine(task.cancelReason);
default:
@@ -213,6 +271,10 @@ function slackTaskId(id: string): string {
return id.replace(/[^a-zA-Z0-9_-]/g, "_").slice(-200);
}
+function slackBlockId(turnId: string): string {
+ return `eve_task_card_${slackTaskId(turnId)}`;
+}
+
/** A turn's tracked calls, and the card eve last wrote for it. */
export interface SlackTaskCardState {
readonly turn: TaskCardTurn;
@@ -256,6 +318,7 @@ export function withTaskCards(
const handler = events[type] as TrackedHandler | undefined;
wrapped[type] = async (data, channel, ctx) => {
const event = { data, type } as UnstampedMessageStreamEvent;
+ if (event.type === "task.started") await closeSettledCard(channel, event.data, taskCard);
const changed = trackTaskCardEvent(
trackedTurns(channel.state),
event,
@@ -273,6 +336,32 @@ export function withTaskCards(
return { ...events, ...wrapped } as SlackChannelInternalEvents;
}
+/**
+ * Writes a turn's card one last time as finished when the turn starts a task
+ * after all of the card's tasks settled, then leaves the turn's working calls
+ * to post a new card. Without this, a turn the caller kept talking to would
+ * add its next tasks to a card far up the thread.
+ */
+async function closeSettledCard(
+ channel: SlackEventContext,
+ data: { readonly callId: string; readonly turnId: string },
+ taskCard: (view: TaskCardView) => SlackTaskCard | null,
+): Promise<void> {
+ const current = channel.state.taskCards?.[data.turnId];
+ const split = current && closeSettledTasks(current.turn, data.callId);
+ if (split === undefined) return;
+ channel.state.taskCards = {
+ ...channel.state.taskCards,
+ [data.turnId]: { ...current, turn: split.closed },
+ };
+ await writeTaskCard(channel, data.turnId, taskCard);
+ // No `ts`: the working calls post a new card, even if the closing write failed.
+ channel.state.taskCards = {
+ ...channel.state.taskCards,
+ [data.turnId]: { turn: split.open },
+ };
+}
+
function trackedTurns(state: SlackChannelState): Readonly<Record<string, TaskCardTurn>> {
return Object.fromEntries(
Object.entries(state.taskCards ?? {}).map(([turnId, card]) => [turnId, card.turn]),
diff --git a/packages/eve/src/shared/format-duration.ts b/packages/eve/src/shared/format-duration.ts
new file mode 100644
index 000000000..67c6443ae
--- /dev/null
+++ b/packages/eve/src/shared/format-duration.ts
@@ -0,0 +1,13 @@
+/** `450ms`, `14s`, `2m 14s`, `1h 3m`: whole units, leaving out the zero ones. */
+export function formatDuration(ms: number): string {
+ if (ms < 1_000) return `${String(Math.max(0, Math.round(ms)))}ms`;
+ const totalSeconds = Math.round(ms / 1_000);
+ const hours = Math.floor(totalSeconds / 3_600);
+ const minutes = Math.floor((totalSeconds % 3_600) / 60);
+ const seconds = totalSeconds % 60;
+ const parts: string[] = [];
+ if (hours > 0) parts.push(`${String(hours)}h`);
+ if (minutes > 0) parts.push(`${String(minutes)}m`);
+ if (seconds > 0) parts.push(`${String(seconds)}s`);
+ return parts.join(" ");
+}