The Open Framework for Building Agents
import { e2eAgentConfig, e2eModel } from "@eve-e2e/config";
import { defineAgent, defineDynamic, type AgentDefinition, type DynamicResolveContext } from "eve";
const model = e2eModel();
const { experimental } = e2eAgentConfig();
/**
* Dynamic-model e2e fixture. Resolves at `step.started` so live model objects
* exercise the same selection, omission, and failure paths as gateway ids.
*/
const agent: AgentDefinition = defineAgent({
experimental,
model: defineDynamic({
events: {
"turn.started": (_event, ctx) => {
const text = lastUserText(ctx.messages);
if (text.length === 0) throw new Error("Turn resolver did not receive incoming input.");
if (
text.includes('"selected again"') &&
!ctx.messages.some((message) => message.role === "assistant")
) {
throw new Error("Turn resolver did not receive message history.");
}
// Turn selections are durable; the step resolver supplies the live mock.
return {
model: typeof model === "string" ? model : "openai/gpt-6.1-sol",
modelContextWindowTokens: 1_000_000,
};
},
"step.started": (_event, ctx) => {
const text = lastUserText(ctx.messages);
if (text.includes("[model: boom]")) {
throw new Error("intentional resolver failure");
}
if (text.includes("[model: mini]")) {
return {
model,
modelContextWindowTokens: 128_000,
};
}
if (text.includes("[model: catalog]")) {
return model;
}
if (text.includes("[model: missing]")) {
return null as never;
}
return { model, modelContextWindowTokens: 1_000_000 };
},
},
}),
});
export default agent;
function lastUserText(messages: DynamicResolveContext["messages"]): string {
for (let index = messages.length - 1; index >= 0; index -= 1) {
const message = messages[index];
if (message?.role !== "user") continue;
if (typeof message.content === "string") return message.content;
return message.content.map((part) => (part.type === "text" ? part.text : "")).join(" ");
}
return "";
}