AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(frontend): restore result cards for tools run through run_capability (#14700)
Krzysztof Czerwinski42218ba8ea19
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/components/__tests__/ChainMessageParts.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/components/__tests__/ChainMessageParts.test.tsxindex bb495b9422..96ee1269c5 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/components/__tests__/ChainMessageParts.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/components/__tests__/ChainMessageParts.test.tsx@@ -84,4 +84,63 @@ describe("ChainMessageParts", () => {expect(screen.getByTestId("expert-group").dataset.count).toBe("2");expect(screen.queryByTestId("message-part")).toBeNull();});++ it("lifts an expert approval out of the chain when it ran through run_capability", () => {+ const parts = [+ {+ type: "tool-run_capability",+ state: "input-available",+ toolCallId: "hire",+ input: { id: "tool:hire_expert", input: { name: "Researcher" } },+ },+ {+ type: "tool-run_capability",+ state: "output-available",+ toolCallId: "confirm",+ input: { id: "confirm_expert_change", input: {} },+ output: { type: "expert_change_proposed" },+ },+ ] as MessagePart[];++ render(+ <ChainMessageParts+ parts={parts}+ messageID="message"+ isCurrentlyStreaming={true}+ />,+ );++ expect(screen.queryByTestId("tool-chain")).toBeNull();+ expect(screen.getByTestId("expert-group").dataset.count).toBe("2");+ });++ it("keeps other run_capability calls in the chain", () => {+ const parts = [+ {+ type: "tool-run_capability",+ state: "output-available",+ toolCallId: "dry",+ input: { id: "tool:hire_expert", validate_only: true },+ output: {},+ },+ {+ type: "tool-run_capability",+ state: "output-available",+ toolCallId: "search",+ input: { id: "tool:web_search", input: { query: "x" } },+ output: {},+ },+ ] as MessagePart[];++ render(+ <ChainMessageParts+ parts={parts}+ messageID="message"+ isCurrentlyStreaming={false}+ />,+ );++ expect(screen.getAllByTestId("tool-chain").length).toBe(1);+ expect(screen.queryByTestId("expert-group")).toBeNull();+ });});diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/ToolResult.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/ToolResult.tsxindex a284c4bc95..627a62b06a 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/ToolResult.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/ToolResult.tsx@@ -15,6 +15,7 @@ import {SubSessionCard,} from "./AgentCards";import { BlockListCard, BlockOutputCard } from "./BlockCards";+import { capabilityTargetRow } from "./capabilityRow";import { ConsultVerdictCard } from "./ConsultCard";import { ExecutionCard } from "./ExecutionCard";import { FileDiff } from "./FileDiff";@@ -501,7 +502,10 @@ export function ToolResult({ row, readOnly = false }: Props) {);}- const card = toolCard(row, output, readOnly);+ const target = capabilityTargetRow(row);+ const card =+ toolCard(target, output, readOnly) ??+ (target === row ? null : toolCard(row, output, readOnly));if (card) return card;if (!output) return <KeyValueList value={row.output} />;@@ -515,7 +519,7 @@ export function ToolResult({ row, readOnly = false }: Props) {return <KeyValueList value={str(output, "message") ?? ""} />;return (- linkCard(data, asObject(row.input)) ??+ linkCard(data, asObject(target.input)) ??shapeCard(data) ?? <KeyValueList value={data} />);}diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/ToolResult.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/ToolResult.test.tsxindex 4993924847..d8f6155995 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/ToolResult.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/ToolResult.test.tsx@@ -1081,3 +1081,291 @@ describe("ToolResult run_capability", () => {expect(screen.getByText(/total/i)).toBeDefined();});});++describe("ToolResult deferred platform tools", () => {+ const cases: {+ tool: string;+ input: Record<string, unknown>;+ output: Record<string, unknown>;+ marker: string | RegExp;+ }[] = [+ {+ tool: "find_agent",+ input: { query: "leads" },+ output: { agents: [{ id: "lib-1", source: "library", name: "Leads" }] },+ marker: "Leads",+ },+ {+ tool: "find_library_agent",+ input: { query: "leads" },+ output: {+ agents: [{ id: "lib-2", source: "library", name: "Lib", runs: 1200 }],+ },+ marker: "1,200 runs",+ },+ {+ tool: "list_schedules",+ input: {},+ output: {+ schedules: [+ {+ name: "Daily run",+ next_run_time: "2026-08-21T10:00:00Z",+ cron: "0 10 * * *",+ kind: "copilot_turn",+ },+ ],+ },+ marker: "chat",+ },+ {+ tool: "list_folders",+ input: {},+ output: { folders: [{ name: "Marketing", agent_count: 3 }] },+ marker: "3 agents",+ },+ {+ tool: "search_docs",+ input: { query: "blocks" },+ output: {+ results: [+ {+ title: "Blocks",+ section: "Guide",+ snippet: "How blocks work",+ doc_url: "https://docs.agpt.co/blocks",+ },+ ],+ },+ marker: "How blocks work",+ },+ {+ tool: "list_skills",+ input: {},+ output: { skills: [{ name: "summarize" }, { name: "draft" }] },+ marker: "Skills",+ },+ {+ tool: "get_sub_session_result",+ input: { sub_session_id: "sub-1" },+ output: {+ status: "COMPLETED",+ response: "Everything worked",+ elapsed_seconds: 75,+ sub_autopilot_session_link: "/copilot?session=sub-1",+ },+ marker: "1m 15s",+ },+ {+ tool: "validate_agent_graph",+ input: { agent_json: {} },+ output: { valid: true },+ marker: "Graph is valid",+ },+ {+ tool: "setup_agent_webhook_trigger",+ input: { library_agent_id: "lib-1" },+ output: {+ message: "Webhook ready",+ webhook_url: "https://hooks.example.com/h1",+ },+ marker: "https://hooks.example.com/h1",+ },+ {+ tool: "setup_agent_webhook_trigger",+ input: { library_agent_id: "lib-1" },+ output: {+ message: "Connect an account",+ setup_info: { agent_id: "agent-1", agent_name: "Tracker" },+ },+ marker: "mode:trigger",+ },+ ];++ it.each(cases)(+ "renders the $tool card the same when it ran through run_capability",+ ({ tool, input, output, marker }) => {+ const direct = render(<ToolResult row={row(output, tool, input)} />);+ expect(screen.getByText(marker)).toBeDefined();+ const expected = direct.container.innerHTML;+ direct.unmount();++ const wrapped = render(+ <ToolResult+ row={row(output, "run_capability", { id: `tool:${tool}`, input })}+ />,+ );++ expect(wrapped.container.innerHTML).toBe(expected);+ },+ );++ it("keeps the open-agent link for a deferred find_agent", () => {+ render(+ <ToolResult+ row={row(+ { agents: [{ id: "lib-1", source: "library", name: "Leads" }] },+ "run_capability",+ { id: "tool:find_agent", input: { query: "leads" } },+ )}+ />,+ );++ expect(screen.getByLabelText("Open agent").getAttribute("href")).toBe(+ "/library/agents/lib-1",+ );+ });++ it("resolves a bare tool name the way the backend does", () => {+ render(+ <ToolResult+ row={row({ valid: true }, "run_capability", {+ id: "validate_agent_graph",+ input: {},+ })}+ />,+ );++ expect(screen.getByText("Graph is valid")).toBeDefined();+ });++ it("reads the nested input as the tool's input", () => {+ render(+ <ToolResult+ row={row(+ { execution_id: "exec-2", graph_id: "graph-9" },+ "run_capability",+ {+ id: "tool:schedule_agent",+ input: { username_agent_slug: "creator/scraper" },+ },+ )}+ />,+ );++ expect(screen.getByText("creator/scraper")).toBeDefined();+ });++ it.each(["delete_workspace_file", "store_skill", "validate_agent_graph"])(+ "shows the error when a deferred %s call failed",+ (tool) => {+ render(+ <ToolResult+ row={row(+ { type: "error", message: "File not found: notes.txt" },+ "run_capability",+ { id: `tool:${tool}`, input: { path: "notes.txt" } },+ )}+ />,+ );++ expect(screen.getByText("File not found: notes.txt")).toBeDefined();+ },+ );++ it("does not take an inherited object key for a tool name", () => {+ render(+ <ToolResult+ row={row({ note: "first", other: "second" }, "run_capability", {+ id: "constructor",+ input: { url: "https://nested.example.com/page" },+ })}+ />,+ );++ expect(screen.queryByText(/nested\.example\.com/)).toBeNull();+ expect(screen.getByText("first")).toBeDefined();+ });++ it("does not render a validate_only response as an execution card", () => {+ render(+ <ToolResult+ row={row({ valid: true }, "run_capability", {+ id: "tool:validate_agent_graph",+ input: {},+ validate_only: true,+ })}+ />,+ );++ expect(screen.queryByText("Graph is valid")).toBeNull();+ });++ it("does not render capability details as an execution card", () => {+ render(+ <ToolResult+ row={row(+ {+ type: "capability_details",+ message: "Validate a graph.",+ capability: { id: "tool:validate_agent_graph", kind: "tool" },+ valid: true,+ },+ "run_capability",+ { id: "tool:validate_agent_graph", input: {} },+ )}+ />,+ );++ expect(screen.queryByText("Graph is valid")).toBeNull();+ });++ it("does not render a describe_capability response as an execution card", () => {+ render(+ <ToolResult+ row={row({ valid: true }, "describe_capability", {+ id: "tool:validate_agent_graph",+ })}+ />,+ );++ expect(screen.queryByText("Graph is valid")).toBeNull();+ });++ it("leaves a resumed call alone, since it names a review and not a tool", () => {+ render(+ <ToolResult+ row={row({ valid: true }, "resume_capability", {+ review_id: "copilot-node-abc:1f",+ })}+ />,+ );++ expect(screen.queryByText("Graph is valid")).toBeNull();+ });++ it("keeps block capability rows on the block card", () => {+ render(+ <ToolResult+ row={row(+ {+ block_id: "b1",+ block_name: "Get Weather",+ outputs: { temperature: [21] },+ },+ "run_capability",+ { id: "block:b1", input: { city: "Oslo" } },+ )}+ />,+ );++ expect(screen.getByText("Get Weather")).toBeDefined();+ });++ it("keeps MCP capability rows on the MCP setup card", () => {+ render(+ <ToolResult+ row={row(+ {+ message: "Connect the tracker",+ setup_info: { agent_id: "mcp", agent_name: "Tracker" },+ },+ "run_capability",+ { id: "mcp:mcp.example.com", input: { tool: "list_issues" } },+ )}+ />,+ );++ expect(screen.getByText("mcp-setup-card")).toBeDefined();+ });+});diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/helpers.test.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/helpers.test.tsindex b95dd2f712..3d2fdde8ba 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/helpers.test.ts+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/helpers.test.ts@@ -561,6 +561,25 @@ describe("markSupersededSubSessionRows", () => {]);});+ it("supersedes the delegation card when the poll ran through run_capability", () => {+ const rows = [+ subRow("a", "delegate_to_expert", "sub-1"),+ {+ ...subRow("b", "run_capability", "sub-1"),+ input: {+ id: "tool:get_sub_session_result",+ input: { sub_session_id: "sub-1" },+ },+ },+ ];++ const marked = markSupersededSubSessionRows(rows);+ expect(marked.map((r) => r.supersededSubSession === true)).toEqual([+ true,+ false,+ ]);+ });+it("keeps the answer of a run a re-delegation reuses the session for", () => {// Re-delegation deliberately reuses the sub-session, so keying on the id// alone would drop the first run's response from the transcript.diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/capabilityRow.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/capabilityRow.tsnew file mode 100644index 0000000000..6e5abfdb1b--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/capabilityRow.ts@@ -0,0 +1,52 @@+import type { ChainRow } from "./helpers";+import { asObject, str } from "./resultHelpers";+import { COPILOT_TOOL_CATALOG } from "./toolCatalog";++const TOOL_ID_PREFIX = "tool:";++const CAPABILITY_TOOLS = new Set([+ "find_capability",+ "describe_capability",+ "run_capability",+ "resume_capability",+]);++function platformToolName(id: string): string | null {+ const key = id.trim();+ if (key.toLowerCase().startsWith(TOOL_ID_PREFIX)) {+ return key.slice(TOOL_ID_PREFIX.length).trim() || null;+ }+ return Object.hasOwn(COPILOT_TOOL_CATALOG, key) ? key : null;+}++/** A deferred platform tool runs through `run_capability`, which returns the+ * tool's own response unchanged: the row is the tool's row under another+ * name, with its arguments nested one level down. Only `run_capability` is+ * unwrapped — `describe_capability` and `validate_only` describe a call+ * instead of making it, and `resume_capability` replays block and MCP+ * reviews only, never a platform tool. A failed call stays as it is too:+ * several tool cards draw from the input alone and would hide the error. */+export function capabilityTargetRow(row: ChainRow): ChainRow {+ if (row.tool !== "run_capability") return row;+ const call = asObject(row.input);+ if (!call || call.validate_only === true) return row;+ const type = asObject(row.output)?.type;+ if (type === "capability_details" || type === "error") return row;+ const tool = platformToolName(str(call, "id") ?? "");+ if (!tool || CAPABILITY_TOOLS.has(tool)) return row;+ return { ...row, tool, input: asObject(call.input) ?? {} };+}++/** The part-level sibling of `capabilityTargetRow`, for cards that are lifted+ * out of the chain by tool name. It reads the input alone: an approval card+ * has to be on screen while the call is still pending. */+export function capabilityTargetToolName(+ type: string,+ input: unknown,+): string | null {+ if (type !== "tool-run_capability") return null;+ const call = asObject(input);+ if (!call || call.validate_only === true) return null;+ const tool = platformToolName(str(call, "id") ?? "");+ return tool && !CAPABILITY_TOOLS.has(tool) ? tool : null;+}diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/helpers.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/helpers.tsindex cf36d353a6..764145beb2 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/helpers.ts+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/helpers.ts@@ -7,6 +7,7 @@ import {getAnimationText,getToolCategory,} from "../../tools/GenericTool/helpers";+import { capabilityTargetRow, capabilityTargetToolName } from "./capabilityRow";import { type ChainCategory, getCatalogLabel } from "./toolCatalog";import { asObject, integrationIconSrc } from "./resultHelpers";@@ -42,7 +43,8 @@ const SUB_SESSION_CARD_TOOLS = new Set([]);function subSessionIdOf(row: ChainRow): string | null {- if (!row.tool || !SUB_SESSION_CARD_TOOLS.has(row.tool)) return null;+ const tool = capabilityTargetRow(row).tool;+ if (!tool || !SUB_SESSION_CARD_TOOLS.has(tool)) return null;const output = asObject(row.output);const sid = output?.sub_session_id;return typeof sid === "string" && sid ? sid : null;@@ -68,7 +70,8 @@ export function markSupersededSubSessionRows(rows: ChainRow[]): ChainRow[] {const sid = subSessionIdOf(row);if (!sid) continue;const open = openRowKey.get(sid);- if (open && !SUB_SESSION_START_TOOLS.has(row.tool ?? "")) {+ const tool = capabilityTargetRow(row).tool ?? "";+ if (open && !SUB_SESSION_START_TOOLS.has(tool)) {supersededKeys.add(open);}openRowKey.set(sid, row.key);@@ -166,10 +169,13 @@ export const EXPERT_CHANGE_TOOLS = new Set([]);export function isExpertChangePart(part: MessagePart): boolean {- return (- part.type.startsWith("tool-") &&- EXPERT_CHANGE_TOOLS.has(part.type.slice("tool-".length))+ if (!part.type.startsWith("tool-")) return false;+ if (EXPERT_CHANGE_TOOLS.has(part.type.slice("tool-".length))) return true;+ const target = capabilityTargetToolName(+ part.type,+ "input" in part ? part.input : undefined,);+ return target !== null && EXPERT_CHANGE_TOOLS.has(target);}export function isChainPart(part: MessagePart): boolean {