From 36dcec812ab5bc311a2cc9763ae663e0e871aa14 Mon Sep 17 00:00:00 2001 From: Bentlybro Date: Sat, 31 Jan 2026 10:06:28 +0000 Subject: [PATCH] Add block_name support to run_block tool and UI Updated backend and frontend to support and prefer the use of block_name when executing blocks via run_block. This improves user experience by displaying human-readable block names and aligns API usage hints and documentation accordingly. --- .../backend/api/features/chat/tools/find_block.py | 11 +++++++---- .../backend/api/features/chat/tools/models.py | 8 ++++++-- .../backend/api/features/chat/tools/run_block.py | 13 +++++++++++-- .../Chat/components/ToolCallMessage/helpers.ts | 10 ++++++++++ 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/autogpt_platform/backend/backend/api/features/chat/tools/find_block.py b/autogpt_platform/backend/backend/api/features/chat/tools/find_block.py index 7ca85961f9..f9f7fdc770 100644 --- a/autogpt_platform/backend/backend/api/features/chat/tools/find_block.py +++ b/autogpt_platform/backend/backend/api/features/chat/tools/find_block.py @@ -31,8 +31,10 @@ class FindBlockTool(BaseTool): "Search for available blocks by name or description. " "Blocks are reusable components that perform specific tasks like " "sending emails, making API calls, processing text, etc. " - "IMPORTANT: Use this tool FIRST to get the block's 'id' before calling run_block. " - "The response includes each block's id, required_inputs, and input_schema." + "IMPORTANT: Use this tool FIRST to get the block's 'id' " + "before calling run_block. " + "The response includes each block's id, required_inputs, " + "and input_schema." ) @property @@ -175,8 +177,9 @@ class FindBlockTool(BaseTool): return BlockListResponse( message=( f"Found {len(blocks)} block(s) matching '{query}'. " - "To execute a block, use run_block with the block's 'id' field " - "and provide 'input_data' matching the block's input_schema." + "To execute a block, use run_block with the block's " + "'id' and 'name' fields and provide 'input_data' " + "matching the block's input_schema." ), blocks=blocks, count=len(blocks), diff --git a/autogpt_platform/backend/backend/api/features/chat/tools/models.py b/autogpt_platform/backend/backend/api/features/chat/tools/models.py index 8552681d03..5684a32460 100644 --- a/autogpt_platform/backend/backend/api/features/chat/tools/models.py +++ b/autogpt_platform/backend/backend/api/features/chat/tools/models.py @@ -325,8 +325,12 @@ class BlockListResponse(ToolResponseBase): count: int query: str usage_hint: str = Field( - default="To execute a block, call run_block with block_id set to the block's " - "'id' field and input_data containing the required fields from input_schema." + default=( + "To execute a block, call run_block with block_id set to " + "the block's 'id' field, block_name set to the block's 'name' " + "field, and input_data containing the required fields from " + "input_schema." + ) ) diff --git a/autogpt_platform/backend/backend/api/features/chat/tools/run_block.py b/autogpt_platform/backend/backend/api/features/chat/tools/run_block.py index 3f57236564..8df68f4cc7 100644 --- a/autogpt_platform/backend/backend/api/features/chat/tools/run_block.py +++ b/autogpt_platform/backend/backend/api/features/chat/tools/run_block.py @@ -54,6 +54,14 @@ class RunBlockTool(BaseTool): "NEVER guess this - always get it from find_block first." ), }, + "block_name": { + "type": "string", + "description": ( + "The block's human-readable 'name' field from " + "find_block results. Include this for better user " + "experience." + ), + }, "input_data": { "type": "object", "description": ( @@ -200,8 +208,9 @@ class RunBlockTool(BaseTool): return SetupRequirementsResponse( message=( - f"Block '{block.name}' requires credentials that are not configured. " - "Please set up the required credentials before running this block." + f"Block '{block.name}' requires credentials that are " + "not configured. Please set up the required credentials " + "before running this block." ), session_id=session_id, setup_info=SetupInfo( diff --git a/autogpt_platform/frontend/src/components/contextual/Chat/components/ToolCallMessage/helpers.ts b/autogpt_platform/frontend/src/components/contextual/Chat/components/ToolCallMessage/helpers.ts index 2f9f50b455..b9747d9957 100644 --- a/autogpt_platform/frontend/src/components/contextual/Chat/components/ToolCallMessage/helpers.ts +++ b/autogpt_platform/frontend/src/components/contextual/Chat/components/ToolCallMessage/helpers.ts @@ -12,6 +12,7 @@ import { SquaresFourIcon, type Icon, } from "@phosphor-icons/react"; +import { beautifyString } from "@/lib/utils"; /** * Maps internal tool names to human-friendly action phrases (present continuous). @@ -108,6 +109,15 @@ export function formatToolArguments( break; case "run_block": + // Prefer block_name if provided, otherwise fall back to block_id + if (args.block_name) { + // Beautify and remove redundant "Block" suffix (same pattern as blocks menu) + const displayName = beautifyString(args.block_name as string).replace( + / Block$/, + "", + ); + return ` "${displayName}"`; + } if (args.block_id) { return ` "${args.block_id as string}"`; }