Skip to content

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(backend): keep block and agent inputs off the copilot setup card (#14448)

Ubbe629e9a95c650
diff --git a/autogpt_platform/backend/backend/copilot/prompting.py b/autogpt_platform/backend/backend/copilot/prompting.py
index 032982814c..abf24b9626 100644
--- a/autogpt_platform/backend/backend/copilot/prompting.py
+++ b/autogpt_platform/backend/backend/copilot/prompting.py
@@ -385,6 +385,18 @@ not promise a card — call the tool first, then describe it.
`connect_integration(provider="github")`. The card the tool surfaces
does the job better than the sentence.
+**4. Connecting is not running.** When the user only asks to connect or
+sign in to a service, call `connect_integration(provider=...)` — never
+`run_block` or `run_agent`, which commit to an action the user has not
+asked for. Call those only when the user asks for the action itself.
+
+**5. The card asks for credentials, not inputs.** A setup card never
+renders a form for a block's or agent's inputs (the one exception is a
+picker-backed field, see above). Collect every other input in the chat:
+if you do not have a value, ask the user for it via `ask_question`, then
+call the tool with it once they connect. Do not tell the user to fill
+anything in on the card.
+
### Grounded claims — CRITICAL
Every factual claim in your reply must be backed by a tool result from this
diff --git a/autogpt_platform/backend/backend/copilot/tools/helpers.py b/autogpt_platform/backend/backend/copilot/tools/helpers.py
index e7c5e40215..ec714bfc5a 100644
--- a/autogpt_platform/backend/backend/copilot/tools/helpers.py
+++ b/autogpt_platform/backend/backend/copilot/tools/helpers.py
@@ -105,6 +105,36 @@ def get_inputs_from_schema(
return results
+def is_picker_field(schema: Any) -> bool:
+ """A field only a platform-rendered picker can fill (e.g. Google Drive).
+
+ The picker attaches hidden credentials to the chosen resource, so a bare
+ ID or URL typed into the chat can never stand in for it.
+ """
+ return isinstance(schema, dict) and (
+ schema.get("format") == "google-drive-picker" or "auto_credentials" in schema
+ )
+
+
+def get_picker_inputs_from_schema(
+ input_schema: dict[str, Any],
+ exclude_fields: set[str] | None = None,
+ input_data: dict[str, Any] | None = None,
+) -> list[dict[str, Any]]:
+ """Inputs a setup card should render: picker-backed fields only.
+
+ Every other input is collected in the chat by the CoPilot asking the
+ user, so the card carries no form for them.
+ """
+ return [
+ entry
+ for entry in get_inputs_from_schema(
+ input_schema, exclude_fields=exclude_fields, input_data=input_data
+ )
+ if is_picker_field(entry)
+ ]
+
+
async def _charge_block_credits(
_credit_db: Any,
*,
@@ -388,7 +418,7 @@ async def execute_block(
),
requirements={
"credentials": [],
- "inputs": get_inputs_from_schema(
+ "inputs": get_picker_inputs_from_schema(
input_schema,
exclude_fields=credentials_fields,
input_data=input_data,
@@ -761,11 +791,7 @@ async def prepare_block_for_execution(
picker_fields_missing = [
f
for f in required_non_credential_keys - provided_input_keys
- if isinstance(input_schema.get("properties", {}).get(f), dict)
- and (
- input_schema["properties"][f].get("format") == "google-drive-picker"
- or "auto_credentials" in input_schema["properties"][f]
- )
+ if is_picker_field(input_schema.get("properties", {}).get(f))
]
# validate_only suppresses the setup-card early-return — the caller is
@@ -805,7 +831,7 @@ async def prepare_block_for_execution(
),
requirements={
"credentials": missing_creds_list,
- "inputs": get_inputs_from_schema(
+ "inputs": get_picker_inputs_from_schema(
input_schema,
exclude_fields=credentials_fields,
input_data=input_data,
diff --git a/autogpt_platform/backend/backend/copilot/tools/helpers_test.py b/autogpt_platform/backend/backend/copilot/tools/helpers_test.py
index 5f232d700b..7f3c264809 100644
--- a/autogpt_platform/backend/backend/copilot/tools/helpers_test.py
+++ b/autogpt_platform/backend/backend/copilot/tools/helpers_test.py
@@ -1,7 +1,7 @@
"""Tests for execute_block, prepare_block_for_execution, and check_hitl_review."""
from collections.abc import AsyncIterator
-from typing import Any, Literal
+from typing import Any, ClassVar, Literal
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
@@ -14,6 +14,9 @@ from backend.copilot.tools.helpers import (
check_hitl_review,
execute_block,
get_block_provider,
+ get_inputs_from_schema,
+ get_picker_inputs_from_schema,
+ is_picker_field,
prepare_block_for_execution,
require_library_check,
)
@@ -1842,6 +1845,58 @@ class TestRequireLibraryCheck:
assert require_library_check(session, "create_agent") is None
+class TestPickerInputs:
+ """Setup cards carry only picker-backed inputs; the rest is asked in chat."""
+
+ _schema: ClassVar[dict[str, Any]] = {
+ "properties": {
+ "term": {"type": "string"},
+ "limit": {"type": "integer", "default": 10, "advanced": True},
+ "spreadsheet": {
+ "type": "object",
+ "format": "google-drive-picker",
+ },
+ "doc": {
+ "type": "object",
+ "auto_credentials": {"provider": "google", "kwarg_name": "creds"},
+ },
+ "credentials": {"type": "object"},
+ },
+ "required": ["term", "spreadsheet", "credentials"],
+ }
+
+ def test_is_picker_field(self):
+ assert is_picker_field({"format": "google-drive-picker"})
+ assert is_picker_field({"auto_credentials": {"provider": "google"}})
+ assert not is_picker_field({"type": "string"})
+ assert not is_picker_field(None)
+
+ def test_only_picker_fields_survive(self):
+ inputs = get_picker_inputs_from_schema(
+ self._schema, exclude_fields={"credentials"}
+ )
+ assert [i["name"] for i in inputs] == ["spreadsheet", "doc"]
+
+ def test_plain_inputs_yield_empty_list(self):
+ schema = {
+ "properties": {"term": {"type": "string"}},
+ "required": ["term"],
+ }
+ assert get_picker_inputs_from_schema(schema) == []
+ assert len(get_inputs_from_schema(schema)) == 1
+
+ def test_provided_values_are_kept_on_picker_fields(self):
+ picked = {"id": "file-1", "name": "Sheet"}
+ inputs = get_picker_inputs_from_schema(
+ self._schema,
+ exclude_fields={"credentials"},
+ input_data={"term": "bug", "spreadsheet": picked},
+ )
+ by_name = {i["name"]: i for i in inputs}
+ assert by_name["spreadsheet"]["value"] == picked
+ assert "term" not in by_name
+
+
class TestExecuteBlockExpertFileScope:
"""A ``workspace://`` block input is a second door into the workspace, so
the run it belongs to must carry the session's expert."""
diff --git a/autogpt_platform/backend/backend/copilot/tools/run_agent.py b/autogpt_platform/backend/backend/copilot/tools/run_agent.py
index d33b869a9c..bf8127aa5f 100644
--- a/autogpt_platform/backend/backend/copilot/tools/run_agent.py
+++ b/autogpt_platform/backend/backend/copilot/tools/run_agent.py
@@ -38,7 +38,7 @@ from .execution_utils import (
summarize_node_failures,
wait_for_execution,
)
-from .helpers import get_inputs_from_schema
+from .helpers import get_inputs_from_schema, get_picker_inputs_from_schema
from .models import (
AgentDetails,
AgentDetailsResponse,
@@ -528,6 +528,7 @@ class RunAgentTool(BaseTool):
graph: GraphModel,
error: GraphValidationError,
session_id: str,
+ inputs: dict[str, Any] | None = None,
) -> SetupRequirementsResponse | None:
"""Turn a credential-only ``GraphValidationError`` into the inline
setup-requirements card; return ``None`` if *any* non-credential
@@ -565,7 +566,9 @@ class RunAgentTool(BaseTool):
),
requirements={
"credentials": list(credentials_dict.values()),
- "inputs": get_inputs_from_schema(graph.input_schema),
+ "inputs": get_picker_inputs_from_schema(
+ graph.input_schema, input_data=inputs
+ ),
"execution_modes": self._get_execution_modes(graph),
},
),
@@ -580,6 +583,7 @@ class RunAgentTool(BaseTool):
user_id: str,
session_id: str,
action_verb: str,
+ inputs: dict[str, Any] | None = None,
) -> ToolResponseBase:
"""Handle a ``GraphValidationError`` that slipped past the prereq check.
@@ -598,6 +602,7 @@ class RunAgentTool(BaseTool):
graph=graph,
error=error,
session_id=session_id,
+ inputs=inputs,
)
if creds_setup is not None:
return creds_setup
@@ -672,7 +677,9 @@ class RunAgentTool(BaseTool):
),
requirements={
"credentials": list(requirements_creds_dict.values()),
- "inputs": get_inputs_from_schema(graph.input_schema),
+ "inputs": get_picker_inputs_from_schema(
+ graph.input_schema, input_data=params.inputs
+ ),
"execution_modes": self._get_execution_modes(graph),
},
),
@@ -920,6 +927,7 @@ class RunAgentTool(BaseTool):
user_id=user_id,
session_id=session_id,
action_verb="running",
+ inputs=inputs,
)
# Track successful run (dry runs don't count against the session limit)
@@ -1208,6 +1216,7 @@ class RunAgentTool(BaseTool):
user_id=user_id,
session_id=session_id,
action_verb="scheduling",
+ inputs=inputs,
)
# Convert next_run_time to user timezone for display
diff --git a/autogpt_platform/backend/backend/copilot/tools/run_block_test.py b/autogpt_platform/backend/backend/copilot/tools/run_block_test.py
index 2c66ca4f9a..837e272766 100644
--- a/autogpt_platform/backend/backend/copilot/tools/run_block_test.py
+++ b/autogpt_platform/backend/backend/copilot/tools/run_block_test.py
@@ -663,6 +663,123 @@ class TestRunBlockInputValidation:
assert picker_field is not None
assert picker_field["format"] == "google-drive-picker"
+ @pytest.mark.asyncio(loop_scope="session")
+ async def test_missing_credentials_card_carries_no_plain_inputs(self):
+ """A connect card is only a connect card: the block's ordinary inputs
+ are collected in chat, so the setup card must not ship a form for
+ them alongside the credentials."""
+ from backend.data.model import CredentialsFieldInfo
+
+ from .models import SetupRequirementsResponse
+
+ session = make_session(user_id=_TEST_USER_ID)
+
+ mock_block = make_mock_block_with_schema(
+ block_id="github-search-id",
+ name="GitHub Search Issues",
+ input_properties={
+ "term": {"type": "string"},
+ "limit": {"type": "integer", "default": 10, "advanced": True},
+ },
+ required_fields=["term"],
+ )
+ info = CredentialsFieldInfo(
+ credentials_provider=frozenset({"github"}),
+ credentials_types=frozenset({"api_key"}),
+ )
+ mock_block.input_schema.get_credentials_fields_info.return_value = {
+ "credentials": info
+ }
+ mock_block.input_schema.get_credentials_fields.return_value = {
+ "credentials": MagicMock()
+ }
+ mock_block.input_schema.get_required_fields.return_value = {
+ "credentials",
+ "term",
+ }
+
+ with (
+ patch(
+ "backend.copilot.tools.helpers.get_block",
+ return_value=mock_block,
+ ),
+ patch(
+ "backend.copilot.tools.helpers.match_credentials_to_requirements",
+ return_value=({}, [MagicMock()]),
+ ),
+ ):
+ tool = RunBlockTool()
+ response = await tool._execute(
+ user_id=_TEST_USER_ID,
+ session=session,
+ block_id="github-search-id",
+ input_data={"term": "login bug"},
+ )
+
+ assert isinstance(response, SetupRequirementsResponse)
+ assert "credentials" in response.setup_info.user_readiness.missing_credentials
+ assert response.setup_info.requirements["inputs"] == []
+
+ @pytest.mark.asyncio(loop_scope="session")
+ async def test_missing_credentials_card_keeps_picker_inputs(self):
+ """Picker-backed fields are the one input the chat cannot supply, so
+ they stay on the card next to the credentials."""
+ from backend.data.model import CredentialsFieldInfo
+
+ from .models import SetupRequirementsResponse
+
+ session = make_session(user_id=_TEST_USER_ID)
+
+ mock_block = make_mock_block_with_schema(
+ block_id="sheets-read-id",
+ name="Google Sheets Read",
+ input_properties={
+ "spreadsheet": {
+ "type": "object",
+ "format": "google-drive-picker",
+ },
+ "range": {"type": "string"},
+ },
+ required_fields=["spreadsheet", "range"],
+ )
+ info = CredentialsFieldInfo(
+ credentials_provider=frozenset({"google"}),
+ credentials_types=frozenset({"oauth2"}),
+ )
+ mock_block.input_schema.get_credentials_fields_info.return_value = {
+ "credentials": info
+ }
+ mock_block.input_schema.get_credentials_fields.return_value = {
+ "credentials": MagicMock()
+ }
+ mock_block.input_schema.get_required_fields.return_value = {
+ "credentials",
+ "spreadsheet",
+ "range",
+ }
+
+ with (
+ patch(
+ "backend.copilot.tools.helpers.get_block",
+ return_value=mock_block,
+ ),
+ patch(
+ "backend.copilot.tools.helpers.match_credentials_to_requirements",
+ return_value=({}, [MagicMock()]),
+ ),
+ ):
+ tool = RunBlockTool()
+ response = await tool._execute(
+ user_id=_TEST_USER_ID,
+ session=session,
+ block_id="sheets-read-id",
+ input_data={"range": "Sheet1!A1:Z100"},
+ )
+
+ assert isinstance(response, SetupRequirementsResponse)
+ names = [i["name"] for i in response.setup_info.requirements["inputs"]]
+ assert names == ["spreadsheet"]
+
class TestRunBlockSensitiveAction:
"""Tests for sensitive action HITL review in RunBlockTool.