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.

feat(backend/copilot): experts do the public-data part of the job when a connection is skipped (#14411)

Reinier van der Leerf86956636f4e
diff --git a/autogpt_platform/backend/backend/api/features/experts/experts_db_test.py b/autogpt_platform/backend/backend/api/features/experts/experts_db_test.py
index 9d49678451..02630dd033 100644
--- a/autogpt_platform/backend/backend/api/features/experts/experts_db_test.py
+++ b/autogpt_platform/backend/backend/api/features/experts/experts_db_test.py
@@ -3503,6 +3503,24 @@ def test_to_expert_run_reports_how_the_run_started():
assert triggered.source == "trigger"
+ "execution_status",
+ [
+ prisma.enums.AgentExecutionStatus.FAILED,
+ prisma.enums.AgentExecutionStatus.TERMINATED,
+ ],
+)
+def test_to_expert_run_never_reports_a_failed_run_as_completed(execution_status):
+ run = experts_db._to_expert_run(
+ _run_execution(executionStatus=execution_status),
+ _run_workflow(),
+ "unknown",
+ None,
+ needs_review=False,
+ )
+ assert run.status == execution_status.value.lower()
+
+
def test_to_expert_run_names_a_library_only_workflow():
run = experts_db._to_expert_run(
_run_execution(),
diff --git a/autogpt_platform/backend/backend/copilot/expert_context.py b/autogpt_platform/backend/backend/copilot/expert_context.py
index 470b13338a..19016b5f66 100644
--- a/autogpt_platform/backend/backend/copilot/expert_context.py
+++ b/autogpt_platform/backend/backend/copilot/expert_context.py
@@ -227,6 +227,14 @@ async def _expert_session_context(
f"workflow's purpose, prefer running it with `run_agent` using the "
f"IDs below over building something new:\n"
f"{workflow_lines}\n"
+ # The skip comes after the kickoff message's ask, so the rule lives in
+ # session context, which every later turn sees, not in that message.
+ f"If the user skips or declines a connection a workflow needs, do the "
+ f"part of the job public data allows (research, drafts) and save it as "
+ f"a workspace file with its sources; say what stays blocked and which "
+ f"one connection would unlock it. If public data does not support "
+ f"useful work, say so. Never report a workflow as run, or a step as "
+ f"completed, when it was blocked or failed.\n"
f"</expert_workflows>\n\n"
)
return workflows_block + teammates
diff --git a/autogpt_platform/backend/backend/copilot/expert_context_test.py b/autogpt_platform/backend/backend/copilot/expert_context_test.py
index a068abedb5..9dd0912431 100644
--- a/autogpt_platform/backend/backend/copilot/expert_context_test.py
+++ b/autogpt_platform/backend/backend/copilot/expert_context_test.py
@@ -389,6 +389,25 @@ class TestBuildExpertContextExpertSession:
assert "graph-1" in result
assert "run_agent" in result
+ @pytest.mark.asyncio
+ @pytest.mark.parametrize("workflows", [[_workflow()], []])
+ async def test_workflows_block_covers_a_skipped_connection(self, workflows):
+ from backend.copilot.expert_context import build_expert_context
+
+ mock_db = MagicMock()
+ mock_db.get_expert = AsyncMock(return_value=_expert(workflows=workflows))
+ mock_db.list_experts = AsyncMock(return_value=[])
+ with patch(f"{_EC}.experts_db", MagicMock(return_value=mock_db)):
+ result = await build_expert_context("user-1", "exp-1")
+
+ block = result.split("</expert_workflows>")[0]
+ assert "skips or declines a connection" in block
+ assert "public data allows (research, drafts)" in block
+ assert "workspace file with its sources" in block
+ assert "which one connection would unlock it" in block
+ assert "If public data does not support useful work, say so" in block
+ assert "Never report a workflow as run, or a step as completed" in block
+
@pytest.mark.asyncio
async def test_lists_teammates_excluding_self_with_delegation_rule(self):
from backend.copilot.expert_context import build_expert_context