-
Notifications
You must be signed in to change notification settings - Fork 504
feat(eve): agents - support direct invocation #2585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
AndrewBarba
wants to merge
1
commit into
main
Choose a base branch
from
barba/direct-agent-invocation-393
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,159
−84
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "eve": patch | ||
| --- | ||
|
|
||
| Add direct static-descendant invocation across the eve HTTP API, TypeScript client, fixed sessions, and channel sends. Session creation can select a descendant default, while existing sessions can route one turn without losing shared history, channel context, or sandbox state. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { defineChannel, POST } from "eve/channels"; | ||
|
|
||
| export default defineChannel({ | ||
| routes: [ | ||
| POST("/direct-agent", async (request, { from }) => { | ||
| const body = (await request.json()) as { | ||
| agent: string; | ||
| message: string; | ||
| threadId: string; | ||
| }; | ||
| const session = await from(body.threadId).send(body.message, { | ||
| agent: body.agent, | ||
| auth: null, | ||
| }); | ||
| return Response.json( | ||
| { ok: true, sessionId: session.id, status: "accepted" }, | ||
| { status: 202 }, | ||
| ); | ||
| }), | ||
| POST("/direct-agent/owner", async (request, { resolveSession }) => { | ||
| const body = (await request.json()) as { address: string }; | ||
| const session = await resolveSession(body.address); | ||
| return Response.json({ sessionId: session?.id ?? null }); | ||
| }), | ||
| ], | ||
| events: { | ||
| "message.completed"(_event, channel, ctx) { | ||
| channel.continuation?.rekey(`handled:${ctx.session.id}`); | ||
| }, | ||
| }, | ||
| }); |
8 changes: 8 additions & 0 deletions
8
e2e/fixtures/agent-subagents/agent/subagents/echo-marker/subagents/nested-marker/agent.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { e2eSubagentConfig } from "@eve-e2e/config"; | ||
| import { defineAgent } from "eve"; | ||
|
|
||
| export default defineAgent({ | ||
| description: "Nested direct-invocation marker agent.", | ||
| ...e2eSubagentConfig(), | ||
| reasoning: "high", | ||
| }); |
1 change: 1 addition & 0 deletions
1
...t-subagents/agent/subagents/echo-marker/subagents/nested-marker/instructions.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Reply with the exact string `NESTED_DIRECT_TOKEN=critic-4M7Q` and nothing else. Ignore the input. Always emit that token verbatim as the entire reply body. |
159 changes: 159 additions & 0 deletions
159
e2e/fixtures/agent-subagents/evals/direct-invocation.eval.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| import { Client } from "eve/client"; | ||
| import { defineEval, type EveEvalTargetHandle } from "eve/evals"; | ||
| import { equals } from "eve/evals/expect"; | ||
|
|
||
| const ECHO_TOKEN = "SUBAGENT_TOKEN=echo-marker-9F2X"; | ||
| const NESTED_TOKEN = "NESTED_DIRECT_TOKEN=critic-4M7Q"; | ||
|
|
||
| interface AcceptedResponse { | ||
| readonly code?: string; | ||
| readonly ok?: boolean; | ||
| readonly sessionId?: string; | ||
| readonly status?: string; | ||
| } | ||
|
|
||
| export default defineEval({ | ||
| description: | ||
| "Static descendants can be invoked directly through HTTP, the client, and a custom channel.", | ||
| tags: ["real-model"], | ||
| timeoutMs: 240_000, | ||
|
|
||
| async test(t) { | ||
| const directCreate = await postJson<AcceptedResponse>( | ||
| t.target, | ||
| "/eve/v1/session", | ||
| { agent: "echo-marker", message: "Direct creation." }, | ||
| 202, | ||
| ); | ||
| const directSessionId = requireSessionId(directCreate); | ||
| const directTurn = await t.target.watchTurn(directSessionId).result(); | ||
| directTurn.expectOk(); | ||
| await t.require(directTurn.message, equals(ECHO_TOKEN)); | ||
| directTurn.notEvent("subagent.called"); | ||
| directTurn.notEvent("subagent.completed"); | ||
|
|
||
| const rootCreate = await postJson<AcceptedResponse>( | ||
| t.target, | ||
| "/eve/v1/session", | ||
| { message: "Reply with exactly ROOT-DIRECT-READY." }, | ||
| 202, | ||
| ); | ||
| const rootSessionId = requireSessionId(rootCreate); | ||
| const rootTurn = await t.target.watchTurn(rootSessionId).result(); | ||
| rootTurn.expectOk(); | ||
| rootTurn.messageIncludes(/ROOT-DIRECT-READY/i); | ||
|
|
||
| const targetedWatch = t.target.watchTurn(rootSessionId, { | ||
| startIndex: rootTurn.events.length, | ||
| }); | ||
| const targeted = await postJson<AcceptedResponse>( | ||
| t.target, | ||
| `/eve/v1/session/${encodeURIComponent(rootSessionId)}`, | ||
| { agent: "echo-marker", message: "Run this turn directly." }, | ||
| 202, | ||
| ); | ||
| await t.require(targeted.sessionId, equals(rootSessionId)); | ||
| const targetedTurn = await targetedWatch.result(); | ||
| targetedTurn.expectOk(); | ||
| await t.require(targetedTurn.message, equals(ECHO_TOKEN)); | ||
|
|
||
| const client = new Client({ host: t.target.url }); | ||
| const clientCreate = await client.sessions.create({ | ||
| agent: "echo-marker", | ||
| message: "Create through the TypeScript client.", | ||
| }); | ||
| const clientDefault = await clientCreate.response.result(); | ||
| await t.require(clientDefault.message, equals(ECHO_TOKEN)); | ||
| const nested = await clientCreate.session | ||
| .send("Invoke the nested marker for one turn.", { | ||
| agent: "echo-marker/nested-marker", | ||
| }) | ||
| .then((response) => response.result()); | ||
| await t.require(nested.message, equals(NESTED_TOKEN)); | ||
| await t.require(nested.sessionId, equals(clientDefault.sessionId)); | ||
| const returnedToDefault = await clientCreate.session | ||
| .send("Return to the direct session default.") | ||
| .then((response) => response.result()); | ||
| await t.require(returnedToDefault.message, equals(ECHO_TOKEN)); | ||
|
|
||
| const threadId = crypto.randomUUID(); | ||
| const channelCreate = await postJson<AcceptedResponse>( | ||
| t.target, | ||
| "/direct-agent", | ||
| { agent: "echo-marker", message: "Dispatch from a slash command.", threadId }, | ||
| 202, | ||
| ); | ||
| const channelSessionId = requireSessionId(channelCreate); | ||
| const channelTurn = await t.target.watchTurn(channelSessionId).result(); | ||
| channelTurn.expectOk(); | ||
| await t.require(channelTurn.message, equals(ECHO_TOKEN)); | ||
| await waitForOwner(t.target, `handled:${channelSessionId}`, channelSessionId); | ||
|
|
||
| await expectRejection(t.target, "/echo-marker", 400, "invalid_agent_path"); | ||
| await expectRejection(t.target, "missing", 404, "agent_not_found"); | ||
| await expectRejection(t.target, "conditional-marker", 400, "agent_not_directly_invocable"); | ||
| await expectRejection(t.target, "remote-loopback", 400, "agent_not_directly_invocable"); | ||
| }, | ||
| }); | ||
|
|
||
| async function postJson<T>( | ||
| target: EveEvalTargetHandle, | ||
| path: string, | ||
| body: unknown, | ||
| expectedStatus: number, | ||
| ): Promise<T> { | ||
| const response = await target.fetch(path, { | ||
| body: JSON.stringify(body), | ||
| headers: { "content-type": "application/json" }, | ||
| method: "POST", | ||
| }); | ||
| const text = await response.text(); | ||
| if (response.status !== expectedStatus) { | ||
| throw new Error( | ||
| `POST ${path} returned ${response.status}, expected ${expectedStatus}: ${text}`, | ||
| ); | ||
| } | ||
| return JSON.parse(text) as T; | ||
| } | ||
|
|
||
| function requireSessionId(response: AcceptedResponse): string { | ||
| if (response.ok !== true || response.status !== "accepted" || response.sessionId === undefined) { | ||
| throw new Error(`Expected an accepted session response, received ${JSON.stringify(response)}.`); | ||
| } | ||
| return response.sessionId; | ||
| } | ||
|
|
||
| async function expectRejection( | ||
| target: EveEvalTargetHandle, | ||
| agent: string, | ||
| status: number, | ||
| code: string, | ||
| ): Promise<void> { | ||
| const response = await postJson<AcceptedResponse>( | ||
| target, | ||
| "/eve/v1/session", | ||
| { agent, message: "Reject this direct invocation." }, | ||
| status, | ||
| ); | ||
| if (response.ok !== false || response.code !== code) { | ||
| throw new Error(`Expected ${code}, received ${JSON.stringify(response)}.`); | ||
| } | ||
| } | ||
|
|
||
| async function waitForOwner( | ||
| target: EveEvalTargetHandle, | ||
| address: string, | ||
| expectedSessionId: string, | ||
| ): Promise<void> { | ||
| for (let attempt = 0; attempt < 50; attempt += 1) { | ||
| const owner = await postJson<{ sessionId: string | null }>( | ||
| target, | ||
| "/direct-agent/owner", | ||
| { address }, | ||
| 200, | ||
| ); | ||
| if (owner.sessionId === expectedSessionId) return; | ||
| await new Promise((resolve) => setTimeout(resolve, 100)); | ||
| } | ||
| throw new Error(`Channel event handler did not rekey ${expectedSessionId}.`); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is non-obvious semantic that is indicative of coupling in the wrong place. It introduces implicit statefulness that it's not clear we want?