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(copilot): the content judge reads only what came from outside AutoGPT, never the platform's own guidance (#15056)
Reinier van der Leer60d450554fd9
diff --git a/autogpt_platform/backend/backend/copilot/gate/mcp_seam.py b/autogpt_platform/backend/backend/copilot/gate/mcp_seam.pyindex 5b763f66ad..adba1acf1c 100644--- a/autogpt_platform/backend/backend/copilot/gate/mcp_seam.py+++ b/autogpt_platform/backend/backend/copilot/gate/mcp_seam.py@@ -77,10 +77,16 @@ async def screen_non_registry_read(user_id: str | None,session: ChatSession,result: dict[str, Any],+ *,+ outside: tuple[Any, ...] | None = None,+ full: dict[str, Any] | None = None,) -> dict[str, Any]:- """``result`` as capped for the model, or the stub that replaces it."""+ """``result`` as capped for the model, or the stub that replaces it.++ ``outside`` is what the handler declared came from outside AutoGPT, placed+ in ``full``, its result before the cap; None judges all of ``result``."""+ text = _text_of(result)blocks = [b for b in result.get("content") or () if isinstance(b, dict)]- text = "\n".join(str(b.get("text", "")) for b in blocks if b.get("type") == "text")images = tuple(Image(mime_type=str(b.get("mimeType", "")), data_base64=str(b["data"]))for b in blocks@@ -98,12 +104,19 @@ async def screen_non_registry_read(# The MCP handler never sees the SDK's tool_use_id; registry tools# on this engine use the same stand-in.tool_call_id=f"sdk-{uuid.uuid4().hex[:12]}",+ outside=outside,+ full=_text_of(full or result),)if stub is None:return resultreturn {"content": [{"type": "text", "text": stub}], "isError": True}+def _text_of(result: dict[str, Any]) -> str:+ blocks = [b for b in result.get("content") or () if isinstance(b, dict)]+ return "\n".join(str(b.get("text", "")) for b in blocks if b.get("type") == "text")++def _error(tool_name: str,reason: str,diff --git a/autogpt_platform/backend/backend/copilot/gate/reads.py b/autogpt_platform/backend/backend/copilot/gate/reads.pyindex edb0beb618..dec1d03149 100644--- a/autogpt_platform/backend/backend/copilot/gate/reads.py+++ b/autogpt_platform/backend/backend/copilot/gate/reads.py@@ -6,16 +6,23 @@ user's approval releases exactly those bytes; a rejection leaves them out.Both seams hand this module the result AS CAPPED for the model, so the judgereads what the model would read and the stored bytes are what it would have got.+A result whose producer declared its outside parts is judged on what of those+parts the model reads; an undeclared one is judged whole."""+import asyncioimport base64import jsonimport loggingimport posixpathimport re+from collections.abc import Mappingfrom contextvars import ContextVar-from datetime import UTC, datetime+from datetime import UTC, date, datetime, time+from decimal import Decimal+from enum import Enumfrom typing import Any, Callable+from uuid import UUIDfrom prisma.enums import ReviewStatusfrom pydantic import BaseModel, ConfigDict@@ -87,6 +94,9 @@ _SOURCE_KEYS = ("session_id","name",)+# The judge's source line sits inside its fence of outside bytes, so it never+# carries the model's own words (a command, a search query).+_JUDGED_SOURCE_KEYS = ("url", "file_path", "path")_WAITING = ("This content is withheld while the user reviews it. Carry on with what ""does not depend on it; do not fetch it another way."@@ -205,26 +215,33 @@ async def screen_read(text: str,images: tuple[Image, ...] = (),tool_call_id: str = "",+ outside: tuple[Any, ...] | None = None,+ full: str = "",) -> str | None:"""A stub to hand the model in place of ``output``, or None to hand it over.``output`` is what the model would receive; ``text`` and ``images`` are- what of it can be read. Any failure in here withholds the read.+ what of it can be read. ``outside`` is what the producer declared came from+ outside AutoGPT, placed in ``full``, the result before any cap; None judges+ ``text`` whole. Any failure in here withholds the read."""if tool_name not in JUDGED_READS or trusted_read(tool_name, args, output):return None- if platform_setup_card(output):- return Nonesource = source_of(tool_name, args)try:mode = await active_mode(user_id, session)if mode is None or mode == "unsupervised":return None+ if outside is not None:+ # AutoGPT writes no images, so a declaration narrows only the text.+ text = await asyncio.to_thread(outside_view, outside, full, text, tool_name)# Bytes nobody can read are not instructions until something decodes# them, and that later read is judged.if not text.strip() and not images:return None- verdict = await judge_content(source=source, text=text, images=images)+ verdict = await judge_content(+ source=judged_source(tool_name, args), text=text, images=images+ )if not verdict.held:return Noneassert user_id is not None@@ -263,20 +280,6 @@ def trusted_read(tool_name: str, args: dict[str, Any], output: str) -> bool:return False-def platform_setup_card(output: str) -> bool:- """A sign-in or setup card the platform wrote: holding it would replace the- card with a stub. A provider's rejection text in it is outside, so judged."""- try:- data = json.loads(output)- except ValueError:- return False- return (- isinstance(data, dict)- and data.get("type") == ResponseType.SETUP_REQUIREMENTS- and not data.get("rejection")- )--def is_skill_path(path: str | None) -> bool:"""A workspace path under an installed-skill folder. Only the skillsregistry writes there; ``write_workspace_file`` refuses these roots."""@@ -327,15 +330,151 @@ def readable_parts(output: str) -> tuple[str, tuple[Image, ...]]:return f"{output}\n\n{decoded}", ()-def source_of(tool_name: str, args: dict[str, Any]) -> str:+def outside_view(+ outside: tuple[Any, ...], full: str, text: str, tool_name: str = ""+) -> str:+ """What of the declared parts the model reads in ``text``, each as the caps+ left it; ``text`` whole when a part is not in ``full``, so a mark that+ misses the bytes it names fails closed."""+ pieces: dict[str, None] = {}+ budget = [_MAX_OUTSIDE_VALUES]+ if not all(_locate(part, full, text, pieces, budget) for part in outside):+ logger.warning(+ f"Declared outside parts of {tool_name} not located; judged whole"+ )+ return text+ return "\n".join(pieces)+++# Past this many values a declaration is judged whole: locating each is a scan+# of the capped text.+_MAX_OUTSIDE_VALUES = 5_000+# A shorter fragment of a cut part is kept only beside the cap's marker, so a+# stray match of a few characters elsewhere is not judged as the part.+_MIN_FRAGMENT = 16+_CUT = "\u2026"+_OPAQUE = (int, float, bool, type(None), datetime, date, time, UUID, Decimal)+++def _locate(+ value: Any, full: str, view: str, pieces: dict[str, None], budget: list[int]+) -> bool:+ """Add what of ``value`` shows in ``view``; False when it is not in ``full``."""+ budget[0] -= 1+ if budget[0] < 0:+ return False+ if isinstance(value, Enum):+ value = value.value+ if isinstance(value, BaseModel):+ value = value.model_dump(mode="json")+ if isinstance(value, bytes):+ value = value.decode("utf-8", errors="replace")+ if isinstance(value, str):+ return _locate_text(value, full, view, pieces)+ if isinstance(value, _OPAQUE):+ return True+ if isinstance(value, Mapping):+ # The response is dumped with ``exclude_none``, which drops the key too.+ children = [part for kv in value.items() if kv[1] is not None for part in kv]+ elif isinstance(value, (list, tuple, set, frozenset)):+ children = list(value)+ else:+ return False+ for dumped in _dumps(value):+ if dumped in view:+ pieces[dumped] = None+ return True+ return all(_locate(child, full, view, pieces, budget) for child in children)+++def _locate_text(value: str, full: str, view: str, pieces: dict[str, None]) -> bool:+ if not value.strip():+ return True+ encodings = list(dict.fromkeys(_encodings(value)))+ if not any(encoded in full for encoded in encodings):+ return False+ for encoded in encodings:+ if encoded in view:+ pieces[encoded] = None+ return True+ kept = max((_fragments(encoded, view) for encoded in encodings), key=_coverage)+ pieces.update(dict.fromkeys(kept))+ return True+++def _encodings(value: str) -> tuple[str, str, str]:+ """Raw in an MCP text block, escaped in the JSON a registry tool returns, and+ ASCII-escaped in a digest's outline."""+ return (+ value,+ json.dumps(value, ensure_ascii=False)[1:-1],+ json.dumps(value)[1:-1],+ )+++def _dumps(value: Any) -> list[str]:+ """``value`` as the response's JSON serialises it, and as a preview re-dumps it."""+ try:+ return [+ json.dumps(value, ensure_ascii=False, separators=(",", ":")),+ json.dumps(value, ensure_ascii=False),+ ]+ except (TypeError, ValueError):+ return []+++def _fragments(encoded: str, view: str) -> list[str]:+ """The head and tail of a part a cap cut, as far as ``view`` still shows them."""+ head = encoded[: _longest(encoded, view, head=True)]+ tail = encoded[len(encoded) - _longest(encoded, view, head=False) :]+ kept = []+ if head and (len(head) >= _MIN_FRAGMENT or head + _CUT in view):+ kept.append(head)+ if tail and (len(tail) >= _MIN_FRAGMENT or _CUT + tail in view):+ kept.append(tail)+ return kept+++def _coverage(fragments: list[str]) -> int:+ return sum(len(f) for f in fragments)+++def _longest(encoded: str, view: str, *, head: bool) -> int:+ """The longest head (or tail) of ``encoded`` that occurs in ``view``; it is+ known not to occur whole."""++ def shown(k: int) -> bool:+ return (encoded[:k] if head else encoded[-k:]) in view++ low, high = 0, 1+ while high < len(encoded) and shown(high):+ low, high = high, high * 2+ high = min(high, len(encoded))+ while high - low > 1:+ middle = (low + high) // 2+ if shown(middle):+ low = middle+ else:+ high = middle+ return low+++def source_of(+ tool_name: str, args: dict[str, Any], keys: tuple[str, ...] = _SOURCE_KEYS+) -> str:"""Where the bytes came from, for the stub and the card."""- for key in _SOURCE_KEYS:+ for key in keys:value = args.get(key)if isinstance(value, str) and value:return f"{tool_name} {value[:200]}"return tool_name+def judged_source(tool_name: str, args: dict[str, Any]) -> str:+ """Where the bytes came from, for the judge: a URL or a path at most."""+ return source_of(tool_name, args, _JUDGED_SOURCE_KEYS)++def page_words(passage: str, text: str) -> str:"""The judge's quote, only as far as the page itself says it.diff --git a/autogpt_platform/backend/backend/copilot/gate/reads_test.py b/autogpt_platform/backend/backend/copilot/gate/reads_test.pyindex ee1ceb25f4..6326a8e192 100644--- a/autogpt_platform/backend/backend/copilot/gate/reads_test.py+++ b/autogpt_platform/backend/backend/copilot/gate/reads_test.py@@ -5,16 +5,18 @@ SDK wrapper for the rest — with only the judge and the review rows faked. Therows go through ``sanitize_json`` as Postgres's JSON column does."""+import asyncioimport base64import jsonfrom datetime import UTC, datetime, timedeltafrom types import SimpleNamespacefrom typing import Any-from unittest.mock import AsyncMock, patch+from unittest.mock import AsyncMock, MagicMock, patchimport pytestfrom prisma.enums import ReviewStatus+from backend.copilot.context import set_turn_unattendedfrom backend.copilot.gate import held, readsfrom backend.copilot.gate import review as review_storefrom backend.copilot.gate.content import ContentVerdict@@ -842,3 +844,537 @@ async def test_a_blocks_own_output_is_still_judged(rows):def _no_action_gate():return patch.object(BaseTool, "_gate", AsyncMock(return_value=(None, False)))+++# What a producer declares came from outside AutoGPT is all the judge reads.++_STORE_VALUE = "1ff065e9-88e8-4358-9d82-8dc91f622ba9"+_MCP_URL = "https://mcp.example.com/mcp"+++def _capability(kind: str, ref: str):+ from backend.copilot.capabilities.models import CapabilityEntry, Implementation++ return CapabilityEntry(+ id="cap",+ kind=kind,+ name="cap",+ purpose="cap",+ implementations=[Implementation(kind=kind, ref=ref)],+ )+++def _resolves_to(entry):+ return patch(+ "backend.copilot.tools.run_capability.resolve_session_entry",+ AsyncMock(return_value=entry),+ )+++def _mcp_server(client):+ from contextlib import ExitStack++ stack = ExitStack()+ for name, value in (+ ("validate_url_host", AsyncMock()),+ ("auto_lookup_mcp_credential", AsyncMock(return_value=None)),+ ("MCPClient", lambda *a, **k: client),+ ):+ stack.enter_context(patch(f"backend.copilot.tools.run_mcp_tool.{name}", value))+ return stack+++async def _run_capability(args: dict[str, Any]) -> StreamToolOutputAvailable:+ from backend.copilot.tools.run_capability import RunCapabilityTool++ return await _call(RunCapabilityTool(), _session(), args)+++ "kind, ref",+ [+ ("block", _STORE_VALUE),+ ("tool", "connect_integration"),+ ("mcp_server", _MCP_URL),+ ],+)+async def test_a_validate_only_answer_is_the_platforms_own_words_and_not_judged(+ rows, kind, ref+):+ """A platform tool's validate_only answer ends "Call again without+ validate_only to run.": the platform's own instruction, never judged."""+ from backend.copilot.tools import TOOL_REGISTRY++ judge = _judge(_HELD)+ with (+ patch(f"{_READS}.judge_content", judge),+ _no_action_gate(),+ _resolves_to(_capability(kind, ref)),+ patch(+ "backend.copilot.tools.run_capability.configured_tool",+ TOOL_REGISTRY.get,+ ),+ ):+ result = await _run_capability(+ {"id": "cap", "input": {}, "validate_only": True}+ )++ judge.assert_not_awaited()+ assert result.success and rows.rows == {}+ if kind == "tool":+ assert "Call again without validate_only to run." in result.output+++async def test_an_mcp_tools_description_is_judged_and_the_listing_around_it_is_not(+ rows,+):+ """A server's tool descriptions reach the model through discovery."""+ from backend.blocks.mcp.client import MCPTool++ client = AsyncMock()+ client.list_tools = AsyncMock(+ return_value=[MCPTool(name="send_mail", description=_MARKER, input_schema={})]+ )+ judge = _judge(_HELD)+ with (+ patch(f"{_READS}.judge_content", judge),+ _no_action_gate(),+ _resolves_to(_capability("mcp_server", _MCP_URL)),+ _mcp_server(client),+ ):+ result = await _run_capability({"id": "cap", "input": {}})++ judged = judge.await_args.kwargs["text"]+ assert _MARKER in judged and "send_mail" in judged+ assert "Do NOT re-run discovery" not in judged+ assert _MARKER not in result.output and len(rows.rows) == 1+++async def test_a_blocks_output_is_judged_without_the_platforms_message(rows):+ workspace = AsyncMock()+ workspace.get_or_create_workspace = AsyncMock(return_value=SimpleNamespace(id="w"))+ users = AsyncMock()+ users.get_user_by_id = AsyncMock(return_value=SimpleNamespace(timezone="UTC"))+ judge = _judge(_HELD)+ with (+ patch(f"{_READS}.judge_content", judge),+ # Approved, so the block runs without its own review pause.+ patch.object(BaseTool, "_gate", AsyncMock(return_value=(None, True))),+ _resolves_to(_capability("block", _STORE_VALUE)),+ patch("backend.copilot.tools.helpers.workspace_db", lambda: workspace),+ patch("backend.copilot.tools.helpers.user_db", lambda: users),+ ):+ result = await _run_capability({"id": "cap", "input": {"input": _MARKER}})++ judged = judge.await_args.kwargs["text"]+ assert _MARKER in judged and "executed successfully" not in judged+ assert _MARKER not in result.output and len(rows.rows) == 1+++async def test_an_mcp_tools_result_is_judged_without_the_platforms_message(rows):+ from backend.blocks.mcp.client import MCPCallResult++ client = AsyncMock()+ client.call_tool = AsyncMock(+ return_value=MCPCallResult(content=[{"type": "text", "text": _MARKER}])+ )+ judge = _judge(_HELD)+ with (+ patch(f"{_READS}.judge_content", judge),+ _no_action_gate(),+ _resolves_to(_capability("mcp_server", _MCP_URL)),+ _mcp_server(client),+ ):+ result = await _run_capability(+ {"id": "cap", "input": {"tool": "read_inbox", "arguments": {}}}+ )++ judged = judge.await_args.kwargs["text"]+ assert _MARKER in judged and "executed successfully" not in judged+ assert _MARKER not in result.output and len(rows.rows) == 1+++async def test_an_mcp_error_is_judged_without_the_hint_the_platform_adds(rows):+ """The hint repeats the tool name the model asked for; only the server's+ error and its tool names are outside bytes."""+ from backend.blocks.mcp.client import MCPCallResult, MCPTool++ client = AsyncMock()+ client.call_tool = AsyncMock(+ return_value=MCPCallResult(+ content=[{"type": "text", "text": _MARKER}], is_error=True+ )+ )+ client.list_tools = AsyncMock(+ return_value=[MCPTool(name="send_mail", description="", input_schema={})]+ )+ judge = _judge(_HELD)+ with (+ patch(f"{_READS}.judge_content", judge),+ _no_action_gate(),+ _resolves_to(_capability("mcp_server", _MCP_URL)),+ _mcp_server(client),+ ):+ result = await _run_capability(+ {"id": "cap", "input": {"tool": "read_inbox", "arguments": {}}}+ )++ judged = judge.await_args.kwargs["text"]+ assert _MARKER in judged and "send_mail" in judged+ assert "read_inbox" not in judged and "No tool named" not in judged+ assert _MARKER not in result.output and len(rows.rows) == 1+++async def test_an_mcp_sign_in_card_is_not_judged_but_the_providers_refusal_in_one_is(+ rows,+):+ """The refusal sits inside the card's own message: only it is judged."""+ from backend.copilot.tools.models import CredentialRejection+ from backend.copilot.tools.run_mcp_tool import RunMCPToolTool++ class _Card(_Fetch):+ def __init__(self, rejection):+ super().__init__("", name="run_capability")+ self.rejection = rejection++ async def _execute(self, user_id, session, **kwargs):+ return await RunMCPToolTool()._build_setup_requirements(+ _MCP_URL, session.session_id, rejection=self.rejection+ )++ judge = _judge(_HELD)+ with patch(f"{_READS}.judge_content", judge), _no_action_gate():+ signed_out = await _call(_Card(None), _session())+ judge.assert_not_awaited()+ refused = await _call(+ _Card(CredentialRejection(provider="mcp", detail=_MARKER, status_code=401)),+ _session(),+ )++ assert json.loads(signed_out.output)["type"] == ResponseType.SETUP_REQUIREMENTS+ assert judge.await_args.kwargs["text"] == _MARKER+ assert _MARKER not in refused.output and len(rows.rows) == 1+++class _Declared(_Fetch):+ """A read whose producer declares ``parts`` (None: declares nothing)."""++ def __init__(self, content: str, parts: tuple[Any, ...] | None, **kwargs):+ super().__init__(content, **kwargs)+ self.parts = parts++ async def _execute(self, user_id, session, **kwargs):+ page = _Page(message="Call again without validate_only.", content=self.content)+ return page if self.parts is None else page.from_outside(*self.parts)+++ "parts, whole",+ [+ (None, True),+ (("a sentence this page never says",), True),+ ((_MARKER,), False),+ ((_MARKER,) * (reads._MAX_OUTSIDE_VALUES + 1), True),+ ((object(),), True),+ ],+ ids=["undeclared", "declared-but-absent", "declared", "over-budget", "unreadable"],+)+async def test_a_result_is_judged_whole_unless_its_declaration_holds(+ rows, parts, whole+):+ judge = _judge(_HELD)+ with patch(f"{_READS}.judge_content", judge):+ result = await _call(_Declared(_MARKER, parts), _session())++ whole_output = _Page(+ message="Call again without validate_only.", content=_MARKER+ ).model_dump_json(exclude_none=True)+ assert judge.await_args.kwargs["text"] == (whole_output if whole else _MARKER)+ assert _MARKER not in result.output and len(rows.rows) == 1+++async def test_every_image_is_judged_whatever_its_producer_declared(rows):+ """AutoGPT writes no images, so declaring a result its own narrows only+ its text."""++ class _Picture(_Fetch):+ async def _execute(self, user_id, session, **kwargs):+ return _WorkspaceFile(+ message="Here is the page.",+ mime_type="image/png",+ content_base64="iVBOR",+ ).from_outside()++ judge = _judge(_HELD)+ with patch(f"{_READS}.judge_content", judge):+ result = await _call(_Picture(""), _session())++ judge.assert_awaited_once()+ (image,) = judge.await_args.kwargs["images"]+ assert image.data_base64 == "iVBOR"+ assert "iVBOR" not in result.output and len(rows.rows) == 1+++async def test_a_declared_part_is_judged_as_the_json_the_model_reads(rows):+ part = f'"{_MARKER}"\n\\ — é'+ judge = _judge(_CLEAN)+ with patch(f"{_READS}.judge_content", judge):+ await _call(_Declared(part, (part,)), _session())+ assert judge.await_args.kwargs["text"] == json.dumps(part, ensure_ascii=False)[1:-1]+++ "tool_name, args",+ [+ ("bash_exec", {"command": f"cat > x.mjs <<'EOF'\n{_MARKER}\nEOF\nnode x.mjs"}),+ ("web_search", {"query": _MARKER}),+ ],+)+async def test_the_judge_never_reads_the_models_own_words(rows, tool_name, args):+ """The source line sits inside the judge's fence of outside bytes, so a+ command or query there was judged as the page's own text."""+ from backend.copilot.tools.bash_exec import _build_completion_response++ class _Ran(_Fetch):+ async def _execute(self, user_id, session, **kwargs):+ return _build_completion_response("ok", "", 0, [], None)++ judge = _judge(_CLEAN)+ with patch(f"{_READS}.judge_content", judge), _no_action_gate():+ await _call(_Ran("", name=tool_name), _session(), args)++ assert judge.await_args.kwargs["text"] == "ok"+ assert _MARKER not in judge.await_args.kwargs["source"]+++async def test_a_declared_part_the_cap_cut_is_judged_as_cut(rows):+ """Past the SDK's 70K cap the model reads the part's head and tail; the+ judge reads exactly those, never the middle nobody saw."""+ part = f"{_MARKER} " + "m" * 40_000 + "NOT-SEEN" + "n" * 40_000 + " tail words"+ session = _session()+ set_execution_context("user-1", session)+ wrapper = _make_truncating_wrapper(+ create_tool_handler(_Declared(part, (part,))), "web_fetch"+ )+ judge = _judge(_CLEAN)+ with (+ patch(f"{_READS}.judge_content", judge),+ patch(+ "backend.copilot.sdk.tool_adapter.resolve_tool_dispatch", lambda *_: None+ ),+ ):+ to_model = _text_from_mcp_result(await wrapper({"url": "u"}))++ head, tail = judge.await_args.kwargs["text"].split("\n")+ assert head.startswith(_MARKER) and tail.endswith(" tail words")+ assert head in to_model and tail in to_model+ assert "NOT-SEEN" not in head + tail and "validate_only" not in head + tail+++def test_a_short_stray_match_of_a_cut_parts_head_is_not_judged_as_the_part():+ """Away from the cap's marker, a head this short is the view's own words."""+ part = "Call again tomorrow " + "x" * 200+ view = 'The platform says: "Call again later."'+ assert reads.outside_view((part,), full=json.dumps(part), text=view) == ""+++async def test_a_declared_part_in_a_digest_is_judged_as_its_outline_shows_it(rows):+ """A large ``run_capability`` result reaches the model as an outline whose+ scalars are cut at the head, beside the platform's retrieval instructions."""++ class _Digested(_Declared):+ digest_large_output = True++ part = f"é{_MARKER} " + "z" * 9_000+ manager = AsyncMock()+ workspace = AsyncMock()+ workspace.get_or_create_workspace = AsyncMock(return_value=SimpleNamespace(id="w"))+ judge = _judge(_CLEAN)+ with (+ patch(f"{_READS}.judge_content", judge),+ patch("backend.copilot.tools.base.workspace_db", lambda: workspace),+ patch("backend.copilot.tools.base.WorkspaceManager", lambda *a: manager),+ ):+ result = await _call(_Digested(part, (part,)), _session())++ judged = judge.await_args.kwargs["text"]+ assert judged.startswith(f"é{_MARKER}") and len(judged) < len(part)+ assert all(piece in result.output for piece in judged.split("\n"))+ assert "read_workspace_file" not in judged and "validate_only" not in judged+++async def test_the_persisted_copy_of_a_cut_read_is_judged_when_read_back(rows):+ """The part a cap cut from the first view is still in the persisted file;+ a window of it read back either way is judged whole."""+ part = "a" * 50_000 + f" {_MARKER} " + "b" * 50_000+ manager = AsyncMock()+ workspace = AsyncMock()+ workspace.get_or_create_workspace = AsyncMock(return_value=SimpleNamespace(id="w"))++ async def judge(*, source, text, images):+ return _HELD if _MARKER in text else _CLEAN++ session = _session()+ with (+ patch(f"{_READS}.judge_content", judge),+ patch("backend.copilot.tools.base.workspace_db", lambda: workspace),+ patch("backend.copilot.tools.base.WorkspaceManager", lambda *a: manager),+ ):+ first = await _call(_Declared(part, (part,)), session)+ assert first.success and rows.rows == {}+ persisted = manager.write_file.await_args.kwargs["content"].decode()+ assert _MARKER in persisted and _MARKER not in first.output+ window = persisted[45_000:55_000]++ read_back = await _call(+ _Fetch(window, name="read_workspace_file"),+ session,+ {"path": "tool-outputs/call-1.json"},+ )++ async def read_tool_result(args):+ return {"content": [{"type": "text", "text": window}], "isError": False}++ set_execution_context("user-1", session)+ wrapper = _make_truncating_wrapper(+ read_tool_result, "read_tool_result", required_args=["file_path"]+ )+ sandbox_read = await wrapper({"file_path": "tool-outputs/call-1.json"})++ assert _MARKER not in read_back.output and _MARKER not in json.dumps(sandbox_read)+ assert len(rows.rows) == 2+++async def test_a_sandbox_files_lines_are_judged_and_an_empty_grep_is_not(+ rows, tmp_path+):+ from backend.copilot.sdk import e2b_file_tools++ (tmp_path / "notes.md").write_text(f"{_MARKER}\n")+ sandbox = SimpleNamespace(+ commands=SimpleNamespace(run=AsyncMock(return_value=SimpleNamespace(stdout="")))+ )+ session = _session()+ set_execution_context("user-1", session)+ read = _make_truncating_wrapper(+ e2b_file_tools._handle_read_file, "read_file", required_args=["file_path"]+ )+ grep = _make_truncating_wrapper(+ e2b_file_tools._handle_grep, "grep", required_args=["pattern"]+ )+ judge = _judge(_HELD)+ with (+ patch(f"{_READS}.judge_content", judge),+ patch.object(e2b_file_tools, "get_sdk_cwd", lambda: str(tmp_path)),+ patch.object(e2b_file_tools, "_get_sandbox", lambda: None),+ ):+ held_read = await read({"file_path": str(tmp_path / "notes.md")})+ assert judge.await_args.kwargs["text"] == f" 1\t{_MARKER}\n"+ assert _MARKER not in json.dumps(held_read) and len(rows.rows) == 1++ judge.reset_mock()+ with (+ patch(f"{_READS}.judge_content", judge),+ patch.object(e2b_file_tools, "_get_sandbox", lambda: sandbox),+ # The double holds no login files for run_internal to check.+ patch(+ "backend.util.sandbox_login.changed_login_files",+ AsyncMock(return_value={}),+ ),+ ):+ empty = await grep({"pattern": "nothing"})+ judge.assert_not_awaited()+ assert "No matches found." in _text_from_mcp_result(empty)+++# A scheduled turn's step that could not run answers with the platform's own+# instructions for the reply; held, the reply never says the step was skipped.+++async def _agent_without_credentials() -> ToolResponseBase | None:+ from backend.copilot.tools.run_agent import RunAgentInput, RunAgentTool++ graph = MagicMock(id="graph-1", version=1, input_schema={})+ graph.name = "Daily Scraper"+ with (+ patch(+ "backend.copilot.tools.run_agent.match_user_credentials_to_graph",+ AsyncMock(return_value=({}, ["credentials"])),+ ),+ patch(+ "backend.copilot.tools.run_agent.build_missing_credentials_from_graph",+ return_value={"credentials": {"provider": "firecrawl"}},+ ),+ ):+ _, response = await RunAgentTool()._check_prerequisites(+ graph, "user-1", RunAgentInput(), "session-1"+ )+ return response+++async def _block_credential_rejected() -> ToolResponseBase:+ from backend.blocks.search import GetWeatherInformationBlock+ from backend.copilot.tools.helpers import _credential_rejected_response+ from backend.util.request import HTTPClientError++ block = GetWeatherInformationBlock()+ return _credential_rejected_response(+ block=block,+ block_id=block.id,+ input_data={},+ matched_credentials={},+ session_id="session-1",+ status_code=401,+ exc=HTTPClientError("HTTP 401", 401),+ )+++async def _pinned_account_gone() -> ToolResponseBase:+ from backend.copilot.credential_selection import (+ CredentialPin,+ set_turn_credential_pins,+ )+ from backend.copilot.tools.helpers import unattended_missing_credentials_error++ set_turn_credential_pins({"exa": CredentialPin(id="cred-1", title="Work Exa")})+ with patch(+ "backend.copilot.tools.helpers.get_user_credentials",+ AsyncMock(return_value=[]),+ ):+ return await unattended_missing_credentials_error(+ "Block 'Search'",+ {"credentials": {"provider": "exa"}},+ "session-1",+ "user-1",+ None,+ )+++ "tool_name, produce, error",+ [+ ("run_agent", _agent_without_credentials, "missing_credentials"),+ ("run_capability", _block_credential_rejected, "credential_rejected"),+ ("run_capability", _pinned_account_gone, "pinned_credential_missing"),+ ],+)+async def test_a_scheduled_turns_skipped_step_reaches_the_model_unjudged(+ rows, tool_name, produce, error+):+ class _Unattended(_Fetch):+ async def _execute(self, user_id, session, **kwargs):+ return await produce()++ session = _session()++ async def turn():+ # Fired by the scheduler into the user's own chat, so the gate is on.+ set_turn_unattended(session, scheduled=True)+ return await _call(_Unattended("", name=tool_name), session)++ judge = _judge(_HELD)+ with patch(f"{_READS}.judge_content", judge), _no_action_gate():+ result = await asyncio.create_task(turn())++ judge.assert_not_awaited()+ assert json.loads(result.output)["error"] == error and rows.rows == {}diff --git a/autogpt_platform/backend/backend/copilot/sdk/e2b_file_tools.py b/autogpt_platform/backend/backend/copilot/sdk/e2b_file_tools.pyindex 146ae61660..02f5b040ca 100644--- a/autogpt_platform/backend/backend/copilot/sdk/e2b_file_tools.py+++ b/autogpt_platform/backend/backend/copilot/sdk/e2b_file_tools.py@@ -201,10 +201,23 @@ def _is_allowed_local(path: str) -> bool:return is_allowed_local_path(path, get_sdk_cwd())-def _mcp(text: str, *, error: bool = False) -> dict[str, Any]:+def _mcp(+ text: str, *, error: bool = False, outside: tuple[str, ...] | None = None+) -> dict[str, Any]:if error:text = json.dumps({"error": text, "type": "error"})- return {"content": [{"type": "text", "text": text}], "isError": error}+ result = {"content": [{"type": "text", "text": text}], "isError": error}+ return result if outside is None else DeclaredResult(result, outside=outside)+++class DeclaredResult(dict[str, Any]):+ """An MCP result whose ``outside`` names what in it came from outside+ AutoGPT (see ``ToolResponseBase.from_outside``). The wrapper reads it+ before the cap, which builds a plain dict."""++ def __init__(self, result: dict[str, Any], *, outside: tuple[str, ...]):+ super().__init__(result)+ self.outside = outsidedef _get_sandbox_and_path(@@ -329,7 +342,7 @@ async def _handle_read_file(args: dict[str, Any]) -> dict[str, Any]:numbered = "".join(f"{i + offset + 1:>6}\t{line}" for i, line in enumerate(selected))- return _mcp(numbered)+ return _mcp(numbered, outside=(numbered,))# Non-E2B path — read from SDK working directorysdk_cwd = get_sdk_cwd()@@ -361,7 +374,7 @@ async def _handle_read_file(args: dict[str, Any]) -> dict[str, Any]:numbered = "".join(f"{i + offset + 1:>6}\t{line}" for i, line in enumerate(selected))- return _mcp(numbered)+ return _mcp(numbered, outside=(numbered,))async def _handle_write_file(args: dict[str, Any]) -> dict[str, Any]:@@ -627,7 +640,7 @@ async def _handle_glob(args: dict[str, Any]) -> dict[str, Any]:return _mcp(f"Glob failed: {exc}", error=True)files = [line for line in (result.stdout or "").strip().splitlines() if line]- return _mcp(json.dumps(files, indent=2))+ return _mcp(json.dumps(files, indent=2), outside=tuple(files))async def _handle_grep(args: dict[str, Any]) -> dict[str, Any]:@@ -667,7 +680,9 @@ async def _handle_grep(args: dict[str, Any]) -> dict[str, Any]:return _mcp(f"Grep failed: {exc}", error=True)output = (result.stdout or "").strip()- return _mcp(output if output else "No matches found.")+ if not output:+ return _mcp("No matches found.", outside=())+ return _mcp(output, outside=(output,))# Bridging: copy SDK-internal files into E2B sandbox@@ -781,7 +796,7 @@ def _read_local(file_path: str, offset: int, limit: int) -> dict[str, Any]:numbered = "".join(f"{i + offset + 1:>6}\t{line}" for i, line in enumerate(selected))- return _mcp(numbered)+ return _mcp(numbered, outside=(numbered,))except FileNotFoundError:return _mcp(f"File not found: {file_path}", error=True)except Exception as exc:diff --git a/autogpt_platform/backend/backend/copilot/sdk/tool_adapter.py b/autogpt_platform/backend/backend/copilot/sdk/tool_adapter.pyindex f6e733fddf..516266ba72 100644--- a/autogpt_platform/backend/backend/copilot/sdk/tool_adapter.py+++ b/autogpt_platform/backend/backend/copilot/sdk/tool_adapter.py@@ -65,6 +65,7 @@ from .e2b_file_tools import (WRITE_TOOL_DESCRIPTION,WRITE_TOOL_NAME,WRITE_TOOL_SCHEMA,+ DeclaredResult,bridge_and_annotate,get_edit_tool_handler,get_read_tool_handler,@@ -865,7 +866,15 @@ def _make_truncating_wrapper(# Registry tools were judged inside ``BaseTool.execute`` on this cap.if session is not None and name not in TOOL_REGISTRY:truncated = await screen_non_registry_read(- name, original_args, user_id, session, truncated+ name,+ original_args,+ user_id,+ session,+ truncated,+ outside=(+ result.outside if isinstance(result, DeclaredResult) else None+ ),+ full=result,)if truncated.get("isError"):diff --git a/autogpt_platform/backend/backend/copilot/tools/agent_browser.py b/autogpt_platform/backend/backend/copilot/tools/agent_browser.pyindex e86252f321..51c6334d01 100644--- a/autogpt_platform/backend/backend/copilot/tools/agent_browser.py+++ b/autogpt_platform/backend/backend/copilot/tools/agent_browser.py@@ -582,7 +582,7 @@ class BrowserNavigateTool(BaseTool):message="Please provide a URL to navigate to.",error="missing_url",session_id=session_name,- )+ ).from_outside()try:await validate_url_host(url)@@ -591,7 +591,7 @@ class BrowserNavigateTool(BaseTool):message=str(e),error="blocked_url",session_id=session_name,- )+ ).from_outside()# Restore browser state from cloud if this is a different podif user_id:@@ -607,7 +607,7 @@ class BrowserNavigateTool(BaseTool):message="Failed to navigate to URL.",error="navigation_failed",session_id=session_name,- )+ ).from_outside()# Wait for page to settle (best-effort: some SPAs never reach networkidle)wait_rc, _, wait_err = await _run(session_name, "wait", "--load", wait_for)@@ -630,7 +630,7 @@ class BrowserNavigateTool(BaseTool):title=title_out.strip(),snapshot=snapshot,session_id=session_name,- )+ ).from_outside(snapshot, title_out.strip(), url_out.strip() or url)# Persist browser state to cloud for cross-pod continuityif user_id:@@ -752,7 +752,7 @@ class BrowserActTool(BaseTool):message="Please specify an action.",error="missing_action",session_id=session_name,- )+ ).from_outside()# Build the agent-browser command argsif action in _NO_TARGET_ACTIONS:@@ -767,7 +767,7 @@ class BrowserActTool(BaseTool):message="'press' requires a 'value' (key name, e.g. 'Enter').",error="missing_value",session_id=session_name,- )+ ).from_outside()cmd_args = ["press", value]elif action in _TARGET_ONLY_ACTIONS:@@ -776,7 +776,7 @@ class BrowserActTool(BaseTool):message=f"'{action}' requires a 'target' element.",error="missing_target",session_id=session_name,- )+ ).from_outside()cmd_args = [action, target]elif action in _TARGET_VALUE_ACTIONS:@@ -785,7 +785,7 @@ class BrowserActTool(BaseTool):message=f"'{action}' requires both 'target' and 'value'.",error="missing_params",session_id=session_name,- )+ ).from_outside()cmd_args = [action, target, value]elif action in _WAIT_ACTIONS:@@ -797,7 +797,7 @@ class BrowserActTool(BaseTool):),error="missing_target",session_id=session_name,- )+ ).from_outside()cmd_args = ["wait", target]else:@@ -805,7 +805,7 @@ class BrowserActTool(BaseTool):message=f"Unsupported action: {action}",error="invalid_action",session_id=session_name,- )+ ).from_outside()# Restore browser state from cloud if this is a different podif user_id:@@ -818,7 +818,7 @@ class BrowserActTool(BaseTool):message=f"Action '{action}' failed.",error="action_failed",session_id=session_name,- )+ ).from_outside()# Allow the page to settle after interaction (best-effort: SPAs may not idle)settle_rc, _, settle_err = await _run(@@ -838,7 +838,7 @@ class BrowserActTool(BaseTool):current_url=url_out.strip(),snapshot=snapshot,session_id=session_name,- )+ ).from_outside(snapshot, url_out.strip())# Persist browser state to cloud for cross-pod continuityif user_id:@@ -936,7 +936,7 @@ class BrowserScreenshotTool(BaseTool):message="Failed to take screenshot.",error="screenshot_failed",session_id=session_name,- )+ ).from_outside()with open(tmp_path, "rb") as f:png_bytes = f.read()@@ -965,14 +965,14 @@ class BrowserScreenshotTool(BaseTool):message="Screenshot taken but failed to save to workspace.",error="workspace_write_failed",session_id=session_name,- )+ ).from_outside()result = BrowserScreenshotResponse(message=f"Screenshot saved to workspace as '{filename}'. Use read_workspace_file with file_id='{write_resp.file_id}' to retrieve it.",file_id=write_resp.file_id,filename=filename,session_id=session_name,- )+ ).from_outside()# Persist browser state to cloud for cross-pod continuityif user_id:diff --git a/autogpt_platform/backend/backend/copilot/tools/agent_output.py b/autogpt_platform/backend/backend/copilot/tools/agent_output.pyindex 041918d3c2..0f0c08a398 100644--- a/autogpt_platform/backend/backend/copilot/tools/agent_output.py+++ b/autogpt_platform/backend/backend/copilot/tools/agent_output.py@@ -347,7 +347,7 @@ class AgentOutputTool(BaseTool):library_agent_id=agent.id,library_agent_link=library_agent_link,total_executions=0,- )+ ).from_outside()node_executions_data = Nonenode_failures: list[NodeFailureSummary] = []@@ -435,7 +435,7 @@ class AgentOutputTool(BaseTool):execution=execution_info,available_executions=available_list,total_executions=len(available_executions) if available_executions else 1,- )+ ).from_outside(execution_info)async def _execute(self,@@ -460,14 +460,14 @@ class AgentOutputTool(BaseTool):message="Invalid input parameters",error=str(e),session_id=session_id,- )+ ).from_outside()# Ensure user_id is present (should be guaranteed by requires_auth)if not user_id:return ErrorResponse(message="User authentication required",session_id=session_id,- )+ ).from_outside()# Check if at least one identifier is providedif not any(@@ -484,7 +484,7 @@ class AgentOutputTool(BaseTool):"library_agent_id, store_slug, or execution_id"),session_id=session_id,- )+ ).from_outside()# If only execution_id provided, we need to find the agent differentlyif (@@ -503,7 +503,7 @@ class AgentOutputTool(BaseTool):return ErrorResponse(message=f"Execution '{input_data.execution_id}' not found",session_id=session_id,- )+ ).from_outside()# Find library agent by graph_idagent = await library_db().get_library_agent_by_graph_id(@@ -517,7 +517,7 @@ class AgentOutputTool(BaseTool):),session_id=session_id,suggestions=["Add the agent to your library to see more details"],- )+ ).from_outside()return self._build_response(agent, execution, [], session_id)diff --git a/autogpt_platform/backend/backend/copilot/tools/base.py b/autogpt_platform/backend/backend/copilot/tools/base.pyindex c74ef0f799..75cbf1869c 100644--- a/autogpt_platform/backend/backend/copilot/tools/base.py+++ b/autogpt_platform/backend/backend/copilot/tools/base.py@@ -493,7 +493,7 @@ class BaseTool:result = await self._execute(user_id, session, **run_kwargs)if user_id:await _record_activity(self, user_id, session, result, kwargs)- raw_output = result.model_dump_json(exclude_none=True)+ raw_output = full = result.model_dump_json(exclude_none=True)digest = (self.digest_large_output@@ -523,7 +523,9 @@ class BaseTool:).model_dump_json(),success=False,)- return await self._screen_read(user_id, session, tool_call_id, kwargs, output)+ return await self._screen_read(+ user_id, session, tool_call_id, kwargs, output, result.outside, full+ )async def _gate(self,@@ -615,8 +617,11 @@ class BaseTool:tool_call_id: str,kwargs: dict[str, Any],result: StreamToolOutputAvailable,+ outside: tuple[Any, ...] | None,+ full: str,) -> StreamToolOutputAvailable:- """Judge the output as the model will receive it, after every cap."""+ """Judge the output as the model will receive it, after every cap: the+ parts ``outside`` declares, or all of it when nothing was declared."""from backend.copilot.gate.reads import model_view, readable_parts, screen_readseen = (@@ -638,6 +643,8 @@ class BaseTool:text=text,images=images,tool_call_id=tool_call_id,+ outside=outside,+ full=full,)if stub is None:return resultdiff --git a/autogpt_platform/backend/backend/copilot/tools/bash_exec.py b/autogpt_platform/backend/backend/copilot/tools/bash_exec.pyindex 78d322fe4a..fda009a138 100644--- a/autogpt_platform/backend/backend/copilot/tools/bash_exec.py+++ b/autogpt_platform/backend/backend/copilot/tools/bash_exec.py@@ -72,7 +72,7 @@ def _build_completion_response(exit_code=exit_code,timed_out=False,session_id=session_id,- )+ ).from_outside(out, err)class BashExecTool(BaseTool):@@ -178,7 +178,7 @@ class BashExecTool(BaseTool):message="No command provided.",error="empty_command",session_id=session_id,- )+ ).from_outside()# Pre-flight redirect: bash sandbox can't reach host-side SDK# tool-result paths. Without this the model burns turns retrying@@ -188,7 +188,7 @@ class BashExecTool(BaseTool):message=sdk_tool_result_redirect_hint(command),error="sdk_tool_result_path_in_bash_command",session_id=session_id,- )+ ).from_outside()sandbox = get_current_sandbox()if sandbox is not None:@@ -207,7 +207,7 @@ class BashExecTool(BaseTool):message="bash_exec requires bubblewrap sandbox (Linux only).",error="sandbox_unavailable",session_id=session_id,- )+ ).from_outside()workspace = get_workspace_dir(session_id or "default")@@ -228,7 +228,7 @@ class BashExecTool(BaseTool):exit_code=exit_code,timed_out=timed_out,session_id=session_id,- )+ ).from_outside(stdout, stderr)async def _execute_on_e2b(self,@@ -292,14 +292,14 @@ class BashExecTool(BaseTool):exit_code=-1,timed_out=True,session_id=session_id,- )+ ).from_outside()except Exception as exc:logger.error("[E2B] bash_exec failed: %s", exc, exc_info=True)return ErrorResponse(message=f"E2B execution failed: {exc}",error="e2b_execution_error",session_id=session_id,- )+ ).from_outside(str(exc))async def _lands_on(path: str) -> bool:diff --git a/autogpt_platform/backend/backend/copilot/tools/capability_gates.py b/autogpt_platform/backend/backend/copilot/tools/capability_gates.pyindex e153cc5660..f7f839e1c5 100644--- a/autogpt_platform/backend/backend/copilot/tools/capability_gates.py+++ b/autogpt_platform/backend/backend/copilot/tools/capability_gates.py@@ -36,4 +36,4 @@ def gate_denied_error(name: str, session_id: str) -> ErrorResponse:),error="tool_disabled",session_id=session_id,- )+ ).from_outside()diff --git a/autogpt_platform/backend/backend/copilot/tools/continue_run_block.py b/autogpt_platform/backend/backend/copilot/tools/continue_run_block.pyindex ed7800b0d5..bf6838fa90 100644--- a/autogpt_platform/backend/backend/copilot/tools/continue_run_block.py+++ b/autogpt_platform/backend/backend/copilot/tools/continue_run_block.py@@ -62,12 +62,12 @@ class ContinueRunBlockTool(BaseTool):if not review_id:return ErrorResponse(message="Please provide a review_id", session_id=session_id- )+ ).from_outside()if not user_id:return ErrorResponse(message="Authentication required", session_id=session_id- )+ ).from_outside()# Look up and validate the review record via adapterreviews = await review_db().get_reviews_by_node_exec_ids([review_id], user_id)@@ -80,27 +80,27 @@ class ContinueRunBlockTool(BaseTool):"It may have been consumed by a previous resume_capability call."),session_id=session_id,- )+ ).from_outside()# Validate the review belongs to this sessionif review.session_id != session_id:return ErrorResponse(message="Review does not belong to this session.",session_id=session_id,- )+ ).from_outside()if review.status == ReviewStatus.WAITING:return ErrorResponse(message="Review has not been approved yet. ""Please wait for the user to approve the review first.",session_id=session_id,- )+ ).from_outside()if review.status == ReviewStatus.REJECTED:return ErrorResponse(message="Review was rejected. The block will not execute.",session_id=session_id,- )+ ).from_outside()# Extract block_id from review_id: copilot-node-{block_id}:{random_hex}block_id = parse_node_id_from_exec_id(review_id).removeprefix(@@ -110,7 +110,7 @@ class ContinueRunBlockTool(BaseTool):if not block:return ErrorResponse(message=f"Block '{block_id}' not found", session_id=session_id- )+ ).from_outside()emit_tool_display_name(block.name)@@ -133,7 +133,7 @@ class ContinueRunBlockTool(BaseTool):return ErrorResponse(message=f"Block '{block.name}' requires credentials that are not configured.",session_id=session_id,- )+ ).from_outside()# dry_run=False is safe here: run_capability's dry-run fast-path skips# HITL entirely, so resume_capability is never called during adiff --git a/autogpt_platform/backend/backend/copilot/tools/delegate_to_expert.py b/autogpt_platform/backend/backend/copilot/tools/delegate_to_expert.pyindex 21568bff08..4e8b139358 100644--- a/autogpt_platform/backend/backend/copilot/tools/delegate_to_expert.py+++ b/autogpt_platform/backend/backend/copilot/tools/delegate_to_expert.py@@ -241,7 +241,9 @@ class DelegateToExpertTool(BaseTool):)def _error(self, message: str, session: ChatSession) -> ErrorResponse:- return ErrorResponse(message=message, session_id=session.session_id)+ return ErrorResponse(+ message=message, session_id=session.session_id+ ).from_outside()async def _load_delegate_target(self, user_id: str, target_id: str, session: ChatSessiondiff --git a/autogpt_platform/backend/backend/copilot/tools/describe_capability.py b/autogpt_platform/backend/backend/copilot/tools/describe_capability.pyindex 38b7d9bad8..0af5c9e6aa 100644--- a/autogpt_platform/backend/backend/copilot/tools/describe_capability.py+++ b/autogpt_platform/backend/backend/copilot/tools/describe_capability.py@@ -162,7 +162,7 @@ def describe_skill(entry: CapabilityEntry, session_id: str) -> ToolResponseBase:capability=entry.listing(),parameters=NO_INPUT,session_id=session_id,- )+ ).from_outside()def _describe_tool(diff --git a/autogpt_platform/backend/backend/copilot/tools/expert_chats.py b/autogpt_platform/backend/backend/copilot/tools/expert_chats.pyindex ea339b7348..67d7ee78c4 100644--- a/autogpt_platform/backend/backend/copilot/tools/expert_chats.py+++ b/autogpt_platform/backend/backend/copilot/tools/expert_chats.py@@ -249,13 +249,13 @@ class ReadExpertChatTool(BaseTool):if user_id is None:return ErrorResponse(message="Authentication required", session_id=session.session_id- )+ ).from_outside()chat_id = (session_id or "").strip()if not chat_id:return ErrorResponse(message="session_id is required",session_id=session.session_id,- )+ ).from_outside()try:page = await chat_db().get_chat_messages_paginated(@@ -272,7 +272,7 @@ class ReadExpertChatTool(BaseTool):return ErrorResponse(message="Could not load that chat right now. Try again.",session_id=session.session_id,- )+ ).from_outside()# Both are excluded from list_expert_chats, so reject them here too —# otherwise fetch-by-id is a way around the listing's scope.@@ -284,7 +284,7 @@ class ReadExpertChatTool(BaseTool):return ErrorResponse(message=_NOT_FOUND.format(session_id=chat_id),session_id=session.session_id,- )+ ).from_outside()rendered = [message@@ -326,7 +326,7 @@ class ReadExpertChatTool(BaseTool):messages=kept,has_more=has_more,next_before_sequence=next_cursor,- )+ ).from_outside(kept, page.session.title)def _clamp(value: int | None, default: int) -> int:diff --git a/autogpt_platform/backend/backend/copilot/tools/feature_requests.py b/autogpt_platform/backend/backend/copilot/tools/feature_requests.pyindex b2d128c690..9086926e08 100644--- a/autogpt_platform/backend/backend/copilot/tools/feature_requests.py+++ b/autogpt_platform/backend/backend/copilot/tools/feature_requests.py@@ -168,7 +168,7 @@ class SearchFeatureRequestsTool(BaseTool):message="Please provide a search query.",error="Missing query parameter",session_id=session_id,- )+ ).from_outside()try:client, project_id, _team_id = _get_linear_config()@@ -194,7 +194,7 @@ class SearchFeatureRequestsTool(BaseTool):"You can create a new feature request if none exists",],session_id=session_id,- )+ ).from_outside()results = [FeatureRequestInfo(@@ -211,14 +211,14 @@ class SearchFeatureRequestsTool(BaseTool):count=len(results),query=query,session_id=session_id,- )+ ).from_outside(results)except Exception as e:logger.exception("Failed to search feature requests")return ErrorResponse(message="Failed to search feature requests.",error=str(e),session_id=session_id,- )+ ).from_outside(str(e))class CreateFeatureRequestTool(BaseTool):diff --git a/autogpt_platform/backend/backend/copilot/tools/gate_subject_test.py b/autogpt_platform/backend/backend/copilot/tools/gate_subject_test.pyindex fae799dc94..493d62ff81 100644--- a/autogpt_platform/backend/backend/copilot/tools/gate_subject_test.py+++ b/autogpt_platform/backend/backend/copilot/tools/gate_subject_test.py@@ -32,9 +32,11 @@ from backend.blocks.search import GetWikipediaSummaryBlockfrom backend.blocks.sql_query_block import SQLQueryBlockfrom backend.copilot.gate import RUN_FILES_KEYfrom backend.copilot.gate.classifier import Judgement+from backend.copilot.gate.content import ContentVerdictfrom backend.copilot.gate.effects import block_effect, graph_effectfrom backend.copilot.gate.headline import Headlinefrom backend.copilot.gate.policy import Effect+from backend.copilot.gate.reads import screen_readfrom backend.copilot.gate.review import review_payloadfrom backend.copilot.gate.subject import workflow_subjectfrom backend.copilot.model import AutopilotMode, ChatSession, ChatSessionMetadata@@ -882,6 +884,40 @@ async def test_a_heredoc_write_into_the_workspace_runs_as_a_file_write(assert asked == int(not runs)+ "command, asked, judged",+ [(_LONG_POST, 0, None), (_LONG_POST + "\necho ok", 1, r"ok\n")],+ ids=["write", "write-then-run"],+)+async def test_a_heredoc_write_is_judged_by_neither_gate_as_the_models_words(+ gate, home, command, asked, judged+):+ """Both gates on the real command: a pure write reaches neither the supervisor+ nor the content judge, and the judge reads only what a command printed."""+ asks = AsyncMock(return_value=Judgement(allowed=True, reason=""))+ judge = AsyncMock(return_value=ContentVerdict(held=False))+ with (+ patch(f"{_GATE}.reads.screen_read", screen_read),+ patch(f"{_GATE}.reads.judge_content", judge),+ patch(f"{_GATE}.supervise", asks),+ patch(f"{_BASH}.selected_credentials", AsyncMock(return_value={})),+ patch(f"{_BASH}.get_integration_env_vars", AsyncMock(return_value={})),+ patch(f"{_BASH}.get_github_user_git_identity", AsyncMock(return_value=None)),+ ):+ result = await BashExecTool().execute(+ "user-1", _session("auto"), "call-1", command=command+ )++ assert json.loads(result.output)["exit_code"] == 0+ assert (home / "workspace/blog/post.md").read_text().startswith("word ")+ assert asks.await_count == asked+ if judged is None:+ judge.assert_not_awaited()+ else:+ assert judge.await_args.kwargs["text"] == judged+ assert judge.await_args.kwargs["source"] == "bash_exec"++@pytest.mark.parametrize("link, points_to",[("workspace/blog/post.md", ".bashrc"), ("workspace/blog", ".config")],diff --git a/autogpt_platform/backend/backend/copilot/tools/get_sub_session_result.py b/autogpt_platform/backend/backend/copilot/tools/get_sub_session_result.pyindex 5ab1b7a788..732c21f84c 100644--- a/autogpt_platform/backend/backend/copilot/tools/get_sub_session_result.py+++ b/autogpt_platform/backend/backend/copilot/tools/get_sub_session_result.py@@ -131,12 +131,12 @@ class GetSubSessionResultTool(BaseTool):return ErrorResponse(message="sub_session_id is required",session_id=session.session_id,- )+ ).from_outside()if user_id is None:return ErrorResponse(message="Authentication required",session_id=session.session_id,- )+ ).from_outside()# Ownership check on every call — loads the ChatSession and# confirms the caller owns it. Returning the same "not found"@@ -150,7 +150,7 @@ class GetSubSessionResultTool(BaseTool):"never existed or belongs to another user."),session_id=session.session_id,- )+ ).from_outside()started_at = time.monotonic()delegate = await _delegated_expert_info(user_id, sub, session)@@ -167,7 +167,7 @@ class GetSubSessionResultTool(BaseTool):"you need instead."),session_id=session.session_id,- )+ ).from_outside()# Fan out the cancel event. Whichever worker is running the# sub will break out of its stream and finalise the session# as failed. Return "cancelled" immediately; the sub may@@ -183,7 +183,7 @@ class GetSubSessionResultTool(BaseTool):sub_autopilot_session_id=inner_session_id,sub_autopilot_session_link=_sub_session_link(inner_session_id),elapsed_seconds=0.0,- ),+ ).from_outside(),delegate,)@@ -235,7 +235,7 @@ class GetSubSessionResultTool(BaseTool):sub_autopilot_session_link=link,elapsed_seconds=round(elapsed, 2),progress=progress,- ),+ ).from_outside(progress),delegate,)diff --git a/autogpt_platform/backend/backend/copilot/tools/helpers.py b/autogpt_platform/backend/backend/copilot/tools/helpers.pyindex b6b8688538..83e55e57e5 100644--- a/autogpt_platform/backend/backend/copilot/tools/helpers.py+++ b/autogpt_platform/backend/backend/copilot/tools/helpers.py@@ -275,7 +275,7 @@ async def execute_block(message=sim_error[0],error=sim_error[0],session_id=session_id,- )+ ).from_outside(sim_error[0])return BlockOutputResponse(message=f"Block '{block.name}' executed successfully",@@ -286,14 +286,14 @@ async def execute_block(success=True,is_dry_run=True,session_id=session_id,- )+ ).from_outside(outputs)except Exception as e:logger.error("Dry-run simulation failed: %s", e, exc_info=True)return ErrorResponse(message=f"Dry-run simulation failed: {e}",error=str(e),session_id=session_id,- )+ ).from_outside(str(e))try:workspace = await workspace_db().get_or_create_workspace(user_id)@@ -393,7 +393,7 @@ async def execute_block(return ErrorResponse(message=f"Failed to retrieve credentials for {field_name}",session_id=session_id,- )+ ).from_outside()if not (credentials is not Noneand provider_matches(credentials.provider, cred_meta.provider)@@ -403,14 +403,14 @@ async def execute_block(return ErrorResponse(message=f"Failed to retrieve credentials for {field_name}",session_id=session_id,- )+ ).from_outside()exec_kwargs[field_name] = credentialsexcept ValueError:await _release_credential_leases(credential_leases)return ErrorResponse(message=f"Failed to retrieve credentials for {credential_field_name}",session_id=session_id,- )+ ).from_outside()except BaseException:await _release_credential_leases(credential_leases)raise@@ -458,10 +458,13 @@ async def execute_block(),graph_id=None,graph_version=None,- )+ ).from_outside()except ValueError as e:await _release_credential_leases(credential_leases)- return ErrorResponse(message=str(e), error=str(e), session_id=session_id)+ # Our wording around the model's own input: nothing from outside.+ return ErrorResponse(+ message=str(e), error=str(e), session_id=session_id+ ).from_outside()except BaseException:await _release_credential_leases(credential_leases)raise@@ -496,7 +499,7 @@ async def execute_block("Please top up your credits to continue."),session_id=session_id,- )+ ).from_outside()# Execute the block under the shared MCP wait cap. A block is# expected to finish in MAX_TOOL_WAIT_SECONDS; if it doesn't, the@@ -541,7 +544,7 @@ async def execute_block(provider=get_block_provider(block),success=True,session_id=session_id,- )+ ).from_outside(outputs)except asyncio.TimeoutError:# Structured record of tool-call timeouts (SECRT-2247 part 3).# Grep prod logs for `copilot_tool_timeout` to find tools that@@ -567,7 +570,7 @@ async def execute_block("so nothing blocks the chat stream."),session_id=session_id,- )+ ).from_outside()finally:# Sentry r3105079148: asyncio.wait_for raises CancelledError# into the generator. Normal `except Exception` doesn't catch@@ -624,14 +627,14 @@ async def execute_block(message=f"Block execution failed: {e}",error=str(e),session_id=session_id,- )+ ).from_outside(str(e))except Exception as e:logger.error("Unexpected error executing block: %s", e, exc_info=True)return ErrorResponse(message=f"Failed to execute block: {str(e)}",error=str(e),session_id=session_id,- )+ ).from_outside(str(e))def _credential_rejected_response(@@ -685,7 +688,7 @@ def _credential_rejected_response(),error="credential_rejected",session_id=session_id,- )+ ).from_outside()def _rejected_credential(@@ -727,6 +730,7 @@ def _build_credential_rejected_card(rejected, provider = _rejected_credential(block, matched_credentials)provider_name = provider.replace("_", " ").title() or "The provider"named = f" '{rejected.title}'" if rejected and rejected.title else ""+ detail = sanitize_provider_message(str(exc))return SetupRequirementsResponse(message=(f"{provider_name} rejected the saved credential{named} "@@ -752,12 +756,12 @@ def _build_credential_rejected_card(),rejection=CredentialRejection(provider=provider or "unknown",- detail=sanitize_provider_message(str(exc)),+ detail=detail,status_code=status_code,credential_id=rejected.id if rejected else None,credential_title=rejected.title if rejected else None,),- )+ ).from_outside(detail)async def _collect_block_outputs(@@ -877,7 +881,7 @@ async def unattended_missing_credentials_error(+ grant_hint,error="missing_credentials",session_id=session_id,- )+ ).from_outside()async def _pinned_account_error(@@ -937,7 +941,7 @@ async def _pinned_account_error(),error="pinned_credential_missing" if lost else "pinned_credential_unusable",session_id=session_id,- )+ ).from_outside()@dataclass@@ -1012,11 +1016,11 @@ async def prepare_block_for_execution(if not block:return ErrorResponse(message=f"Block '{block_id}' not found", session_id=session_id- )+ ).from_outside()if block.disabled:return ErrorResponse(message=f"Block '{block_id}' is disabled", session_id=session_id- )+ ).from_outside()if (block.block_type in COPILOT_EXCLUDED_BLOCK_TYPES@@ -1034,7 +1038,7 @@ async def prepare_block_for_execution(return ErrorResponse(message=f"Block '{block.name}' cannot be run directly.{hint}",session_id=session_id,- )+ ).from_outside()emit_tool_display_name(block.name)@@ -1058,7 +1062,7 @@ async def prepare_block_for_execution(message=f"Block '{block.name}' has an invalid input schema",error=str(e),session_id=session_id,- )+ ).from_outside()# Expand @@agptfile: refs using the block's input schema so string/list# fields get the correct deserialization.@@ -1074,7 +1078,7 @@ async def prepare_block_for_execution("Ensure the file exists before referencing it."),session_id=session_id,- )+ ).from_outside()credentials_fields = set(block.input_schema.get_credentials_fields().keys())required_non_credential_keys = required_input_keys(block)@@ -1154,7 +1158,7 @@ async def prepare_block_for_execution(),graph_id=None,graph_version=None,- )+ ).from_outside()valid_fields = set(input_schema.get("properties", {}).keys()) - credentials_fieldsunrecognized_fields = provided_input_keys - valid_fields@@ -1167,7 +1171,7 @@ async def prepare_block_for_execution(session_id=session_id,unrecognized_fields=sorted(unrecognized_fields),inputs=input_schema,- )+ ).from_outside()synthetic_graph_id = f"{COPILOT_SESSION_PREFIX}{session_id}"synthetic_node_id = f"{COPILOT_NODE_PREFIX}{block_id}"@@ -1237,7 +1241,7 @@ async def check_hitl_review(block_name=block.name,review_id=existing_review.node_exec_id,input_data=input_data,- )+ ).from_outside()synthetic_node_exec_id = (f"{synthetic_node_id}{COPILOT_NODE_EXEC_ID_SEPARATOR}{uuid.uuid4().hex[:8]}"@@ -1275,7 +1279,7 @@ async def check_hitl_review(block_name=block.name,review_id=synthetic_node_exec_id,input_data=input_data,- )+ ).from_outside()return synthetic_node_exec_id, input_data@@ -1315,7 +1319,7 @@ async def check_spend_approval(block_name=prep.block.name,review_id=review_id,input_data=prep.input_data,- )+ ).from_outside()async def metered_expert_id(user_id: str, expert_id: str | None) -> str | None:diff --git a/autogpt_platform/backend/backend/copilot/tools/helpers_test.py b/autogpt_platform/backend/backend/copilot/tools/helpers_test.pyindex 3878b0f812..ae871a7476 100644--- a/autogpt_platform/backend/backend/copilot/tools/helpers_test.py+++ b/autogpt_platform/backend/backend/copilot/tools/helpers_test.py@@ -1468,6 +1468,29 @@ class TestExecuteBlockAutoCredentials:assert isinstance(result, SetupRequirementsResponse)assert result.setup_info.user_readiness.ready_to_run is False+ async def test_a_refused_picker_credential_is_answered_in_our_own_words(self):+ """The error wraps the model's own input in our guidance, so the content+ judge has nothing from outside in it to read."""+ block = _make_block_with_auto_creds()+ credit_patch, _ = _patch_credit_db()++ with _patch_workspace(), credit_patch:+ result = await execute_block(+ block=block,+ block_id="drive-consumer",+ input_data={+ "spreadsheet": {"id": "f", "name": "Q3.xlsx", "_credentials_id": ""}+ },+ user_id=_USER,+ session_id=_SESSION,+ node_exec_id="exec-drive-refused",+ matched_credentials={},+ dry_run=False,+ )++ assert isinstance(result, ErrorResponse) and "re-select" in result.message+ assert result.outside == ()+async def test_auto_cred_locks_released_when_coerce_raises(self):"""Regression guard for Sentry r3135420231: if coerce_inputs_to_schemaraises between acquire_auto_credentials and the inner wait_for try,diff --git a/autogpt_platform/backend/backend/copilot/tools/models.py b/autogpt_platform/backend/backend/copilot/tools/models.pyindex a6d8112f3a..dfd81cbb6d 100644--- a/autogpt_platform/backend/backend/copilot/tools/models.py+++ b/autogpt_platform/backend/backend/copilot/tools/models.py@@ -2,9 +2,9 @@from datetime import datetimefrom enum import Enum-from typing import Any, Literal+from typing import Any, Literal, Self-from pydantic import BaseModel, Field, model_validator+from pydantic import BaseModel, Field, PrivateAttr, model_validatorfrom backend.copilot.tools.execution_utils import NodeFailureSummaryfrom backend.data.graph import BaseGraph, GraphTriggerInfo@@ -159,6 +159,21 @@ class ToolResponseBase(BaseModel):type: ResponseTypemessage: strsession_id: str | None = None+ # None until the producer declares it, and the content judge then reads the+ # whole response.+ _outside: tuple[Any, ...] | None = PrivateAttr(default=None)++ def from_outside(self, *parts: Any) -> Self:+ """Declare the values in this response that came from outside AutoGPT,+ exactly as placed in it; with none, the response is wholly ours. The+ content judge reads only these, and every image. An agent's name,+ description and schema count as ours: discovery returns them unjudged."""+ self._outside = (*(self._outside or ()), *parts)+ return self++ @property+ def outside(self) -> tuple[Any, ...] | None:+ return self._outside# Agent discovery modelsdiff --git a/autogpt_platform/backend/backend/copilot/tools/resume_capability.py b/autogpt_platform/backend/backend/copilot/tools/resume_capability.pyindex f3377ee916..c10f2c7b6f 100644--- a/autogpt_platform/backend/backend/copilot/tools/resume_capability.py+++ b/autogpt_platform/backend/backend/copilot/tools/resume_capability.py@@ -86,15 +86,15 @@ class ResumeCapabilityTool(BaseTool):if not review_id:return ErrorResponse(message="Please provide a review_id", session_id=session_id- )+ ).from_outside()if not user_id:return ErrorResponse(message="Authentication required", session_id=session_id- )+ ).from_outside()if input_overrides is not None and not isinstance(input_overrides, dict):return ErrorResponse(message="input_overrides must be an object", session_id=session_id- )+ ).from_outside()if SPEND_REVIEW_MARKER in review_id:# A spend approval releases an expert's budget; there is no block# behind it to re-run, and parsing one out of the id fails.@@ -105,7 +105,7 @@ class ResumeCapabilityTool(BaseTool):"and there is nothing here to resume."),session_id=session.session_id,- )+ ).from_outside()# Resuming runs the capability, so it answers to the gate the run# would have. Permissions, hidden tools and the turn envelope are all# rebuilt per turn, and an approval from an earlier turn is not a@@ -136,21 +136,21 @@ async def _load_approved_review("been consumed by an earlier resume_capability call."),session_id=session_id,- )+ ).from_outside()if review.session_id != session_id:return ErrorResponse(message="Review does not belong to this session.", session_id=session_id- )+ ).from_outside()if review.status == ReviewStatus.WAITING:return ErrorResponse(message="Review has not been approved yet. Wait for the user to approve it.",session_id=session_id,- )+ ).from_outside()if review.status == ReviewStatus.REJECTED:return ErrorResponse(message="Review was rejected. The capability will not run.",session_id=session_id,- )+ ).from_outside()return review@@ -170,7 +170,7 @@ async def _resume_mcp(return ErrorResponse(message="Stored review payload is not an MCP call.",session_id=session.session_id,- )+ ).from_outside()arguments = {**payload.arguments, **(input_overrides or {})}if arguments != payload.arguments:# The user approved one call, not a family of them. This review only@@ -203,7 +203,7 @@ async def _resume_mcp(block_name=f"{host}/{payload.tool}",review_id=new_id,input_data=fresh.model_dump(),- )+ ).from_outside()result = await RunMCPToolTool()._execute(user_id,session,diff --git a/autogpt_platform/backend/backend/copilot/tools/run_agent.py b/autogpt_platform/backend/backend/copilot/tools/run_agent.pyindex f7f3ac27c4..6a43642b24 100644--- a/autogpt_platform/backend/backend/copilot/tools/run_agent.py+++ b/autogpt_platform/backend/backend/copilot/tools/run_agent.py@@ -357,14 +357,14 @@ class RunAgentTool(BaseTool):"(format 'username/agent-name') or a library_agent_id"),session_id=session_id,- )+ ).from_outside()# Auth is requiredif not user_id:return ErrorResponse(message="Authentication required. Please sign in to use this tool.",session_id=session_id,- )+ ).from_outside()# Determine if this is a schedule requestis_schedule = bool(params.schedule_name or params.cron)@@ -379,7 +379,7 @@ class RunAgentTool(BaseTool):"a run, or disable dry-run to create a real schedule."),session_id=session_id,- )+ ).from_outside()try:# Step 1: Fetch agent details@@ -390,7 +390,7 @@ class RunAgentTool(BaseTool):return ErrorResponse(message=f"Library agent '{params.library_agent_id}' not found",session_id=session_id,- )+ ).from_outside()if not graph:identifier = (params.library_agent_id@@ -400,7 +400,7 @@ class RunAgentTool(BaseTool):return ErrorResponse(message=f"Agent '{identifier}' not found",session_id=session_id,- )+ ).from_outside()scope_error = await require_installed_workflow(user_id,session,@@ -423,7 +423,7 @@ class RunAgentTool(BaseTool):),error="builder_session_graph_mismatch",session_id=session_id,- )+ ).from_outside()# Webhook-trigger agents can't be run or scheduled directly — they# fire on incoming HTTP events. Hand off to the trigger-setup tool,@@ -447,7 +447,7 @@ class RunAgentTool(BaseTool):user_authenticated=True,graph_id=graph.id,graph_version=graph.version,- )+ ).from_outside()# Step 2: Check credentials and inputsgraph_credentials, prereq_error = await self._check_prerequisites(@@ -504,13 +504,13 @@ class RunAgentTool(BaseTool):message="This expert is no longer available. Please start a new chat.",error="expert_not_found",session_id=session_id,- )+ ).from_outside()except NotFoundError as e:return ErrorResponse(message=f"Agent '{params.username_agent_slug}' not found",error=str(e) if str(e) else "not_found",session_id=session_id,- )+ ).from_outside()except MissingConfigError:return ErrorResponse(message=(@@ -524,21 +524,21 @@ class RunAgentTool(BaseTool):else "configuration_unavailable"),session_id=session_id,- )+ ).from_outside()except DatabaseError as e:logger.error("Database error: %s", e, exc_info=True)return ErrorResponse(message=f"Failed to process request: {e!s}",error=str(e),session_id=session_id,- )+ ).from_outside(str(e))except Exception as e:logger.error("Error processing agent request: %s", e, exc_info=True)return ErrorResponse(message=f"Failed to process request: {e!s}",error=str(e),session_id=session_id,- )+ ).from_outside(str(e))def _get_execution_modes(self, graph: GraphModel) -> list[str]:"""Get available execution modes for the graph."""@@ -654,7 +654,7 @@ class RunAgentTool(BaseTool):),graph_id=graph.id,graph_version=graph.version,- )+ ).from_outside()async def _handle_graph_validation_race(self,@@ -696,7 +696,7 @@ class RunAgentTool(BaseTool):),error="graph_validation_failed",session_id=session_id,- )+ ).from_outside()async def _check_prerequisites(self,@@ -725,16 +725,19 @@ class RunAgentTool(BaseTool):valid_fields = set(input_properties.keys())unrecognized_fields = provided_inputs - valid_fieldsif unrecognized_fields:- return graph_credentials, InputValidationErrorResponse(- message=(- f"Unknown input field(s) provided: {', '.join(sorted(unrecognized_fields))}. "- f"Agent was not executed. Please use the correct field names from the schema."- ),- session_id=session_id,- unrecognized_fields=sorted(unrecognized_fields),- inputs=graph.input_schema,- graph_id=graph.id,- graph_version=graph.version,+ return (+ graph_credentials,+ InputValidationErrorResponse(+ message=(+ f"Unknown input field(s) provided: {', '.join(sorted(unrecognized_fields))}. "+ f"Agent was not executed. Please use the correct field names from the schema."+ ),+ session_id=session_id,+ unrecognized_fields=sorted(unrecognized_fields),+ inputs=graph.input_schema,+ graph_id=graph.id,+ graph_version=graph.version,+ ).from_outside(),)# Dry runs bypass remaining prerequisite gates (credentials, missing inputs)@@ -757,37 +760,40 @@ class RunAgentTool(BaseTool):user_id,expert_id,)- return graph_credentials, SetupRequirementsResponse(- message=self._build_inputs_message(graph, MSG_WHAT_VALUES_TO_USE)- + await ungranted_credential_hint(- user_id,- expert_id,- {- provider_slug(m.get("provider", ""))- for m in missing_credentials_dict.values()- }- - {""},- missing_credentials_dict.values(),- ),- session_id=session_id,- setup_info=SetupInfo(- agent_id=graph.id,- agent_name=graph.name,- user_readiness=UserReadiness(- has_all_credentials=False,- missing_credentials=missing_credentials_dict,- ready_to_run=False,+ return (+ graph_credentials,+ SetupRequirementsResponse(+ message=self._build_inputs_message(graph, MSG_WHAT_VALUES_TO_USE)+ + await ungranted_credential_hint(+ user_id,+ expert_id,+ {+ provider_slug(m.get("provider", ""))+ for m in missing_credentials_dict.values()+ }+ - {""},+ missing_credentials_dict.values(),),- requirements={- "credentials": list(requirements_creds_dict.values()),- "inputs": get_picker_inputs_from_schema(- graph.input_schema, input_data=params.inputs+ session_id=session_id,+ setup_info=SetupInfo(+ agent_id=graph.id,+ agent_name=graph.name,+ user_readiness=UserReadiness(+ has_all_credentials=False,+ missing_credentials=missing_credentials_dict,+ ready_to_run=False,),- "execution_modes": self._get_execution_modes(graph),- },- ),- graph_id=graph.id,- graph_version=graph.version,+ requirements={+ "credentials": list(requirements_creds_dict.values()),+ "inputs": get_picker_inputs_from_schema(+ graph.input_schema, input_data=params.inputs+ ),+ "execution_modes": self._get_execution_modes(graph),+ },+ ),+ graph_id=graph.id,+ graph_version=graph.version,+ ).from_outside(),)# --- Input gates ---@@ -798,13 +804,16 @@ class RunAgentTool(BaseTool):credentials = extract_credentials_from_schema(graph.credentials_input_schema)- return graph_credentials, AgentDetailsResponse(- message=self._build_inputs_message(graph, MSG_ASK_USER_FOR_VALUES),- session_id=session_id,- agent=self._build_agent_details(graph, credentials),- user_authenticated=True,- graph_id=graph.id,- graph_version=graph.version,+ return (+ graph_credentials,+ AgentDetailsResponse(+ message=self._build_inputs_message(graph, MSG_ASK_USER_FOR_VALUES),+ session_id=session_id,+ agent=self._build_agent_details(graph, credentials),+ user_authenticated=True,+ graph_id=graph.id,+ graph_version=graph.version,+ ).from_outside(),)# Required inputs missing@@ -813,17 +822,20 @@ class RunAgentTool(BaseTool):credentials = extract_credentials_from_schema(graph.credentials_input_schema)- return graph_credentials, AgentDetailsResponse(- message=(- f"Agent '{graph.name}' is missing required inputs: "- f"{', '.join(missing_inputs)}. "- "Please provide these values to run the agent."- ),- session_id=session_id,- agent=self._build_agent_details(graph, credentials),- user_authenticated=True,- graph_id=graph.id,- graph_version=graph.version,+ return (+ graph_credentials,+ AgentDetailsResponse(+ message=(+ f"Agent '{graph.name}' is missing required inputs: "+ f"{', '.join(missing_inputs)}. "+ "Please provide these values to run the agent."+ ),+ session_id=session_id,+ agent=self._build_agent_details(graph, credentials),+ user_authenticated=True,+ graph_id=graph.id,+ graph_version=graph.version,+ ).from_outside(),)return graph_credentials, None@@ -841,7 +853,7 @@ class RunAgentTool(BaseTool):return ErrorResponse(message="Authentication required. Please sign in to use this tool.",session_id=session_id,- )+ ).from_outside()if params.username_agent_slug or params.library_agent_id:return ErrorResponse(message=(@@ -849,7 +861,7 @@ class RunAgentTool(BaseTool):"(username_agent_slug / library_agent_id), not both."),session_id=session_id,- )+ ).from_outside()if params.save_as_preset:return ErrorResponse(message=(@@ -857,14 +869,14 @@ class RunAgentTool(BaseTool):"the preset already exists."),session_id=session_id,- )+ ).from_outside()if params.schedule_name or params.cron:return ErrorResponse(message=("preset_id runs the preset now; schedule it separately instead."),session_id=session_id,- )+ ).from_outside()preset, graph = await _preset_graph(user_id, session, params.preset_id)if not preset:@@ -872,7 +884,7 @@ class RunAgentTool(BaseTool):message=f"Preset '{params.preset_id}' not found.",error="preset_not_found",session_id=session_id,- )+ ).from_outside()if not graph:return ErrorResponse(message=(@@ -880,7 +892,7 @@ class RunAgentTool(BaseTool):"accessible (anymore)."),session_id=session_id,- )+ ).from_outside()scope_error = await require_installed_workflow(user_id, session, graph_id=graph.id, name=graph.name)@@ -899,7 +911,7 @@ class RunAgentTool(BaseTool):),error="builder_session_graph_mismatch",session_id=session_id,- )+ ).from_outside()# A webhook-triggered preset fires on its external event; it has no# runnable payload here, so executing it directly would fail downstream.@@ -914,7 +926,7 @@ class RunAgentTool(BaseTool):),error="preset_is_webhook_trigger",session_id=session_id,- )+ ).from_outside()merged_inputs = {**preset.inputs, **params.inputs}return await self._run_agent(@@ -986,7 +998,7 @@ class RunAgentTool(BaseTool):return ErrorResponse(message="Maximum agent runs reached for this session. Please try again later.",session_id=session_id,- )+ ).from_outside()# Get or create library agentlibrary_agent = await get_or_create_library_agent(graph, user_id)@@ -1055,7 +1067,7 @@ class RunAgentTool(BaseTool):library_agent_id=library_agent.id,library_agent_link=library_agent_link,status=ExecutionStatus.REVIEW.value,- )+ ).from_outside()# Track successful run (dry runs don't count against the session limit)if not dry_run:@@ -1162,7 +1174,7 @@ class RunAgentTool(BaseTool):node_executions=node_executions_data,nodes_failed=node_failures or None,),- )+ ).from_outside(outputs, node_executions_data, node_failures)elif completed and completed.status == ExecutionStatus.FAILED:error_detail = completed.stats.error if completed.stats else None# Auto-share the failed run too — share-modal users may@@ -1181,7 +1193,7 @@ class RunAgentTool(BaseTool):session_id=session_id,execution_id=execution.id,error=error_detail,- )+ ).from_outside(error_detail)elif completed and completed.status == ExecutionStatus.TERMINATED:error_detail = completed.stats.error if completed.stats else None# Auto-share terminated runs (cancelled / killed) for the@@ -1198,7 +1210,7 @@ class RunAgentTool(BaseTool):session_id=session_id,execution_id=execution.id,error=error_detail,- )+ ).from_outside(error_detail)elif completed and completed.status == ExecutionStatus.REVIEW:await _safe_link_to_chat_share(session_id=session_id, execution_id=execution.id@@ -1217,7 +1229,7 @@ class RunAgentTool(BaseTool):library_agent_id=library_agent.id,library_agent_link=library_agent_link,status=ExecutionStatus.REVIEW.value,- )+ ).from_outside()else:status = completed.status.value if completed else "unknown"await _safe_link_to_chat_share(@@ -1237,7 +1249,7 @@ class RunAgentTool(BaseTool):library_agent_id=library_agent.id,library_agent_link=library_agent_link,status=status,- )+ ).from_outside()await _safe_link_to_chat_share(session_id=session_id, execution_id=execution.id)return ExecutionStartedResponse(@@ -1252,7 +1264,7 @@ class RunAgentTool(BaseTool):graph_name=library_agent.name,library_agent_id=library_agent.id,library_agent_link=library_agent_link,- )+ ).from_outside()async def _schedule_agent(self,@@ -1274,12 +1286,12 @@ class RunAgentTool(BaseTool):return ErrorResponse(message="schedule_name is required for scheduled execution",session_id=session_id,- )+ ).from_outside()if not cron:return ErrorResponse(message="cron expression is required for scheduled execution",session_id=session_id,- )+ ).from_outside()# Check rate limitsif (@@ -1289,7 +1301,7 @@ class RunAgentTool(BaseTool):return ErrorResponse(message="Maximum agent schedules reached for this session.",session_id=session_id,- )+ ).from_outside()# Precedence mirrors POST /graphs/{graph_id}/schedules: an explicit# timezone wins over the user's stored preference, which wins over UTC.@@ -1306,7 +1318,7 @@ class RunAgentTool(BaseTool):),error="invalid_timezone",session_id=session_id,- )+ ).from_outside()user_timezone = timezoneelse:user = await user_db().get_user_by_id(user_id)@@ -1395,7 +1407,7 @@ class RunAgentTool(BaseTool):library_agent_id=library_agent.id,library_agent_link=library_agent_link,status=SCHEDULED_STATUS,- )+ ).from_outside()# One lookup for the run and for the gate: were they two, a drift betweendiff --git a/autogpt_platform/backend/backend/copilot/tools/run_block.py b/autogpt_platform/backend/backend/copilot/tools/run_block.pyindex 6fcab54bac..4b5dd4ecaf 100644--- a/autogpt_platform/backend/backend/copilot/tools/run_block.py+++ b/autogpt_platform/backend/backend/copilot/tools/run_block.py@@ -143,19 +143,19 @@ class RunBlockTool(BaseTool):return ErrorResponse(message="Please provide a block_id",session_id=session_id,- )+ ).from_outside()if not isinstance(input_data, dict):return ErrorResponse(message="input_data must be an object",session_id=session_id,- )+ ).from_outside()if not user_id:return ErrorResponse(message="Authentication required",session_id=session_id,- )+ ).from_outside()logger.info("Preparing block %s for user %s", block_id, user_id)@@ -191,7 +191,7 @@ class RunBlockTool(BaseTool):"Use find_capability to discover blocks that are allowed."),session_id=session_id,- )+ ).from_outside()# Dry-run fast-path: skip credential/HITL checks — simulation never calls# the real service so credentials and review gates are not needed.@@ -235,7 +235,7 @@ class RunBlockTool(BaseTool):message=f"Block '{prep.block.name}' has an invalid output schema",error=str(e),session_id=session_id,- )+ ).from_outside()credentials_meta = list(prep.matched_credentials.values())missing = sorted(@@ -279,7 +279,7 @@ class RunBlockTool(BaseTool):credentials=credentials_meta,),user_authenticated=True,- )+ ).from_outside()if not dry_run:spend_gate = await check_spend_approval(prep, user_id, session)diff --git a/autogpt_platform/backend/backend/copilot/tools/run_capability.py b/autogpt_platform/backend/backend/copilot/tools/run_capability.pyindex cf9f2948fe..b44ed462bd 100644--- a/autogpt_platform/backend/backend/copilot/tools/run_capability.py+++ b/autogpt_platform/backend/backend/copilot/tools/run_capability.py@@ -161,11 +161,11 @@ class RunCapabilityTool(BaseTool):if not user_id:return ErrorResponse(message="Authentication required", session_id=session_id- )+ ).from_outside()if input is not None and not isinstance(input, dict):return ErrorResponse(message="input must be an object", session_id=session_id- )+ ).from_outside()payload: dict[str, Any] = dict(input or {})entry = await resolve_session_entry(user_id, session, id)if entry is None and id.strip().lower().startswith("https://"):@@ -184,9 +184,11 @@ class RunCapabilityTool(BaseTool):"server's secure endpoint."),session_id=session_id,- )+ ).from_outside()if entry is None:- return ErrorResponse(message=UNKNOWN_ID_HINT, session_id=session_id)+ return ErrorResponse(+ message=UNKNOWN_ID_HINT, session_id=session_id+ ).from_outside()if entry.kind == "block":return await _run_block(entry, user_id, session, payload, validate_only, approved@@ -201,14 +203,14 @@ class RunCapabilityTool(BaseTool):return ErrorResponse(message=setup_hint(entry.schema_ref or entry.id),session_id=session_id,- )+ ).from_outside()return await _run_mcp(entry, server_url, user_id, session, payload, validate_only)return ErrorResponse(message=f"Capabilities of kind '{entry.kind}' cannot run yet.",session_id=session_id,- )+ ).from_outside()async def _run_block(@@ -255,7 +257,9 @@ async def _describe_tool(name = entry.implementations[0].reftool = configured_tool(name)if tool is None:- return ErrorResponse(message=UNKNOWN_ID_HINT, session_id=session.session_id)+ return ErrorResponse(+ message=UNKNOWN_ID_HINT, session_id=session.session_id+ ).from_outside()if gate_denied(name):return gate_denied_error(name, session.session_id)return CapabilityDetailsResponse(@@ -263,7 +267,7 @@ async def _describe_tool(capability=entry.listing(),parameters=tool.parameters,session_id=session.session_id,- )+ ).from_outside()async def _run_skill(@@ -299,7 +303,7 @@ async def _run_mcp(if arguments is not None and not isinstance(arguments, dict):return ErrorResponse(message="input.arguments must be an object", session_id=session.session_id- )+ ).from_outside()connect = bool(payload.get("connect", False))if validate_only:return CapabilityDetailsResponse(@@ -312,7 +316,7 @@ async def _run_mcp(),parameters=MCP_RUN_PARAMETERS,session_id=session.session_id,- )+ ).from_outside()host = urlsplit(server_url).hostname or server_url# With the gate on it has already decided this call on the server's# effect map; the verb heuristic is the flag-off path only.@@ -344,7 +348,7 @@ async def _run_mcp(block_name=f"{host}/{tool_name}",review_id=review_id,input_data=review.model_dump(),- )+ ).from_outside()if tool_name:emit_tool_display_name(f"{host}: {tool_name}")return await RunMCPToolTool()._execute(diff --git a/autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py b/autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.pyindex 9c55d01a27..2d9598884e 100644--- a/autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py+++ b/autogpt_platform/backend/backend/copilot/tools/run_mcp_tool.py@@ -168,13 +168,13 @@ class RunMCPToolTool(BaseTool):result=None,success=True,session_id=session_id,- )+ ).from_outside()if tool_arguments is not None and not isinstance(tool_arguments, dict):return ErrorResponse(message="tool_arguments must be a JSON object.",session_id=session_id,- )+ ).from_outside()resolved_tool_arguments: dict[str, Any] = (tool_arguments if isinstance(tool_arguments, dict) else {})@@ -183,7 +183,7 @@ class RunMCPToolTool(BaseTool):return ErrorResponse(message="Please provide a server_url for the MCP server.",session_id=session_id,- )+ ).from_outside()_parsed = urlparse(server_url)if _parsed.username or _parsed.password:@@ -193,7 +193,7 @@ class RunMCPToolTool(BaseTool):"Use the MCP credential setup flow instead."),session_id=session_id,- )+ ).from_outside()if _parsed.query or _parsed.fragment:return ErrorResponse(message=(@@ -201,13 +201,13 @@ class RunMCPToolTool(BaseTool):"Use the MCP credential setup flow instead."),session_id=session_id,- )+ ).from_outside()if not user_id:return ErrorResponse(message="Authentication required.",session_id=session_id,- )+ ).from_outside()# Validate URL to prevent SSRF — blocks loopback and private IP rangestry:@@ -221,7 +221,7 @@ class RunMCPToolTool(BaseTool):)else:user_msg = f"Blocked server URL: {msg}"- return ErrorResponse(message=user_msg, session_id=session_id)+ return ErrorResponse(message=user_msg, session_id=session_id).from_outside()# Fast DB lookup — no network call.# Normalize for matching because stored credentials use normalized URLs.@@ -391,7 +391,7 @@ class RunMCPToolTool(BaseTool):),session_id=session_id,error=f"HTTP {e.status_code}: {str(e)[:300]}",- )+ ).from_outside(str(e)[:300])return await self._build_setup_requirements(server_url,session_id,@@ -406,14 +406,14 @@ class RunMCPToolTool(BaseTool):message=(f"MCP request to {host} failed with HTTP {e.status_code}."),session_id=session_id,error=f"HTTP {e.status_code}: {str(e)[:300]}",- )+ ).from_outside(str(e)[:300])except MCPClientError as e:logger.warning("MCP client error for %s: %s", server_host(server_url), e)return ErrorResponse(message=str(e),session_id=session_id,- )+ ).from_outside(str(e))except Exception:logger.error(@@ -424,7 +424,7 @@ class RunMCPToolTool(BaseTool):return ErrorResponse(message="An unexpected error occurred connecting to the MCP server. Please try again.",session_id=session_id,- )+ ).from_outside()finally:# Release any legacy session; a no-op on stateless servers.await client.close()@@ -479,7 +479,7 @@ class RunMCPToolTool(BaseTool):server_url=server_url,tools=tool_infos,session_id=session_id,- )+ ).from_outside(tool_infos)async def _execute_tool(self,@@ -521,7 +521,7 @@ class RunMCPToolTool(BaseTool):"Ensure the file exists before referencing it."),session_id=session_id,- )+ ).from_outside()result = await client.call_tool(tool_name, tool_arguments, input_schema=input_schema@@ -533,14 +533,14 @@ class RunMCPToolTool(BaseTool):for item in result.contentif item.get("type") == "text")- hint = await self._build_error_hint(client, tool_name)+ hint, listed = await self._build_error_hint(client, tool_name)return ErrorResponse(message=(f"MCP tool '{tool_name}' returned an error: "f"{error_text or 'Unknown error'}{hint}"),session_id=session_id,- )+ ).from_outside(error_text, listed)result_value = parse_mcp_content(result.content)@@ -551,10 +551,13 @@ class RunMCPToolTool(BaseTool):result=result_value,success=True,session_id=session_id,- )+ ).from_outside(result_value)- async def _build_error_hint(self, client: MCPClient, tool_name: str) -> str:- """Self-correction hint appended to tool-error responses.+ async def _build_error_hint(+ self, client: MCPClient, tool_name: str+ ) -> tuple[str, str]:+ """Self-correction hint appended to tool-error responses, and the part+ of it the server wrote.Discovery omits full input schemas (context cost), so this is wherethe model gets the one schema it actually needs: the failed tool's.@@ -567,16 +570,16 @@ class RunMCPToolTool(BaseTool):match = next((t for t in tools if t.name == tool_name), None)if match is not None:schema_json = _bounded_schema_hint(match.input_schema)- return f" Input schema for '{tool_name}': {schema_json}"+ return f" Input schema for '{tool_name}': {schema_json}", schema_jsonnames = ", ".join(t.name for t in tools[:40])return (f" No tool named '{tool_name}' exists on this server. "f"Available tools: {names}"- )+ ), namesexcept Exception:# Best-effort — a failed hint lookup must not mask the original# tool error.- return ""+ return "", ""async def _lookup_tool_schema(self,@@ -654,7 +657,7 @@ class RunMCPToolTool(BaseTool):"— no credentials configured."),session_id=session_id,- )+ ).from_outside()if user_id is not None and not connected:missing_creds_dict = await annotate_expert_grants(@@ -711,7 +714,7 @@ class RunMCPToolTool(BaseTool):graph_id=None,graph_version=None,rejection=rejection,- )+ ).from_outside(rejection.detail if rejection else None)def _rejection(creds: OAuth2Credentials, error: HTTPClientError) -> CredentialRejection:diff --git a/autogpt_platform/backend/backend/copilot/tools/run_sub_session.py b/autogpt_platform/backend/backend/copilot/tools/run_sub_session.pyindex 93f53f47bc..cac6d3e582 100644--- a/autogpt_platform/backend/backend/copilot/tools/run_sub_session.py+++ b/autogpt_platform/backend/backend/copilot/tools/run_sub_session.py@@ -139,12 +139,12 @@ class RunSubSessionTool(BaseTool):return ErrorResponse(message="prompt is required",session_id=session.session_id,- )+ ).from_outside()if user_id is None:return ErrorResponse(message="Authentication required",session_id=session.session_id,- )+ ).from_outside()# Resolve the sub's ChatSession id — either resume an owned one or# create a fresh session that inherits the parent's dry_run so a@@ -162,7 +162,7 @@ class RunSubSessionTool(BaseTool):"run_sub_session call of yours."),session_id=session.session_id,- )+ ).from_outside()if owned.expert_id != session.expert_id:return ErrorResponse(message=(@@ -171,7 +171,7 @@ class RunSubSessionTool(BaseTool):"fresh sub for this assistant."),session_id=session.session_id,- )+ ).from_outside()# Only the session that opened a sub may steer it: same scope is# not enough, or any sibling — or the sub itself — could queue a# prompt into it under its envelope rather than their own.@@ -193,7 +193,7 @@ class RunSubSessionTool(BaseTool):"sub."),session_id=session.session_id,- )+ ).from_outside()# Subs are created as automations below, so only a sub may be# resumed as one. Otherwise this tool would run a model-authored# prompt inside an interactive session the caller happens to own,@@ -214,7 +214,7 @@ class RunSubSessionTool(BaseTool):"session."),session_id=session.session_id,- )+ ).from_outside()if (owned.metadata.llm_auth_provider != session.metadata.llm_auth_provideror owned.metadata.llm_credential_id@@ -223,7 +223,7 @@ class RunSubSessionTool(BaseTool):return ErrorResponse(message="codex_session_route_mismatch",session_id=session.session_id,- )+ ).from_outside()inner_session_id = sub_session_paramopened_here = Falseelse:@@ -297,7 +297,7 @@ class RunSubSessionTool(BaseTool):# handles — the same shape handoff_to_expert returns on refusal.return ErrorResponse(message=outcome_response.message, session_id=session.session_id- )+ ).from_outside()return outcome_response@@ -510,7 +510,7 @@ def response_from_outcome(sub_autopilot_session_id=inner_session_id,sub_autopilot_session_link=link,elapsed_seconds=round(elapsed, 2),- )+ ).from_outside()if outcome == "running":return SubSessionStatusResponse(@@ -526,7 +526,7 @@ def response_from_outcome(sub_autopilot_session_id=inner_session_id,sub_autopilot_session_link=link,elapsed_seconds=round(elapsed, 2),- )+ ).from_outside()if outcome == "refused":# The turn never started; the tree or the target said why.@@ -538,7 +538,7 @@ def response_from_outcome(sub_autopilot_session_id=inner_session_id,sub_autopilot_session_link=link,elapsed_seconds=round(elapsed, 2),- )+ ).from_outside()if outcome == "rejected_concurrent_turn_cap":# No sub-session record / transcript exists yet — the per-user@@ -553,7 +553,7 @@ def response_from_outcome(sub_autopilot_session_id=inner_session_id,sub_autopilot_session_link=link,elapsed_seconds=round(elapsed, 2),- )+ ).from_outside()if outcome == "failed":return SubSessionStatusResponse(@@ -564,7 +564,7 @@ def response_from_outcome(sub_autopilot_session_id=inner_session_id,sub_autopilot_session_link=link,elapsed_seconds=round(elapsed, 2),- )+ ).from_outside()# completed — prefer the authoritative listing supplied by the caller;# fall back to mining the tool-call log when it's unavailable.@@ -590,4 +590,4 @@ def response_from_outcome(sub_tool_call_count=len(result.tool_calls),sub_workspace_files=workspace_files or None,elapsed_seconds=round(elapsed, 2),- )+ ).from_outside(result.response_text, workspace_files)diff --git a/autogpt_platform/backend/backend/copilot/tools/web_fetch.py b/autogpt_platform/backend/backend/copilot/tools/web_fetch.pyindex a2bb33e7e5..3aeb64be9d 100644--- a/autogpt_platform/backend/backend/copilot/tools/web_fetch.py+++ b/autogpt_platform/backend/backend/copilot/tools/web_fetch.py@@ -202,7 +202,7 @@ class WebFetchTool(BaseTool):message="Please provide a URL to fetch.",error="missing_url",session_id=session_id,- )+ ).from_outside()try:client = Requests(raise_for_status=False, retry_max_attempts=1)@@ -213,14 +213,14 @@ class WebFetchTool(BaseTool):message=f"URL blocked: {e}",error="url_blocked",session_id=session_id,- )+ ).from_outside()except Exception as e:logger.warning(f"[web_fetch] Request failed for {url}: {e}")return ErrorResponse(message=f"Failed to fetch URL: {e}",error="fetch_failed",session_id=session_id,- )+ ).from_outside(str(e))content_type = response.headers.get("content-type", "")if not _is_text_content(content_type):@@ -228,7 +228,7 @@ class WebFetchTool(BaseTool):message=f"Non-text content type: {content_type.split(';')[0]}",error="unsupported_content_type",session_id=session_id,- )+ ).from_outside(content_type.split(";")[0])raw_bytes = response.content[:_MAX_DOWNLOAD_BYTES]raw_text = raw_bytes.decode("utf-8", errors="replace")@@ -253,6 +253,7 @@ class WebFetchTool(BaseTool):text_truncated = Truetruncated = raw_truncated or text_truncated+ page = textmessage = f"Fetched {url}"@@ -288,4 +289,4 @@ class WebFetchTool(BaseTool):content_length=len(response.content),truncated=truncated,session_id=session_id,- )+ ).from_outside(page, title, response.url, content_type.split(";")[0].strip())diff --git a/autogpt_platform/backend/backend/copilot/tools/web_search.py b/autogpt_platform/backend/backend/copilot/tools/web_search.pyindex ed54868917..6add6389e6 100644--- a/autogpt_platform/backend/backend/copilot/tools/web_search.py+++ b/autogpt_platform/backend/backend/copilot/tools/web_search.py@@ -139,7 +139,7 @@ class WebSearchTool(BaseTool):message="Please provide a non-empty search query.",error="missing_query",session_id=session_id,- )+ ).from_outside()try:max_results = int(max_results)@@ -155,7 +155,7 @@ class WebSearchTool(BaseTool):),error="web_search_not_configured",session_id=session_id,- )+ ).from_outside()client = AsyncOpenAI(api_key=_chat_config.api_key, base_url=_chat_config.base_url@@ -181,7 +181,7 @@ class WebSearchTool(BaseTool):message=f"Web search failed: {exc}",error="web_search_failed",session_id=session_id,- )+ ).from_outside(str(exc))answer = _extract_answer(resp)results = _extract_results(resp, limit=max_results)@@ -208,7 +208,7 @@ class WebSearchTool(BaseTool):results=results,search_requests=1 if results else 0,session_id=session_id,- )+ ).from_outside(answer, results)def _extract_answer(resp: ChatCompletion) -> str: