Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.
Refuse a blank question put to a person, the way a blank task handed to a Bot is refused (#476)
kevina0a745ce6e09
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b1814703..73e29559 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,17 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged.## Unreleased+### A Bot cannot end its turn by asking a person nothing++`ask_person` is how a Bot stops and puts something to a person instead of guessing, and a call with+no question in it was already meant to come back as a sentence telling it to say what it needs. That+only happened when the field was missing altogether. A question that was present and empty was+carried out: the Bot was told its question had been put to somebody, its turn ended there, and the+trail took an escalation row with nothing in its question — the row an administrator counts these by,+saying a person was asked something that was never said. On a deployment whose escalation route is a+duty desk rather than the person already in the conversation, it is a page to somebody with no+question on it. A blank question is now refused with the sentence that was already written for it,+and a question typed with room around it is recorded as the question rather than as the spacing.### A routine scheduled for Sunday says Sundays, whichever number it was written withCrontab has always let Sunday be either 0 or 7, the scheduler here takes both, and a routine writtendiff --git a/server/src/agents/escalation.ts b/server/src/agents/escalation.tsindex 017c27d7..590071bc 100644--- a/server/src/agents/escalation.ts+++ b/server/src/agents/escalation.ts@@ -102,12 +102,31 @@ export function escalationTool(options: {return "That was not put to anybody: say what you need a person to answer.";}+ /*+ * A question field that is present and empty is a call with nothing in it.+ *+ * `z.string()` accepts "" and a run of spaces, so the refusal above — which is the sentence+ * written for exactly this — only ever fired when the field was missing altogether. Spelled+ * the other way it went straight through: the Bot was told its question had been put to+ * somebody, the turn ended on that, and the trail took an `agent.escalated` row with nothing+ * in its question, which is the row an operator counts escalations by. Where a route is a duty+ * desk rather than the person already here, it is a page to somebody with no question on it.+ *+ * `message_bot`, which this competes with for the same decision, refuses a blank task and says+ * so. This is the other half of that, and the trimmed text is what travels, for the same+ * reason a handoff sends the trimmed task: what was recorded should be what was asked.+ */+ const question = parsed.data.question.trim();+ if (!question) {+ return "That was not put to anybody: say what you need a person to answer.";+ }+const outcome = await route({actorId: from.actorId,botId: from.botId,...(from.threadId ? { threadId: from.threadId } : {}),runId: from.runId,- question: parsed.data.question,+ question,...(parsed.data.why ? { why: parsed.data.why } : {}),});@@ -128,7 +147,7 @@ export function escalationTool(options: {payload: {bot: from.botId,run: from.runId,- question: parsed.data.question,+ question,...(parsed.data.why ? { why: parsed.data.why } : {}),...("reached" in outcome? { reached: outcome.reached }diff --git a/server/tests/agent-escalation.test.ts b/server/tests/agent-escalation.test.tsindex d1c92eef..80ecaae6 100644--- a/server/tests/agent-escalation.test.ts+++ b/server/tests/agent-escalation.test.ts@@ -128,6 +128,58 @@ describe("asking a person", () => {expect(said).toContain("say what you need");});++ /*+ * The same call, spelled the other way.+ *+ * A question field that is present and empty is a call with nothing in it too, and the refusal+ * above is the sentence written for it. `message_bot`, the tool this competes with for the same+ * decision, refuses a blank task and says so; this is the other half of that.+ */+ test.each([+ ["an empty question", ""],+ ["a question of spaces", " "],+ ])("%s is refused as a sentence", async (_name, question) => {+ const tool = escalationTool({ from: FROM, route: askTheirOwnPerson });++ const said = await tool.execute({ question });++ expect(said).toContain("say what you need");+ expect(said).not.toContain(PUT_TO);+ });++ test("a blank question reaches nobody and leaves no row saying it did", async () => {+ const { written, store } = recorder();+ let reached = 0;+ const tool = escalationTool({+ from: FROM,+ route: async () => {+ reached += 1;+ return { reached: "the on-call engineer" };+ },+ auditStore: store,+ });++ await tool.execute({ question: " " });++ // An `agent.escalated` row with no question in it is the row an operator counts escalations by,+ // saying a person was asked something that was never said.+ expect(reached).toBe(0);+ expect(written).toEqual([]);+ });++ test("a question with room around it is recorded as the question", async () => {+ const { written, store } = recorder();+ const tool = escalationTool({+ from: FROM,+ route: askTheirOwnPerson,+ auditStore: store,+ });++ await tool.execute({ question: " which account? " });++ expect(written[0]?.payload).toMatchObject({ question: "which account?" });+ });});/*