Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(posthog-ai): pluralize the answered question card title (#99404)

Georgiy Tarasovb43326c8f1a5
diff --git a/products/desktop/packages/agent/src/adapters/claude/conversion/tool-use-to-acp.test.ts b/products/desktop/packages/agent/src/adapters/claude/conversion/tool-use-to-acp.test.ts
index ad029570141e..9de1c681a413 100644
--- a/products/desktop/packages/agent/src/adapters/claude/conversion/tool-use-to-acp.test.ts
+++ b/products/desktop/packages/agent/src/adapters/claude/conversion/tool-use-to-acp.test.ts
@@ -33,4 +33,31 @@ describe("toolUpdateFromToolResult", () => {
]);
expect(JSON.stringify(result)).not.toContain(pdfData);
});
+
+ it.each([
+ { questionCount: 1, withText: false, title: "Question answered" },
+ { questionCount: 2, withText: false, title: "Questions answered" },
+ { questionCount: 1, withText: true, title: "Answer received" },
+ { questionCount: 2, withText: true, title: "Answers received" },
+ ])(
+ "titles an AskUserQuestion result for $questionCount question(s) with text=$withText as $title",
+ ({ questionCount, withText, title }) => {
+ const questions = Array.from({ length: questionCount }, (_, index) => ({
+ question: `Question ${index + 1}?`,
+ header: `Q${index + 1}`,
+ options: [{ label: "Yes" }, { label: "No" }],
+ }));
+
+ const result = toolUpdateFromToolResult(
+ {
+ type: "tool_result",
+ tool_use_id: "toolu_1",
+ content: withText ? [{ type: "text", text: "Yes" }] : [],
+ },
+ { name: "AskUserQuestion", input: { questions } },
+ );
+
+ expect(result.title).toBe(title);
+ },
+ );
});
diff --git a/products/desktop/packages/agent/src/adapters/claude/conversion/tool-use-to-acp.ts b/products/desktop/packages/agent/src/adapters/claude/conversion/tool-use-to-acp.ts
index ded7d47c9772..4563c0f56d92 100644
--- a/products/desktop/packages/agent/src/adapters/claude/conversion/tool-use-to-acp.ts
+++ b/products/desktop/packages/agent/src/adapters/claude/conversion/tool-use-to-acp.ts
@@ -21,6 +21,10 @@ import type {
BetaWebFetchToolResultBlockParam,
BetaWebSearchToolResultBlockParam,
} from "@anthropic-ai/sdk/resources/beta.mjs";
+import {
+ type AskUserQuestionInput,
+ normalizeAskUserQuestionInput,
+} from "../questions/utils";
const SYSTEM_REMINDER_REGEX =
/\s*<system-reminder>[\s\S]*?<\/system-reminder>/g;
@@ -723,6 +727,10 @@ export function toolUpdateFromToolResult(
return { title: "Exited Plan Mode" };
}
case "AskUserQuestion": {
+ const questions = normalizeAskUserQuestionInput(
+ (toolUse?.input ?? {}) as AskUserQuestionInput,
+ );
+ const plural = (questions?.length ?? 0) > 1;
const content = toolResult.content;
if (Array.isArray(content) && content.length > 0) {
const firstItem = content[0];
@@ -732,12 +740,12 @@ export function toolUpdateFromToolResult(
"text" in firstItem
) {
return {
- title: "Answer received",
+ title: plural ? "Answers received" : "Answer received",
content: toolContent().text(String(firstItem.text)).build(),
};
}
}
- return { title: "Question answered" };
+ return { title: plural ? "Questions answered" : "Question answered" };
}
case "WebFetch": {
const input = toolUse?.input as Record<string, unknown> | undefined;
diff --git a/products/posthog_ai/frontend/components/QuestionRenderer.test.tsx b/products/posthog_ai/frontend/components/QuestionRenderer.test.tsx
index 8da44614729c..5ed162118af4 100644
--- a/products/posthog_ai/frontend/components/QuestionRenderer.test.tsx
+++ b/products/posthog_ai/frontend/components/QuestionRenderer.test.tsx
@@ -83,6 +83,30 @@ describe('QuestionRenderer', () => {
expect(screen.queryByText('Weekly')).not.toBeInTheDocument()
})
+ it.each([
+ { count: 1, title: 'Question answered' },
+ { count: 2, title: 'Questions answered' },
+ ])(
+ 'titles a completed call with $count question(s) "$title" despite the singular agent title',
+ ({ count, title }) => {
+ const questions = Array.from({ length: count }, (_, index) => ({
+ question: `Question ${index + 1}?`,
+ header: `Q${index + 1}`,
+ multiSelect: false,
+ options: [{ label: 'Yes' }],
+ }))
+ renderCard(
+ makeMessage({
+ title: 'Question answered',
+ rawInput: { questions },
+ rawOutput: { answers: { 'Question 1?': 'Yes' } },
+ })
+ )
+
+ expect(screen.getByText(title)).toBeInTheDocument()
+ }
+ )
+
it('falls back to a joined answer string when there is no per-question map', () => {
renderCard(makeMessage({ rawOutput: { text: 'User picked Revenue' } }))
diff --git a/products/posthog_ai/frontend/components/QuestionRenderer.tsx b/products/posthog_ai/frontend/components/QuestionRenderer.tsx
index 9baf28d3b494..ed7d761feaf9 100644
--- a/products/posthog_ai/frontend/components/QuestionRenderer.tsx
+++ b/products/posthog_ai/frontend/components/QuestionRenderer.tsx
@@ -33,6 +33,15 @@ export function QuestionRenderer(props: ToolRendererProps): JSX.Element {
answer: answersByKey[question.question] ?? (index === 0 ? fallbackAnswer : null),
}))
+ // The agent titles every finished call "Question answered" whatever the question count, so the
+ // recap derives its own title from the parsed input once the call completes.
+ const title =
+ message.status === 'completed'
+ ? questions.length > 1
+ ? 'Questions answered'
+ : 'Question answered'
+ : message.title || displayName || 'Question'
+
const body = (
<div className="flex flex-col gap-3 break-words">
{entries.map((entry, index) => (
@@ -48,7 +57,7 @@ export function QuestionRenderer(props: ToolRendererProps): JSX.Element {
<ToolActivity
message={message}
icon={icon ?? <IconAI />}
- title={message.title || displayName || 'Question'}
+ title={title}
body={body}
turnComplete={turnComplete}
turnCancelled={turnCancelled}