Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

3.2 KB
Raw Blame
import type { MessageStreamEvent } from "eve/client";
import { defineEval } from "eve/evals";

const SUBAGENT_TOKEN = "SUBAGENT_TOKEN=echo-marker-9F2X";
const DOUBLE_SUBAGENT_TOKEN = new RegExp(`${SUBAGENT_TOKEN}.*${SUBAGENT_TOKEN}`, "s");

function isFanOutProgram(input: unknown): boolean {
  if (typeof input !== "object" || input === null) return false;
  const js = (input as { js?: unknown }).js;
  return (
    typeof js === "string" &&
    js.includes("Promise.all") &&
    js.includes("echo-marker") &&
    js.includes("workflow alpha") &&
    js.includes("workflow beta")
  );
}

/** Generated workflow-program smoke: sandboxed JavaScript fans out durable children. */
export default defineEval({
  tags: ["real-model"],
  description:
    "Generated workflow-program smoke: model-authored JavaScript fans out two local subagent calls and combines their results.",
  async test(t) {
    const session = await t.session();
    const parent = await session.start(
      "Use the workflow tool exactly once to fan out two independent echo-marker subagent calls. In its JavaScript, create the messages 'workflow alpha' and 'workflow beta', map them through ctx.agent calls to echo-marker inside Promise.all, and return the resulting two-element array. Do not call echo-marker outside workflow. Then reply with the returned array verbatim as JSON.",
    );
    const firstStarted = await parent.waitForEvent("agent.started", {
      data: { name: "echo-marker" },
    });
    const firstChild = t.target.watchTurn(firstStarted.data.sessionId).result();
    const secondStarted = await parent.waitForEvent("agent.started", {
      data: {
        name: "echo-marker",
        sessionId: (sessionId) => sessionId !== firstStarted.data.sessionId,
      },
    });
    const secondChild = t.target.watchTurn(secondStarted.data.sessionId).result();
    const [turn, firstChildTurn, secondChildTurn] = await Promise.all([
      parent.result(),
      firstChild,
      secondChild,
    ]);
    // Each child's own turn start, not the parent's `agent.started`: the parent
    // publishes that at its next step boundary, which can be after a quick child
    // finished.
    const childStartedAt = (events: readonly MessageStreamEvent[]) =>
      (events.find((event) => event.type === "turn.started") ?? events[0])!.meta.at;
    const latestCallAt = [
      childStartedAt(firstChildTurn.events),
      childStartedAt(secondChildTurn.events),
    ]
      .sort()
      .at(-1)!;

    t.succeeded();
    t.calledTool("workflow", { input: isFanOutProgram, count: 1 });
    turn.event("agent.started", { count: 2, data: { name: "echo-marker" } });
    firstChildTurn.eventsSatisfy(
      "first child does not complete before both children start",
      (events) =>
        events.some((event) => event.type === "turn.completed" && event.meta.at > latestCallAt),
    );
    secondChildTurn.eventsSatisfy(
      "second child does not complete before both children start",
      (events) =>
        events.some((event) => event.type === "turn.completed" && event.meta.at > latestCallAt),
    );
    firstChildTurn.messageIncludes(SUBAGENT_TOKEN);
    secondChildTurn.messageIncludes(SUBAGENT_TOKEN);
    t.messageIncludes(DOUBLE_SUBAGENT_TOKEN);
    t.noFailedActions();
  },
});