Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

[3/6] fix(eve): drop a consumed reply's channel context with its message (#4157)

Ben Pankow285cbe6b9904
diff --git a/.changeset/consumed-answer-context.md b/.changeset/consumed-answer-context.md
new file mode 100644
index 000000000..1818a8d3f
--- /dev/null
+++ b/.changeset/consumed-answer-context.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+A plain-text reply that answers a pending `ask_question` or `ctx.ask()` question no longer leaves its channel context behind. Before, channels that attach per-message context, such as Telegram, Discord, Teams, and Twilio, added that block to history as a separate message after the answer, and the model replied to it instead of continuing from the answer.
diff --git a/packages/eve/src/public/channels/hitl-conformance.integration.test.ts b/packages/eve/src/public/channels/hitl-conformance.integration.test.ts
index 38a6a7b8d..ce0b90078 100644
--- a/packages/eve/src/public/channels/hitl-conformance.integration.test.ts
+++ b/packages/eve/src/public/channels/hitl-conformance.integration.test.ts
@@ -27,21 +27,7 @@ interface BrokenCell {
const channels: readonly {
readonly driver: () => ChannelDriver;
readonly broken?: Partial<Record<HitlRule, BrokenCell>>;
-}[] = [
- { driver: chatSdkDriver },
- { driver: slackDriver },
- {
- driver: telegramDriver,
- broken: {
- "a text reply matching an option answers the only pending question": {
- reason: "the reply's context block reaches the model as its own message after the answer",
- // The question resolves, then the bot answers the leftover context block.
- symptom:
- /Timed out waiting for ask_question to return[\s\S]*Bootstrap reply \[Tool execution\]: <telegram_context>/,
- },
- },
- },
-];
+}[] = [{ driver: chatSdkDriver }, { driver: slackDriver }, { driver: telegramDriver }];
describe.each(channels.map((entry) => ({ ...entry, name: entry.driver().name })))(
"$name HITL contract",
diff --git a/packages/eve/src/subagents/hitl-proxy.test.ts b/packages/eve/src/subagents/hitl-proxy.test.ts
index 9e5ede361..92a45d6e2 100644
--- a/packages/eve/src/subagents/hitl-proxy.test.ts
+++ b/packages/eve/src/subagents/hitl-proxy.test.ts
@@ -307,6 +307,23 @@ describe("routeDeliverPayload message resolution", () => {
]);
});
+ it("drops a consumed message's context but keeps its channel state", () => {
+ const routed = routeDeliverPayload({
+ payload: {
+ context: ["<telegram_context>\nmessage_id: 7\n</telegram_context>"],
+ message: "production",
+ state: { messageId: "7" },
+ },
+ resolveMessage: true,
+ state: askSession([["ask-1", {}]]).state,
+ });
+
+ expect(routed.forSelf).toEqual({ state: { messageId: "7" } });
+ expect(routed.forChildren[0]?.payload.inputResponses).toEqual([
+ { optionId: "2", requestId: "ask-1" },
+ ]);
+ });
+
it("answers the only pending question with free text when it allows it", () => {
const routed = routeDeliverPayload({
payload: { message: "Use the canary pool" },
diff --git a/packages/eve/src/subagents/hitl-proxy.ts b/packages/eve/src/subagents/hitl-proxy.ts
index 9ecd61775..ab3a1849c 100644
--- a/packages/eve/src/subagents/hitl-proxy.ts
+++ b/packages/eve/src/subagents/hitl-proxy.ts
@@ -133,13 +133,16 @@ interface ChildResponseBucket {
readonly routes: ProxyInputRequest[];
}
+/** Payload keys that describe the message, dropped with it when it answers a question. */
+const CONSUMED_MESSAGE_KEYS: ReadonlySet<string> = new Set(["context", "message", inputTextKey]);
+
/**
* Splits a deliver payload into parent-local and proxied-child buckets.
*
* With `resolveMessage`, a plain-text message is also resolved against pending
* `ctx.ask()` questions: when exactly one question is pending, a matching option or
- * permitted free text answers it and consumes the message. Otherwise the
- * message stays with the parent.
+ * permitted free text answers it and consumes the message along with its
+ * `context`. Otherwise the message stays with the parent.
*/
export function routeDeliverPayload(input: {
readonly allowRoute?: (requestId: string, route: ProxyInputRequest) => boolean;
@@ -262,7 +265,9 @@ export function routeDeliverPayload(input: {
if (key === "inputResponses" || value === undefined) {
continue;
}
- if ((key === "message" || key === inputTextKey) && message.consumed) continue;
+ // Channels attach per-message context, such as Telegram's sender block. Kept
+ // without its message, it would reach the model as a message of its own.
+ if (message.consumed && CONSUMED_MESSAGE_KEYS.has(key)) continue;
remainder[key] = value;
}