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.
feat(backend/copilot): hide session-level dry_run from LLM (#12711)
Zamil Majdyf112555fc3ff
diff --git a/autogpt_platform/backend/backend/blocks/autopilot.py b/autogpt_platform/backend/backend/blocks/autopilot.pyindex d479169c94..81d57e2372 100644--- a/autogpt_platform/backend/backend/blocks/autopilot.py+++ b/autogpt_platform/backend/backend/blocks/autopilot.py@@ -383,7 +383,8 @@ class AutoPilotBlock(Block):sid = input_data.session_idif not sid:sid = await self.create_session(- execution_context.user_id, dry_run=input_data.dry_run+ execution_context.user_id,+ dry_run=input_data.dry_run or execution_context.dry_run,)# NOTE: No asyncio.timeout() here — the SDK manages its owndiff --git a/autogpt_platform/backend/backend/blocks/test/test_autopilot.py b/autogpt_platform/backend/backend/blocks/test/test_autopilot.pyindex 2526bf1455..a2b44ff38e 100644--- a/autogpt_platform/backend/backend/blocks/test/test_autopilot.py+++ b/autogpt_platform/backend/backend/blocks/test/test_autopilot.py@@ -175,6 +175,29 @@ class TestRunValidation:assert outputs["session_id"] == "sess-cancel"assert "cancelled" in outputs.get("error", "").lower()+ @pytest.mark.asyncio+ async def test_dry_run_inherited_from_execution_context(self, block):+ """execution_context.dry_run=True must be OR-ed into create_session dry_run+ so that nested AutoPilot sessions simulate even when input_data.dry_run=False.+ """+ mock_result = (+ "ok",+ [],+ "[]",+ "sess-dry",+ {"prompt_tokens": 0, "completion_tokens": 0, "total_tokens": 0},+ )+ block.execute_copilot = AsyncMock(return_value=mock_result)+ block.create_session = AsyncMock(return_value="sess-dry")++ input_data = block.Input(prompt="test", max_recursion_depth=3, dry_run=False)+ ctx = _make_context()+ ctx.dry_run = True # outer execution is dry_run+ async for _ in block.run(input_data, execution_context=ctx):+ pass++ block.create_session.assert_called_once_with(ctx.user_id, dry_run=True)+@pytest.mark.asyncioasync def test_existing_session_id_skips_create(self, block):"""When session_id is provided, create_session should not be called."""diff --git a/autogpt_platform/backend/backend/copilot/sdk/tool_adapter.py b/autogpt_platform/backend/backend/copilot/sdk/tool_adapter.pyindex b865d094cf..06b50f1aa2 100644--- a/autogpt_platform/backend/backend/copilot/sdk/tool_adapter.py+++ b/autogpt_platform/backend/backend/copilot/sdk/tool_adapter.py@@ -54,6 +54,13 @@ _MCP_MAX_CHARS = 500_000MCP_SERVER_NAME = "copilot"MCP_TOOL_PREFIX = f"mcp__{MCP_SERVER_NAME}__"+# Fields stripped from the MCP tool result JSON before it is forwarded to the LLM.+# These fields would reveal execution mode (e.g. dry_run) to the model.+# Stripping happens AFTER the tool output is stashed for the frontend SSE stream,+# so StreamToolOutputAvailable still receives the full output including these fields.+_STRIP_FROM_LLM: frozenset[str] = frozenset(["is_dry_run"])++# Stash for MCP tool outputs before the SDK potentially truncates them.# Keyed by tool_name → full output string. Consumed (popped) by the# response adapter when it builds StreamToolOutputAvailable.@@ -448,6 +455,126 @@ def _text_from_mcp_result(result: dict[str, Any]) -> str:_PARALLEL_ANNOTATION = ToolAnnotations(readOnlyHint=True)+def _strip_llm_fields(result: dict[str, Any]) -> dict[str, Any]:+ """Strip fields in *_STRIP_FROM_LLM* from every JSON text block in *result*.++ Called by *_truncating* AFTER the output has been stashed for the frontend+ SSE stream, so StreamToolOutputAvailable still receives the full payload+ (including ``is_dry_run``). The returned dict is what the LLM sees.++ Non-JSON blocks, non-dict JSON values, and error results are returned unchanged.++ Note: only top-level keys are stripped. Nested occurrences of _STRIP_FROM_LLM+ fields (e.g. inside an ``outputs`` sub-dict) are not removed. Current tool+ responses only set these fields at the top level.+ """+ if result.get("isError"):+ return result+ content = result.get("content", [])+ new_content = []+ for block in content:+ if isinstance(block, dict) and block.get("type") == "text":+ raw = block.get("text", "")+ # Skip JSON parse/re-serialise round-trip when no stripped field+ # appears in the raw text — fast path for the common non-dry-run case.+ if not any(field in raw for field in _STRIP_FROM_LLM):+ new_content.append(block)+ continue+ try:+ parsed = json.loads(raw)+ except json.JSONDecodeError as exc:+ logger.debug("_strip_llm_fields: skipping non-JSON block: %s", exc)+ new_content.append(block)+ continue+ if isinstance(parsed, dict):+ for field in _STRIP_FROM_LLM:+ parsed.pop(field, None)+ block = {**block, "text": json.dumps(parsed)}+ new_content.append(block)+ return {**result, "content": new_content}+++def _make_truncating_wrapper(+ fn, tool_name: str, input_schema: dict[str, Any] | None = None+):+ """Return a wrapper around *fn* that truncates output, stashes it for the+ frontend SSE stream, and strips LLM-revealing fields before returning.++ Extracted from ``create_copilot_mcp_server`` so it can be tested directly.++ WARNING: ``stash_pending_tool_output`` must be called BEFORE+ ``_strip_llm_fields`` so the frontend SSE stream receives the full payload+ (including ``is_dry_run``) while the LLM sees a cleaned version.+ Swapping this order would cause the frontend to lose ``is_dry_run``.+ """++ async def wrapper(args: dict[str, Any]) -> dict[str, Any]:+ if not args and input_schema and input_schema.get("required"):+ logger.warning(+ "[MCP] %s called with empty args (likely output "+ "token truncation) — returning guidance",+ tool_name,+ )+ return _mcp_error(+ f"Your call to {tool_name} had empty arguments — "+ f"this means your previous response was too long and "+ f"the tool call input was truncated by the API. "+ f"To fix this: break your work into smaller steps. "+ f"For large content, first write it to a file using "+ f"bash_exec with cat >> (append section by section), "+ f"then pass it via @@agptfile:filename reference. "+ f"Do NOT retry with the same approach — it will "+ f"be truncated again."+ )++ original_args = args+ stop_msg = _check_circuit_breaker(tool_name, original_args)+ if stop_msg:+ return _mcp_error(stop_msg)++ user_id, session = get_execution_context()+ if session is not None:+ try:+ args = await expand_file_refs_in_args(+ args, user_id, session, input_schema=input_schema+ )+ except FileRefExpansionError as exc:+ _record_tool_failure(tool_name, original_args)+ return _mcp_error(+ f"@@agptfile: reference could not be resolved: {exc}. "+ "Ensure the file exists before referencing it. "+ "For sandbox paths use bash_exec to verify the file exists first; "+ "for workspace files use a workspace:// URI."+ )+ result = await fn(args)+ truncated = truncate(result, _MCP_MAX_CHARS)++ if truncated.get("isError"):+ _record_tool_failure(tool_name, original_args)+ else:+ _clear_tool_failures(tool_name)++ # Stash BEFORE stripping so the frontend SSE stream receives+ # the full output including _STRIP_FROM_LLM fields (e.g. is_dry_run).+ if not truncated.get("isError"):+ text = _text_from_mcp_result(truncated)+ if text:+ stash_pending_tool_output(tool_name, text)++ # Strip is_dry_run only when the session itself is in dry_run mode.+ # In that case the LLM must not know it is simulating — it should act+ # as if every tool call produced real results.+ # In normal (non-session-dry_run) mode, is_dry_run=True is intentionally+ # left visible to the LLM so it knows a specific tool was simulated and+ # can reason about the reliability of that output.+ if session is not None and session.dry_run:+ truncated = _strip_llm_fields(truncated)++ return truncated++ return wrapper++def create_copilot_mcp_server(*, use_e2b: bool = False):"""Create an in-process MCP server configuration for CoPilot tools.@@ -464,84 +591,6 @@ def create_copilot_mcp_server(*, use_e2b: bool = False)::func:`get_sdk_disallowed_tools`."""- def _truncating(fn, tool_name: str, input_schema: dict[str, Any] | None = None):- """Wrap a tool handler so its response is truncated to stay under the- SDK's 10 MB JSON buffer, and stash the (truncated) output for the- response adapter before the SDK can apply its own head-truncation.-- Also expands ``@@agptfile:`` references in args so every registered tool- (BaseTool, E2B file tools, Read) receives resolved content uniformly.-- Applied once to every registered tool."""-- async def wrapper(args: dict[str, Any]) -> dict[str, Any]:- # Empty tool args = model's output was truncated by the API's- # max_tokens limit. Instead of letting the tool fail with a- # confusing error (and eventually tripping the circuit breaker),- # return clear guidance so the model can self-correct.- if not args and input_schema and input_schema.get("required"):- logger.warning(- "[MCP] %s called with empty args (likely output "- "token truncation) — returning guidance",- tool_name,- )- return _mcp_error(- f"Your call to {tool_name} had empty arguments — "- f"this means your previous response was too long and "- f"the tool call input was truncated by the API. "- f"To fix this: break your work into smaller steps. "- f"For large content, first write it to a file using "- f"bash_exec with cat >> (append section by section), "- f"then pass it via @@agptfile:filename reference. "- f"Do NOT retry with the same approach — it will "- f"be truncated again."- )-- # Circuit breaker: stop infinite retry loops with identical args.- # Use the original (pre-expansion) args for fingerprinting so- # check and record always use the same key — @@agptfile:- # expansion mutates args, which would cause a key mismatch.- original_args = args- stop_msg = _check_circuit_breaker(tool_name, original_args)- if stop_msg:- return _mcp_error(stop_msg)-- user_id, session = get_execution_context()- if session is not None:- try:- args = await expand_file_refs_in_args(- args, user_id, session, input_schema=input_schema- )- except FileRefExpansionError as exc:- _record_tool_failure(tool_name, original_args)- return _mcp_error(- f"@@agptfile: reference could not be resolved: {exc}. "- "Ensure the file exists before referencing it. "- "For sandbox paths use bash_exec to verify the file exists first; "- "for workspace files use a workspace:// URI."- )- result = await fn(args)- truncated = truncate(result, _MCP_MAX_CHARS)-- # Track consecutive failures for circuit breaker- if truncated.get("isError"):- _record_tool_failure(tool_name, original_args)- else:- _clear_tool_failures(tool_name)-- # Stash the text so the response adapter can forward our- # middle-out truncated version to the frontend instead of the- # SDK's head-truncated version (for outputs >~100 KB the SDK- # persists to tool-results/ with a 2 KB head-only preview).- if not truncated.get("isError"):- text = _text_from_mcp_result(truncated)- if text:- stash_pending_tool_output(tool_name, text)-- return truncated-- return wrapper-sdk_tools = []for tool_name, base_tool in TOOL_REGISTRY.items():@@ -556,7 +605,7 @@ def create_copilot_mcp_server(*, use_e2b: bool = False):base_tool.description,schema,annotations=_PARALLEL_ANNOTATION,- )(_truncating(handler, tool_name, input_schema=schema))+ )(_make_truncating_wrapper(handler, tool_name, input_schema=schema))sdk_tools.append(decorated)# E2B file tools replace SDK built-in Read/Write/Edit/Glob/Grep.@@ -567,7 +616,7 @@ def create_copilot_mcp_server(*, use_e2b: bool = False):desc,schema,annotations=_PARALLEL_ANNOTATION,- )(_truncating(handler, name))+ )(_make_truncating_wrapper(handler, name))sdk_tools.append(decorated)# Read tool for SDK-truncated tool results (always needed, read-only).@@ -576,7 +625,7 @@ def create_copilot_mcp_server(*, use_e2b: bool = False):_READ_TOOL_DESCRIPTION,_READ_TOOL_SCHEMA,annotations=_PARALLEL_ANNOTATION,- )(_truncating(_read_file_handler, _READ_TOOL_NAME))+ )(_make_truncating_wrapper(_read_file_handler, _READ_TOOL_NAME))sdk_tools.append(read_tool)return create_sdk_mcp_server(diff --git a/autogpt_platform/backend/backend/copilot/sdk/tool_adapter_test.py b/autogpt_platform/backend/backend/copilot/sdk/tool_adapter_test.pyindex 1187dcc97c..4cd398f451 100644--- a/autogpt_platform/backend/backend/copilot/sdk/tool_adapter_test.py+++ b/autogpt_platform/backend/backend/copilot/sdk/tool_adapter_test.py@@ -1,6 +1,7 @@"""Tests for tool_adapter: truncation, stash, context vars, readOnlyHint annotations."""import asyncio+import jsonfrom unittest.mock import AsyncMock, MagicMockimport pytest@@ -12,7 +13,10 @@ from backend.util.truncate import truncatefrom .tool_adapter import (_MCP_MAX_CHARS,+ _STRIP_FROM_LLM,SDK_DISALLOWED_TOOLS,+ _make_truncating_wrapper,+ _strip_llm_fields,_text_from_mcp_result,create_tool_handler,pop_pending_tool_output,@@ -419,10 +423,9 @@ class TestBug1DuplicateExecution:await _buggy_prelaunch_handler(mock_tool, pre_launch_args, dispatch_args)# BUG: pre-launch executed once + fallback executed again = 2- assert len(call_log) == 1, (- f"Expected 1 execution but got {len(call_log)} — "- f"duplicate execution bug!"- )+ assert (+ len(call_log) == 1+ ), f"Expected 1 execution but got {len(call_log)} — duplicate execution bug!"@pytest.mark.asyncioasync def test_current_code_no_duplicate(self):@@ -711,3 +714,218 @@ class TestReadFileHandlerBridge:assert result["isError"] is Falseassert len(bridge_calls) == 0assert "Sandbox copy" not in result["content"][0]["text"]+++# ---------------------------------------------------------------------------+# _STRIP_FROM_LLM / _strip_llm_fields — dry-run field stripping+# ---------------------------------------------------------------------------+++class TestStripLlmFields:+ """Regression tests for _strip_llm_fields — the guard that hides dry_run+ execution mode from the LLM.++ Strip-after-stash ordering is the core correctness guarantee: the frontend+ SSE stream receives the full payload (including is_dry_run) while the LLM+ sees a clean response without it.+ """++ def test_strip_from_llm_contains_is_dry_run(self):+ """_STRIP_FROM_LLM must include is_dry_run so the guard is active."""+ assert "is_dry_run" in _STRIP_FROM_LLM++ def test_is_dry_run_removed_from_json_text_block(self):+ """is_dry_run is stripped from a JSON text block before LLM sees it."""+ result = {+ "content": [+ {+ "type": "text",+ "text": '{"message": "ok", "is_dry_run": true, "outputs": {}}',+ }+ ],+ "isError": False,+ }+ stripped = _strip_llm_fields(result)+ parsed = json.loads(stripped["content"][0]["text"])+ assert "is_dry_run" not in parsed+ assert parsed["message"] == "ok"+ assert parsed["outputs"] == {}++ def test_other_fields_preserved_after_strip(self):+ """Stripping is_dry_run does not affect unrelated fields."""+ result = {+ "content": [+ {+ "type": "text",+ "text": '{"success": true, "is_dry_run": true, "block_id": "b1"}',+ }+ ],+ "isError": False,+ }+ stripped = _strip_llm_fields(result)+ parsed = json.loads(stripped["content"][0]["text"])+ assert parsed["success"] is True+ assert parsed["block_id"] == "b1"+ assert "is_dry_run" not in parsed++ def test_error_result_not_modified(self):+ """Error results pass through unchanged — stripping only applies on success."""+ result = {+ "content": [+ {"type": "text", "text": '{"is_dry_run": true, "error": "boom"}'}+ ],+ "isError": True,+ }+ stripped = _strip_llm_fields(result)+ parsed = json.loads(stripped["content"][0]["text"])+ assert "is_dry_run" in parsed++ def test_non_json_text_block_unchanged(self):+ """Plain-text blocks that are not valid JSON are left as-is."""+ result = {+ "content": [{"type": "text", "text": "plain text, not JSON"}],+ "isError": False,+ }+ stripped = _strip_llm_fields(result)+ assert stripped["content"][0]["text"] == "plain text, not JSON"++ def test_strip_after_stash_ordering(self):+ """Stash receives full payload (with is_dry_run); LLM result does not."""+ set_execution_context(user_id="test", session=None, sandbox=None) # type: ignore[arg-type]++ full_text = '{"message": "ok", "is_dry_run": true}'+ result = {+ "content": [{"type": "text", "text": full_text}],+ "isError": False,+ }++ # Simulate the stash-before-strip ordering in _truncating:+ # 1. Stash the FULL output (before any stripping)+ text = _text_from_mcp_result(result)+ stash_pending_tool_output("tool_x", text)++ # 2. Strip for the LLM+ llm_result = _strip_llm_fields(result)++ # Stash (frontend) still has is_dry_run+ stashed = pop_pending_tool_output("tool_x")+ assert stashed is not None+ assert "is_dry_run" in json.loads(stashed)++ # LLM result does NOT have is_dry_run+ llm_parsed = json.loads(llm_result["content"][0]["text"])+ assert "is_dry_run" not in llm_parsed++ def test_multiple_text_blocks_strips_only_json_blocks(self):+ """Mixed content array: JSON block is stripped, plain-text block is untouched."""+ result = {+ "content": [+ {+ "type": "text",+ "text": '{"message": "ok", "is_dry_run": true}',+ },+ {+ "type": "text",+ "text": "plain text block — not JSON",+ },+ {+ "type": "text",+ "text": '{"other": "data", "is_dry_run": false}',+ },+ ],+ "isError": False,+ }+ stripped = _strip_llm_fields(result)+ # First block: JSON — is_dry_run removed+ first = json.loads(stripped["content"][0]["text"])+ assert "is_dry_run" not in first+ assert first["message"] == "ok"+ # Second block: plain text — unchanged+ assert stripped["content"][1]["text"] == "plain text block — not JSON"+ # Third block: JSON — is_dry_run removed+ third = json.loads(stripped["content"][2]["text"])+ assert "is_dry_run" not in third+ assert third["other"] == "data"++ def test_non_dict_json_value_unchanged(self):+ """A JSON array or string value is valid JSON but not a dict — left as-is."""+ result = {+ "content": [+ {+ "type": "text",+ "text": '["is_dry_run", true]',+ }+ ],+ "isError": False,+ }+ stripped = _strip_llm_fields(result)+ # Not a dict, so should be returned unchanged+ assert stripped["content"][0]["text"] == '["is_dry_run", true]'++ @pytest.mark.asyncio+ async def test_truncating_wrapper_stash_then_strip_ordering(self):+ """The _make_truncating_wrapper must stash BEFORE strip so the frontend+ gets is_dry_run while the LLM return value does not.++ This test calls the ACTUAL _make_truncating_wrapper so that swapping+ the stash/strip lines in production code causes this test to fail.+ Uses a session with dry_run=True so that stripping is active.+ """+ dry_run_session = MagicMock()+ dry_run_session.dry_run = True+ set_execution_context(user_id="test", session=dry_run_session, sandbox=None, sdk_cwd="/tmp/test") # type: ignore[arg-type]++ full_payload = '{"message": "done", "is_dry_run": true}'++ async def fake_tool_fn(_args: dict) -> dict:+ return {+ "content": [{"type": "text", "text": full_payload}],+ "isError": False,+ }++ wrapper = _make_truncating_wrapper(fake_tool_fn, "fake_tool")+ llm_result = await wrapper({})++ # Stash (frontend path) must contain is_dry_run+ stashed = pop_pending_tool_output("fake_tool")+ assert stashed is not None+ assert '"is_dry_run": true' in stashed++ # LLM return value must NOT contain is_dry_run (stripped for session dry_run)+ llm_parsed = json.loads(llm_result["content"][0]["text"])+ assert "is_dry_run" not in llm_parsed+ assert llm_parsed["message"] == "done"++ @pytest.mark.asyncio+ async def test_truncating_wrapper_normal_mode_preserves_is_dry_run_for_llm(self):+ """In normal (non-session-dry_run) mode, is_dry_run=True must reach the LLM.++ When a single tool was individually dry-run but the session is not in+ dry_run mode, the LLM should see is_dry_run=True so it knows that+ specific tool result was simulated.+ """+ normal_session = MagicMock()+ normal_session.dry_run = False+ set_execution_context(user_id="test", session=normal_session, sandbox=None, sdk_cwd="/tmp/test") # type: ignore[arg-type]++ full_payload = '{"message": "simulated", "is_dry_run": true}'++ async def fake_tool_fn(_args: dict) -> dict:+ return {+ "content": [{"type": "text", "text": full_payload}],+ "isError": False,+ }++ wrapper = _make_truncating_wrapper(fake_tool_fn, "fake_tool_normal")+ llm_result = await wrapper({})++ # LLM return value MUST contain is_dry_run in normal session mode+ llm_parsed = json.loads(llm_result["content"][0]["text"])+ assert "is_dry_run" in llm_parsed+ assert llm_parsed["is_dry_run"] is True+ assert llm_parsed["message"] == "simulated"++ # Stash also still has is_dry_run (stash is always unstripped)+ stashed = pop_pending_tool_output("fake_tool_normal")+ assert stashed is not None+ assert '"is_dry_run": true' in stasheddiff --git a/autogpt_platform/backend/backend/copilot/tools/base.py b/autogpt_platform/backend/backend/copilot/tools/base.pyindex 3de0ff7c36..d61d136bb1 100644--- a/autogpt_platform/backend/backend/copilot/tools/base.py+++ b/autogpt_platform/backend/backend/copilot/tools/base.py@@ -186,7 +186,7 @@ class BaseTool:try:result = await self._execute(user_id, session, **kwargs)- raw_output = result.model_dump_json()+ raw_output = result.model_dump_json(exclude_none=True)if (len(raw_output) > _LARGE_OUTPUT_THRESHOLDdiff --git a/autogpt_platform/backend/backend/copilot/tools/models.py b/autogpt_platform/backend/backend/copilot/tools/models.pyindex 6825688ec8..bf211e2da7 100644--- a/autogpt_platform/backend/backend/copilot/tools/models.py+++ b/autogpt_platform/backend/backend/copilot/tools/models.py@@ -467,7 +467,9 @@ class BlockOutputResponse(ToolResponseBase):block_name: stroutputs: dict[str, list[Any]]success: bool = True- is_dry_run: bool = False+ is_dry_run: bool | None = (+ None # only set to True on dry-run; omitted in normal runs+ )class ReviewRequiredResponse(ToolResponseBase):diff --git a/autogpt_platform/backend/backend/copilot/tools/run_agent.py b/autogpt_platform/backend/backend/copilot/tools/run_agent.pyindex 515537e2bd..5e18120c38 100644--- a/autogpt_platform/backend/backend/copilot/tools/run_agent.py+++ b/autogpt_platform/backend/backend/copilot/tools/run_agent.py@@ -71,7 +71,7 @@ class RunAgentInput(BaseModel):cron: str = ""timezone: str = "UTC"wait_for_result: int = Field(default=0, ge=0, le=300)- dry_run: bool+ dry_run: bool = Field(default=False)@field_validator("username_agent_slug",@@ -153,14 +153,10 @@ class RunAgentTool(BaseTool):},"dry_run": {"type": "boolean",- "description": (- "When true, simulates execution using an LLM for each block "- "— no real API calls, credentials, or credits. "- "See agent_generation_guide for the full workflow."- ),+ "description": "Simulate the agent run without executing real actions (default: false). Use when testing agent behaviour or when the user explicitly asks for a dry run.",},},- "required": ["dry_run"],+ "required": [],}@property@@ -181,7 +177,8 @@ class RunAgentTool(BaseTool):validators defined in the Pydantic model."""params = RunAgentInput(**kwargs)- # Session-level dry_run forces all tool calls to use dry-run mode.+ # Session-level dry_run forces all runs to be dry. In normal sessions+ # the LLM may still request dry_run=True on individual calls.if session.dry_run:params.dry_run = Truesession_id = session.session_id@@ -374,8 +371,9 @@ class RunAgentTool(BaseTool):) -> tuple[dict[str, CredentialsMetaInput], ToolResponseBase | None]:"""Validate credentials and inputs before execution.- Dry runs skip all prerequisite gates (credentials, input prompts)- since simulate_block doesn't need real credentials or complete inputs.+ Dry runs skip all prerequisite gates (credentials, input prompts).+ The dry_run flag is read from params.dry_run (which may be set by the+ LLM per-call, or forced to True when session.dry_run is True).Returns:(graph_credentials, error_response) — error_response is None when ready.diff --git a/autogpt_platform/backend/backend/copilot/tools/run_block.py b/autogpt_platform/backend/backend/copilot/tools/run_block.pyindex 90a75284cc..070486b376 100644--- a/autogpt_platform/backend/backend/copilot/tools/run_block.py+++ b/autogpt_platform/backend/backend/copilot/tools/run_block.py@@ -49,12 +49,8 @@ class RunBlockTool(BaseTool):"type": "object","description": "Input values. Use {} first to see schema.",},- "dry_run": {- "type": "boolean",- "description": "Execute in preview mode.",- },},- "required": ["block_id", "input_data", "dry_run"],+ "required": ["block_id", "input_data"],}@property@@ -68,8 +64,7 @@ class RunBlockTool(BaseTool):*,block_id: str = "",input_data: dict | None = None,- dry_run: bool,- **kwargs,+ **kwargs, # dry_run is intentionally not accepted; read from session.dry_run) -> ToolResponseBase:"""Execute a block with the given input data.@@ -78,7 +73,6 @@ class RunBlockTool(BaseTool):session: Chat sessionblock_id: Block UUID to executeinput_data: Input values for the block- dry_run: If True, simulate execution without side effectsReturns:BlockOutputResponse: Block execution outputs@@ -88,9 +82,8 @@ class RunBlockTool(BaseTool):block_id = block_id.strip()if input_data is None:input_data = {}- # Session-level dry_run forces all tool calls to use dry-run mode.- if session.dry_run:- dry_run = True+ # Session-level flag drives dry-run mode — not exposed to the LLM.+ dry_run = session.dry_runsession_id = session.session_idif not block_id:diff --git a/autogpt_platform/backend/backend/copilot/tools/test_dry_run.py b/autogpt_platform/backend/backend/copilot/tools/test_dry_run.pyindex 6fee590478..81321fcded 100644--- a/autogpt_platform/backend/backend/copilot/tools/test_dry_run.py+++ b/autogpt_platform/backend/backend/copilot/tools/test_dry_run.py@@ -1,12 +1,10 @@"""Tests for dry-run execution mode."""-import inspectimport jsonfrom unittest.mock import AsyncMock, MagicMock, patchimport pytest-import backend.copilot.tools.run_block as run_block_modulefrom backend.copilot.tools.helpers import execute_blockfrom backend.copilot.tools.models import BlockOutputResponse, ErrorResponsefrom backend.copilot.tools.run_block import RunBlockTool@@ -266,7 +264,7 @@ async def test_execute_block_dry_run_skips_real_execution():@pytest.mark.asyncioasync def test_execute_block_dry_run_response_format():- """Dry-run response should match real execution message format and have success=True."""+ """Dry-run response should look like a normal success (no dry-run signal to LLM)."""mock_block = make_mock_block()async def fake_simulate(block, input_data):@@ -287,10 +285,41 @@ async def test_execute_block_dry_run_response_format():)assert isinstance(response, BlockOutputResponse)+ assert "[DRY RUN]" not in response.messageassert "executed successfully" in response.message- assert "[DRY RUN]" not in response.message # must not leak to LLM contextassert response.success is Trueassert response.outputs == {"result": ["simulated"]}+ # is_dry_run is present in model_dump (used by frontend SSE via StreamToolOutputAvailable).+ # tool_adapter._truncating strips it from the LLM-facing result AFTER stashing,+ # so the frontend receives it but the LLM does not.+ assert response.is_dry_run is True+ assert "is_dry_run" in response.model_dump()+ # model_dump_json excludes None fields — is_dry_run=True must still appear.+ assert '"is_dry_run"' in response.model_dump_json(exclude_none=True)+++async def test_execute_block_normal_run_omits_is_dry_run():+ """Normal (non-dry-run) BlockOutputResponse must NOT carry is_dry_run in JSON.++ The field must be absent so the frontend and LLM don't see spurious+ 'is_dry_run: false' noise on every tool call.+ """+ from backend.copilot.tools.models import BlockOutputResponse++ response = BlockOutputResponse(+ message="Block 'X' executed successfully",+ block_id="b1",+ block_name="X",+ outputs={"result": ["real"]},+ success=True,+ session_id="s1",+ # is_dry_run intentionally NOT set → stays None+ )++ assert response.is_dry_run is None+ serialized = response.model_dump_json(exclude_none=True)+ assert '"is_dry_run"' not in serialized@pytest.mark.asyncio@@ -335,31 +364,85 @@ async def test_execute_block_real_execution_unchanged():# ----------------------------------------------------------------------------def test_run_block_tool_dry_run_param():- """RunBlockTool parameters should include 'dry_run' as a required field."""+def test_run_block_tool_no_dry_run_param():+ """RunBlockTool parameters must NOT expose 'dry_run' — it's a session-level flag."""tool = RunBlockTool()params = tool.parameters- assert "dry_run" in params["properties"]- assert params["properties"]["dry_run"]["type"] == "boolean"- assert "dry_run" in params["required"]+ assert "dry_run" not in params["properties"]+++async def test_run_block_tool_uses_session_dry_run():+ """RunBlockTool._execute derives dry_run from session.dry_run, not from kwargs.++ Behavioral test: intercepts prepare_block_for_execution and captures the+ dry_run argument actually passed, asserting it matches session.dry_run+ regardless of what a hypothetical kwarg would say.+ """+ from backend.copilot.tools.run_block import RunBlockTool++ tool = RunBlockTool()+ session = MagicMock()+ session.dry_run = True+ session.session_id = "test-session-id"++ captured = {}++ async def capture_prep(**kwargs):+ captured["dry_run"] = kwargs.get("dry_run")+ # Return an error response to short-circuit execution+ from backend.copilot.tools.models import ErrorResponse++ return ErrorResponse(message="stub", session_id="test-session-id")++ with patch(+ "backend.copilot.tools.run_block.prepare_block_for_execution",+ side_effect=capture_prep,+ ):+ await tool._execute(+ user_id="user-1",+ session=session,+ block_id="block-id-123",+ input_data={},+ )++ # dry_run must come from session, not from a default or kwarg+ assert captured["dry_run"] is True-def test_run_block_tool_dry_run_calls_execute():- """RunBlockTool._execute accepts dry_run as a typed parameter.+async def test_run_block_tool_uses_session_dry_run_false():+ """RunBlockTool._execute passes dry_run=False when session.dry_run is False.- We verify the parameter exists in the signature and is forwarded to- execute_block.+ Symmetric counterpart to test_run_block_tool_uses_session_dry_run (True case)."""- source = inspect.getsource(run_block_module.RunBlockTool._execute)- # Verify dry_run is a typed parameter (not extracted from kwargs)- assert "dry_run" in source- assert "dry_run: bool" in source+ from backend.copilot.tools.run_block import RunBlockTool++ tool = RunBlockTool()+ session = MagicMock()+ session.dry_run = False+ session.session_id = "test-session-id"- # Scope to _execute method source only — module-wide search is brittle- # and can match unrelated text/comments.- source_execute = inspect.getsource(run_block_module.RunBlockTool._execute)- # Verify dry_run is passed through to execute_block call- assert "dry_run=dry_run" in source_execute+ captured = {}++ async def capture_prep(**kwargs):+ captured["dry_run"] = kwargs.get("dry_run")+ from backend.copilot.tools.models import ErrorResponse++ return ErrorResponse(message="stub", session_id="test-session-id")++ with patch(+ "backend.copilot.tools.run_block.prepare_block_for_execution",+ side_effect=capture_prep,+ ):+ await tool._execute(+ user_id="user-1",+ session=session,+ block_id="block-id-123",+ input_data={},+ )++ assert captured["dry_run"] is False@pytest.mark.asyncio@@ -623,3 +706,158 @@ async def test_simulate_agent_output_block_no_name():outputs.append((name, data))assert outputs == [("output", 42)]+++# ---------------------------------------------------------------------------+# RunAgentTool session-level dry_run override tests+# ---------------------------------------------------------------------------+++def _make_dry_run_session(dry_run: bool = True) -> MagicMock:+ """Return a minimal ChatSession mock with dry_run set."""+ session = MagicMock()+ session.dry_run = dry_run+ session.session_id = "test-session-id"+ session.successful_agent_runs = {}+ return session+++def _make_graph_mock(graph_id: str = "g1") -> MagicMock:+ """Return a minimal GraphModel mock."""+ graph = MagicMock()+ graph.id = graph_id+ graph.name = "Test Agent"+ graph.version = 1+ graph.description = "A test agent"+ graph.input_schema = {"type": "object", "properties": {}, "required": []}+ graph.credentials_input_schema = {"type": "object", "properties": {}}+ graph.trigger_setup_info = None+ return graph+++async def test_run_agent_session_dry_run_overrides_kwargs():+ """session.dry_run=True must override any dry_run=False from LLM kwargs.++ The LLM can pass dry_run=False, but when the session is a dry-run session,+ the session-level flag wins and forces dry_run=True for all runs.+ """+ from backend.copilot.tools.run_agent import RunAgentTool++ tool = RunAgentTool()+ session = _make_dry_run_session(dry_run=True)+ graph = _make_graph_mock()++ captured_params = {}++ async def capture_prerequisites(graph, user_id, params, session_id):+ captured_params["dry_run"] = params.dry_run+ return {}, None++ with patch(+ "backend.copilot.tools.run_agent.fetch_graph_from_store_slug",+ new_callable=AsyncMock,+ return_value=(graph, None),+ ), patch.object(+ tool, "_check_prerequisites", side_effect=capture_prerequisites+ ), patch.object(+ tool, "_run_agent", new_callable=AsyncMock+ ) as mock_run_agent:+ mock_run_agent.return_value = MagicMock()++ # Pass dry_run=False in kwargs — session.dry_run=True should win.+ await tool._execute(+ user_id="user-1",+ session=session,+ username_agent_slug="user/agent",+ dry_run=False, # LLM would pass this; session should override it+ )++ # Session-level flag must have overridden the False kwarg+ assert captured_params["dry_run"] is True+++async def test_run_agent_session_dry_run_false_allows_scheduling():+ """session.dry_run=False must pass dry_run=False through to _check_prerequisites.++ Verifies that when the session is not a dry run, params.dry_run=False+ is what reaches the prerequisite check — not some stale True value.+ """+ from backend.copilot.tools.run_agent import RunAgentTool++ tool = RunAgentTool()+ session = _make_dry_run_session(dry_run=False)+ graph = _make_graph_mock()++ captured_params = {}++ async def capture_prerequisites(graph, user_id, params, session_id):+ captured_params["dry_run"] = params.dry_run+ return {}, None++ with patch(+ "backend.copilot.tools.run_agent.fetch_graph_from_store_slug",+ new_callable=AsyncMock,+ return_value=(graph, None),+ ), patch.object(+ tool, "_check_prerequisites", side_effect=capture_prerequisites+ ), patch.object(+ tool, "_schedule_agent", new_callable=AsyncMock+ ) as mock_schedule:+ mock_schedule.return_value = MagicMock()++ await tool._execute(+ user_id="user-1",+ session=session,+ username_agent_slug="user/agent",+ schedule_name="daily",+ cron="0 9 * * *",+ )++ # Non-dry-run session must propagate dry_run=False+ assert captured_params["dry_run"] is False+++async def test_run_agent_session_dry_run_false_allows_llm_dry_run_true():+ """session.dry_run=False must NOT override an explicit dry_run=True kwarg.++ In a normal session the LLM can still request a dry run on individual+ run_agent calls (e.g. "test this agent without executing it").+ Only session.dry_run=True forces dry_run — the False value does not force+ the opposite direction.+ """+ from backend.copilot.tools.run_agent import RunAgentTool++ tool = RunAgentTool()+ session = _make_dry_run_session(dry_run=False)+ graph = _make_graph_mock()++ captured_params = {}++ async def capture_prerequisites(graph, user_id, params, session_id):+ captured_params["dry_run"] = params.dry_run+ return {}, None++ with patch(+ "backend.copilot.tools.run_agent.fetch_graph_from_store_slug",+ new_callable=AsyncMock,+ return_value=(graph, None),+ ), patch.object(+ tool, "_check_prerequisites", side_effect=capture_prerequisites+ ), patch.object(+ tool, "_run_agent", new_callable=AsyncMock+ ) as mock_run_agent:+ mock_run_agent.return_value = MagicMock()++ # LLM passes dry_run=True; normal session must NOT override it to False+ await tool._execute(+ user_id="user-1",+ session=session,+ username_agent_slug="user/agent",+ dry_run=True,+ )++ # LLM-requested dry_run=True is preserved in a normal session+ assert captured_params["dry_run"] is Truediff --git a/autogpt_platform/backend/test/copilot/dry_run_loop_test.py b/autogpt_platform/backend/test/copilot/dry_run_loop_test.pyindex b55a050fd2..96c2c73cb0 100644--- a/autogpt_platform/backend/test/copilot/dry_run_loop_test.py+++ b/autogpt_platform/backend/test/copilot/dry_run_loop_test.py@@ -73,24 +73,36 @@ class TestSystemPromptBasics:class TestToolDescriptionsDryRunLoop:- """Verify tool descriptions and parameters related to the dry-run loop."""+ """Verify tool descriptions and parameters related to the dry-run loop.++ After the session-level dry_run refactor, dry_run is NOT exposed in any+ LLM tool schema — it is set at the session level and derived by each tool+ from session.dry_run. These tests verify that the schema is clean and that+ the guide still documents the dry-run workflow.+ """def test_get_agent_building_guide_mentions_workflow(self):desc = TOOL_REGISTRY["get_agent_building_guide"].descriptionassert "dry-run" in desc.lower()- def test_run_agent_dry_run_param_exists_and_is_boolean(self):+ def test_run_agent_dry_run_in_llm_schema(self):+ """dry_run must be in the run_agent LLM schema so the LLM can request+ per-call dry runs in normal sessions (e.g. "test this agent")."""schema = TOOL_REGISTRY["run_agent"].as_openai_tool()params = cast(dict[str, Any], schema["function"].get("parameters", {}))- assert "dry_run" in params["properties"]- assert params["properties"]["dry_run"]["type"] == "boolean"+ assert "dry_run" in params.get("properties", {}), (+ "dry_run must be exposed in the run_agent LLM schema so the LLM "+ "can request per-call dry runs in normal sessions"+ )- def test_run_agent_dry_run_param_mentions_simulation(self):- """After deduplication the dry_run param description mentions simulation."""- schema = TOOL_REGISTRY["run_agent"].as_openai_tool()+ def test_run_block_dry_run_not_in_llm_schema(self):+ """dry_run must NOT be in the run_block LLM schema — it is session-level."""+ schema = TOOL_REGISTRY["run_block"].as_openai_tool()params = cast(dict[str, Any], schema["function"].get("parameters", {}))- dry_run_desc = params["properties"]["dry_run"]["description"]- assert "simulat" in dry_run_desc.lower()+ assert "dry_run" not in params.get("properties", {}), (+ "dry_run must not be exposed in the run_block LLM schema; "+ "it is controlled at the session level"+ )class TestPromptingSupplementContent:@@ -156,11 +168,11 @@ class TestAgentBuildingGuideDryRunLoop:class TestRunAgentToolSchema:- """Validate the run_agent OpenAI tool schema exposes dry_run correctly.+ """Validate the run_agent OpenAI tool schema is clean of session-level fields.- These go beyond substring checks — they verify the full schema structure- that the LLM receives, ensuring the parameter is well-formed and will be- parsed correctly by OpenAI function-calling.+ After the session-level dry_run refactor, dry_run is NOT exposed in the LLM+ schema — it is set at the session level and applied by _execute. These tests+ verify the full schema structure that the LLM receives."""@pytest.fixture@@ -177,36 +189,28 @@ class TestRunAgentToolSchema:assert "parameters" in funcassert func["name"] == "run_agent"- def test_dry_run_is_required(self, schema: ChatCompletionToolParam):- """dry_run must be in 'required' so the LLM always provides it explicitly."""- params = cast(dict[str, Any], schema["function"].get("parameters", {}))- required = params.get("required", [])- assert "dry_run" in required-- def test_dry_run_is_boolean_type(self, schema: ChatCompletionToolParam):- """dry_run must be typed as boolean so the LLM generates true/false."""+ def test_dry_run_in_llm_schema(self, schema: ChatCompletionToolParam):+ """dry_run must be in the run_agent LLM schema so the LLM can request+ per-call dry runs in normal sessions."""params = cast(dict[str, Any], schema["function"].get("parameters", {}))- assert params["properties"]["dry_run"]["type"] == "boolean"-- def test_dry_run_description_is_nonempty(self, schema: ChatCompletionToolParam):- """The description must be present and substantive for LLM guidance."""- params = cast(dict[str, Any], schema["function"].get("parameters", {}))- desc = params["properties"]["dry_run"]["description"]- assert isinstance(desc, str)- assert len(desc) > 10, "Description too short to guide the LLM"-- def test_wait_for_result_coexists_with_dry_run(- self, schema: ChatCompletionToolParam- ):- """wait_for_result must also be present — the guide instructs the LLM- to pass both dry_run=True and wait_for_result=120 together."""+ assert "dry_run" in params.get(+ "properties", {}+ ), "dry_run must be exposed in the run_agent LLM schema"+ assert "dry_run" not in params.get("required", [])++ def test_wait_for_result_in_schema(self, schema: ChatCompletionToolParam):+ """wait_for_result must be present — the guide instructs the LLM+ to pass wait_for_result=120 during dry-run verification."""params = cast(dict[str, Any], schema["function"].get("parameters", {}))assert "wait_for_result" in params["properties"]assert params["properties"]["wait_for_result"]["type"] == "integer"class TestRunBlockToolSchema:- """Validate the run_block OpenAI tool schema exposes dry_run correctly."""+ """Validate the run_block OpenAI tool schema is clean of session-level fields.++ After the session-level dry_run refactor, dry_run is NOT in the LLM schema.+ """@pytest.fixturedef schema(self) -> ChatCompletionToolParam:@@ -218,30 +222,24 @@ class TestRunBlockToolSchema:assert func["name"] == "run_block"assert "parameters" in func- def test_dry_run_exists_and_is_boolean(self, schema: ChatCompletionToolParam):+ def test_dry_run_not_in_llm_schema(self, schema: ChatCompletionToolParam):+ """dry_run must NOT be in the run_block LLM schema — it is session-level."""params = cast(dict[str, Any], schema["function"].get("parameters", {}))- props = params["properties"]- assert "dry_run" in props- assert props["dry_run"]["type"] == "boolean"+ props = params.get("properties", {})+ assert (+ "dry_run" not in props+ ), "dry_run must not be exposed in the run_block LLM schema"+ assert "dry_run" not in params.get("required", [])- def test_dry_run_is_required(self, schema: ChatCompletionToolParam):- """dry_run must be required — along with block_id and input_data."""+ def test_block_id_and_input_data_are_required(+ self, schema: ChatCompletionToolParam+ ):+ """block_id and input_data must be required parameters."""params = cast(dict[str, Any], schema["function"].get("parameters", {}))required = params.get("required", [])- assert "dry_run" in requiredassert "block_id" in requiredassert "input_data" in required- def test_dry_run_description_mentions_preview(- self, schema: ChatCompletionToolParam- ):- params = cast(dict[str, Any], schema["function"].get("parameters", {}))- desc = params["properties"]["dry_run"]["description"]- assert isinstance(desc, str)- assert (- "preview mode" in desc.lower()- ), "run_block dry_run description should mention preview mode"-# ---------------------------------------------------------------------------# Functional tests: RunAgentInput Pydantic model@@ -251,10 +249,26 @@ class TestRunBlockToolSchema:class TestRunAgentInputModel:"""Validate RunAgentInput Pydantic model handles dry_run correctly.- The executor reads dry_run from this model, so it must parse, default,- and validate properly.+ dry_run is exposed in the LLM schema so the LLM can request per-call+ dry runs in normal sessions. It defaults to False. Session-level+ dry_run=True forces all runs dry; normal sessions respect the LLM's choice."""+ def test_dry_run_default_false(self):+ """dry_run defaults to False when not provided."""+ model = RunAgentInput(username_agent_slug="user/agent")+ assert model.dry_run is False++ def test_dry_run_in_schema_parameters(self):+ """dry_run must appear in RunAgentTool.parameters so the LLM can+ request per-call dry runs in normal sessions."""+ from backend.copilot.tools.run_agent import RunAgentTool++ tool = RunAgentTool()+ assert "dry_run" in tool.parameters.get(+ "properties", {}+ ), "dry_run must be exposed in the LLM tool schema"+def test_dry_run_accepts_true(self):model = RunAgentInput(username_agent_slug="user/agent", dry_run=True)assert model.dry_run is True@@ -290,13 +304,12 @@ class TestRunAgentInputModel:with pytest.raises(ValidationError):RunAgentInput(username_agent_slug="user/agent",- dry_run=True,wait_for_result=301,)def test_string_fields_are_stripped(self):"""The strip_strings validator should strip whitespace from string fields."""- model = RunAgentInput(username_agent_slug=" user/agent ", dry_run=True)+ model = RunAgentInput(username_agent_slug=" user/agent ")assert model.username_agent_slug == "user/agent"diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/CopilotPage.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/CopilotPage.tsxindex 46fbe1ed6e..03838a26ba 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/CopilotPage.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/CopilotPage.tsx@@ -7,7 +7,7 @@ import useCredits from "@/hooks/useCredits";import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";import { SidebarProvider } from "@/components/ui/sidebar";import { cn } from "@/lib/utils";-import { UploadSimple } from "@phosphor-icons/react";+import { Flask, UploadSimple } from "@phosphor-icons/react";import dynamic from "next/dynamic";import { useCallback, useEffect, useRef, useState } from "react";import { ChatContainer } from "./components/ChatContainer/ChatContainer";@@ -113,6 +113,8 @@ export function CopilotPage() {// Rate limit resetrateLimitMessage,dismissRateLimit,+ // Dry run dev toggle+ isDryRun,} = useCopilotPage();const {@@ -174,6 +176,12 @@ export function CopilotPage() {>{isMobile && <MobileHeader onOpenDrawer={handleOpenDrawer} />}<NotificationBanner />+ {isDryRun && (+ <div className="flex items-center justify-center gap-1.5 bg-amber-50 px-3 py-1.5 text-xs font-medium text-amber-800">+ <Flask size={13} weight="bold" />+ Test mode — new sessions use dry_run=true+ </div>+ )}{/* Drop overlay */}<divclassName={cn(diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/ChatContainer.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/ChatContainer.tsxindex 6e67c8fc48..f116b053b4 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/ChatContainer.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/ChatContainer.tsx@@ -131,6 +131,7 @@ export const ChatContainer = ({placeholder="What else can I help with?"droppedFiles={droppedFiles}onDroppedFilesConsumed={onDroppedFilesConsumed}+ hasSession={!!sessionId}/></motion.div></div>diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/ChatInput.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/ChatInput.tsxindex b836c1e766..3dac5bf35e 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/ChatInput.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/ChatInput.tsx@@ -11,6 +11,7 @@ import { cn } from "@/lib/utils";import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";import { ChangeEvent, useEffect, useState } from "react";import { AttachmentMenu } from "./components/AttachmentMenu";+import { DryRunToggleButton } from "./components/DryRunToggleButton";import { FileChips } from "./components/FileChips";import { ModeToggleButton } from "./components/ModeToggleButton";import { RecordingButton } from "./components/RecordingButton";@@ -32,6 +33,8 @@ interface Props {droppedFiles?: File[];/** Called after droppedFiles have been merged into internal state. */onDroppedFilesConsumed?: () => void;+ /** When true, the dry-run toggle is disabled (session is active and immutable). */+ hasSession?: boolean;}export function ChatInput({@@ -45,9 +48,12 @@ export function ChatInput({inputId = "chat-input",droppedFiles,onDroppedFilesConsumed,+ hasSession = false,}: Props) {- const { copilotMode, setCopilotMode } = useCopilotUIStore();+ const { copilotMode, setCopilotMode, isDryRun, setIsDryRun } =+ useCopilotUIStore();const showModeToggle = useGetFlag(Flag.CHAT_MODE_OPTION);+ const showDryRunToggle = showModeToggle;const [files, setFiles] = useState<File[]>([]);function handleToggleMode() {@@ -66,6 +72,17 @@ export function ChatInput({});}+ function handleToggleDryRun() {+ const next = !isDryRun;+ setIsDryRun(next);+ toast({+ title: next ? "Test mode enabled" : "Test mode disabled",+ description: next+ ? "New chats will run agents in test mode."+ : "New chats will run agents normally.",+ });+ }+// Merge files dropped onto the chat window into internal state.useEffect(() => {if (droppedFiles && droppedFiles.length > 0) {@@ -186,6 +203,14 @@ export function ChatInput({onToggle={handleToggleMode}/>)}+ {showDryRunToggle && (!hasSession || isDryRun) && (+ <DryRunToggleButton+ isDryRun={isDryRun}+ isStreaming={isStreaming}+ readOnly={hasSession}+ onToggle={handleToggleDryRun}+ />+ )}</PromptInputTools><div className="flex items-center gap-4">diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/DryRunToggleButton.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/DryRunToggleButton.tsxnew file mode 100644index 0000000000..297cd04d8e--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/DryRunToggleButton.tsx@@ -0,0 +1,48 @@+"use client";++import { cn } from "@/lib/utils";+import { Flask } from "@phosphor-icons/react";++interface Props {+ isDryRun: boolean;+ isStreaming: boolean;+ readOnly?: boolean;+ onToggle: () => void;+}++export function DryRunToggleButton({+ isDryRun,+ isStreaming,+ readOnly = false,+ onToggle,+}: Props) {+ const isDisabled = isStreaming || readOnly;+ return (+ <button+ type="button"+ aria-pressed={isDryRun}+ disabled={isDisabled}+ onClick={readOnly ? undefined : onToggle}+ className={cn(+ "inline-flex min-h-11 min-w-11 items-center justify-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors",+ isDryRun+ ? "bg-amber-100 text-amber-900 hover:bg-amber-200"+ : "text-neutral-500 hover:bg-neutral-100 hover:text-neutral-700",+ isDisabled && "cursor-default opacity-70",+ )}+ aria-label={isDryRun ? "Test mode active" : "Enable Test mode"}+ title={+ readOnly+ ? "Test mode active for this session"+ : isStreaming+ ? "Cannot change mode while streaming"+ : isDryRun+ ? "Test mode ON — click to disable"+ : "Enable Test mode — agents will run as dry-run"+ }+ >+ <Flask size={14} />+ {isDryRun && "Test"}+ </button>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/store.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/store.tsindex 34f4c2fda9..a72d515b6d 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/store.ts+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/store.ts@@ -131,6 +131,10 @@ interface CopilotUIState {copilotMode: CopilotMode;setCopilotMode: (mode: CopilotMode) => void;+ /** Developer dry-run mode: sessions created with dry_run=true. */+ isDryRun: boolean;+ setIsDryRun: (enabled: boolean) => void;+clearCopilotLocalData: () => void;}@@ -280,6 +284,16 @@ export const useCopilotUIStore = create<CopilotUIState>((set) => ({set({ copilotMode: mode });},+ isDryRun: isClient && storage.get(Key.COPILOT_DRY_RUN) === "true",+ setIsDryRun: (enabled) => {+ if (enabled) {+ storage.set(Key.COPILOT_DRY_RUN, "true");+ } else {+ storage.clean(Key.COPILOT_DRY_RUN);+ }+ set({ isDryRun: enabled });+ },+clearCopilotLocalData: () => {clearContentCache();storage.clean(Key.COPILOT_NOTIFICATIONS_ENABLED);@@ -289,6 +303,7 @@ export const useCopilotUIStore = create<CopilotUIState>((set) => ({storage.clean(Key.COPILOT_ARTIFACT_PANEL_WIDTH);storage.clean(Key.COPILOT_MODE);storage.clean(Key.COPILOT_COMPLETED_SESSIONS);+ storage.clean(Key.COPILOT_DRY_RUN);set({completedSessionIDs: new Set<string>(),isNotificationsEnabled: false,@@ -302,6 +317,7 @@ export const useCopilotUIStore = create<CopilotUIState>((set) => ({history: [],},copilotMode: "extended_thinking",+ isDryRun: false,});if (isClient) {document.title = ORIGINAL_TITLE;diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/RunAgent.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/RunAgent.tsxindex d14417d6ef..ce1d5e4f20 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/RunAgent.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/RunAgent.tsx@@ -15,6 +15,7 @@ import {getAnimationText,getRunAgentToolOutput,isRunAgentAgentDetailsOutput,+ isRunAgentAgentOutputResponse,isRunAgentErrorOutput,isRunAgentExecutionStartedOutput,isRunAgentNeedLoginOutput,@@ -60,12 +61,17 @@ export function RunAgentTool({ part }: Props) {const needLoginOutput =isOutputAvailable && isRunAgentNeedLoginOutput(output) ? output : null;+ const agentOutputResponse =+ isOutputAvailable && isRunAgentAgentOutputResponse(output) ? output : null;+const hasExpandableContent =isOutputAvailable &&!setupRequirementsOutput &&!agentDetailsOutput &&!needLoginOutput &&- (isRunAgentExecutionStartedOutput(output) || isRunAgentErrorOutput(output));+ (isRunAgentExecutionStartedOutput(output) ||+ isRunAgentAgentOutputResponse(output) ||+ isRunAgentErrorOutput(output));return (<div className="py-2">@@ -123,6 +129,19 @@ export function RunAgentTool({ part }: Props) {<ExecutionStartedCard output={output} />)}+ {agentOutputResponse && (+ <ExecutionStartedCard+ output={{+ message: agentOutputResponse.message,+ execution_id: agentOutputResponse.execution?.execution_id ?? "",+ graph_id: agentOutputResponse.agent_id,+ graph_name: agentOutputResponse.agent_name,+ library_agent_link:+ agentOutputResponse.library_agent_link ?? undefined,+ }}+ />+ )}+{isRunAgentErrorOutput(output) && <ErrorCard output={output} />}</ToolAccordion>)}diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/components/ExecutionStartedCard/ExecutionStartedCard.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/components/ExecutionStartedCard/ExecutionStartedCard.tsxindex f98656e5ff..6246eb8f63 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/components/ExecutionStartedCard/ExecutionStartedCard.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/components/ExecutionStartedCard/ExecutionStartedCard.tsx@@ -24,15 +24,18 @@ export function ExecutionStartedCard({ output }: Props) {<ContentCardTitle>Execution started</ContentCardTitle><ContentCardSubtitle>{output.execution_id}</ContentCardSubtitle><ContentCardDescription>{output.message}</ContentCardDescription>- {output.library_agent_link && (- <Button- size="small"- className="mt-3"- onClick={() => router.push(output.library_agent_link!)}- >- View Execution- </Button>- )}+ <Button+ size="small"+ className="mt-3"+ onClick={() =>+ router.push(+ output.library_agent_link ??+ `/library/agents/${output.graph_id}?activeTab=runs&activeItem=${output.execution_id}`,+ )+ }+ >+ View Execution+ </Button></ContentCard></ContentGrid>);diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/helpers.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/helpers.tsxindex 65447687bc..bdb1a28ac6 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/helpers.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/helpers.tsx@@ -1,4 +1,5 @@import type { AgentDetailsResponse } from "@/app/api/__generated__/models/agentDetailsResponse";+import type { AgentOutputResponse } from "@/app/api/__generated__/models/agentOutputResponse";import type { ErrorResponse } from "@/app/api/__generated__/models/errorResponse";import type { ExecutionStartedResponse } from "@/app/api/__generated__/models/executionStartedResponse";import type { NeedLoginResponse } from "@/app/api/__generated__/models/needLoginResponse";@@ -25,6 +26,7 @@ export interface RunAgentInput {export type RunAgentToolOutput =| SetupRequirementsResponse| ExecutionStartedResponse+ | AgentOutputResponse| AgentDetailsResponse| NeedLoginResponse| ErrorResponse;@@ -32,6 +34,7 @@ export type RunAgentToolOutput =const RUN_AGENT_OUTPUT_TYPES = new Set<string>([ResponseType.setup_requirements,ResponseType.execution_started,+ ResponseType.agent_output,ResponseType.agent_details,ResponseType.need_login,ResponseType.error,@@ -54,6 +57,12 @@ export function isRunAgentExecutionStartedOutput();}+export function isRunAgentAgentOutputResponse(+ output: RunAgentToolOutput,+): output is AgentOutputResponse {+ return output.type === ResponseType.agent_output;+}+export function isRunAgentAgentDetailsOutput(output: RunAgentToolOutput,): output is AgentDetailsResponse {@@ -234,6 +243,14 @@ export function getAccordionMeta(output: RunAgentToolOutput): {};}+ if (isRunAgentAgentOutputResponse(output)) {+ return {+ icon,+ title: output.agent_name,+ description: "Execution completed",+ };+ }+if (isRunAgentNeedLoginOutput(output)) {return { icon, title: "Sign in required" };}diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/useChatSession.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/useChatSession.tsindex e001792456..1d34a99145 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/useChatSession.ts+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/useChatSession.ts@@ -11,7 +11,11 @@ import { parseAsString, useQueryState } from "nuqs";import { useEffect, useMemo, useRef } from "react";import { convertChatSessionMessagesToUiMessages } from "./helpers/convertChatSessionToUiMessages";-export function useChatSession() {+interface UseChatSessionOptions {+ dryRun?: boolean;+}++export function useChatSession({ dryRun = false }: UseChatSessionOptions = {}) {const [sessionId, setSessionId] = useQueryState("sessionId", parseAsString);const queryClient = useQueryClient();@@ -25,6 +29,19 @@ export function useChatSession() {},});+ // When dry-run mode is toggled, discard the current session so the next+ // send creates a fresh one with the correct dry_run flag. Sessions are+ // immutable once created: dry_run cannot be changed after the fact.+ const prevDryRunRef = useRef(dryRun);+ useEffect(() => {+ if (prevDryRunRef.current !== dryRun) {+ prevDryRunRef.current = dryRun;+ if (sessionId) {+ setSessionId(null);+ }+ }+ }, [dryRun, sessionId, setSessionId]);+// Invalidate query cache on session switch.// useChat destroys its Chat instance on id change, so messages are lost.// We invalidate BOTH the old session (stale after leaving) and the new@@ -106,8 +123,9 @@ export function useChatSession() {async function createSession() {if (sessionId) return sessionId;try {+ const body = dryRun ? { data: { dry_run: true } } : { data: null };// eslint-disable-next-line @typescript-eslint/no-explicit-any- const response = await (createSessionMutation as any)({ data: null });+ const response = await (createSessionMutation as any)(body);if (response.status !== 200 || !response.data?.id) {const error = new Error("Failed to create session");Sentry.captureException(error, {diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPage.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPage.tsindex 4d97a9619d..f8b0387c6b 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPage.ts+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPage.ts@@ -43,6 +43,7 @@ export function useCopilotPage() {isDrawerOpen,setDrawerOpen,copilotMode,+ isDryRun,} = useCopilotUIStore();const {@@ -59,7 +60,7 @@ export function useCopilotPage() {createSession,isCreatingSession,refetchSession,- } = useChatSession();+ } = useChatSession({ dryRun: isDryRun });const {messages: currentMessages,@@ -414,5 +415,7 @@ export function useCopilotPage() {// Rate limit resetrateLimitMessage,dismissRateLimit,+ // Dry run dev toggle+ isDryRun,};}diff --git a/autogpt_platform/frontend/src/app/api/__generated__/models/blockOutputResponse.ts b/autogpt_platform/frontend/src/app/api/__generated__/models/blockOutputResponse.tsindex 79789d50bb..a25b1a04d3 100644--- a/autogpt_platform/frontend/src/app/api/__generated__/models/blockOutputResponse.ts+++ b/autogpt_platform/frontend/src/app/api/__generated__/models/blockOutputResponse.ts@@ -8,6 +8,7 @@import type { ResponseType } from "./responseType";import type { BlockOutputResponseSessionId } from "./blockOutputResponseSessionId";import type { BlockOutputResponseOutputs } from "./blockOutputResponseOutputs";+import type { BlockOutputResponseIsDryRun } from "./blockOutputResponseIsDryRun";/*** Response for run_block tool.@@ -20,5 +21,5 @@ export interface BlockOutputResponse {block_name: string;outputs: BlockOutputResponseOutputs;success?: boolean;- is_dry_run?: boolean;+ is_dry_run?: BlockOutputResponseIsDryRun;}diff --git a/autogpt_platform/frontend/src/app/api/openapi.json b/autogpt_platform/frontend/src/app/api/openapi.jsonindex f3e33f5697..e68e68b686 100644--- a/autogpt_platform/frontend/src/app/api/openapi.json+++ b/autogpt_platform/frontend/src/app/api/openapi.json@@ -8523,9 +8523,8 @@},"success": { "type": "boolean", "title": "Success", "default": true },"is_dry_run": {- "type": "boolean",- "title": "Is Dry Run",- "default": false+ "anyOf": [{ "type": "boolean" }, { "type": "null" }],+ "title": "Is Dry Run"}},"type": "object",diff --git a/autogpt_platform/frontend/src/services/storage/local-storage.ts b/autogpt_platform/frontend/src/services/storage/local-storage.tsindex ce4982a352..de31967d53 100644--- a/autogpt_platform/frontend/src/services/storage/local-storage.ts+++ b/autogpt_platform/frontend/src/services/storage/local-storage.ts@@ -18,6 +18,7 @@ export enum Key {COPILOT_ARTIFACT_PANEL_WIDTH = "copilot-artifact-panel-width",COPILOT_MODE = "copilot-mode",COPILOT_COMPLETED_SESSIONS = "copilot-completed-sessions",+ COPILOT_DRY_RUN = "copilot-dry-run",}function get(key: Key) {