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.
refactor(backend/copilot): run dream tests without the test server and drop unreachable dream paths (#14953)
Nicholas Tindle316977d32d6e
diff --git a/autogpt_platform/backend/backend/copilot/dream/batch_submit.py b/autogpt_platform/backend/backend/copilot/dream/batch_submit.pyindex e891534c24..6596b7e834 100644--- a/autogpt_platform/backend/backend/copilot/dream/batch_submit.py+++ b/autogpt_platform/backend/backend/copilot/dream/batch_submit.py@@ -19,7 +19,7 @@ from __future__ import annotationsimport jsonimport logging-from datetime import datetime, timezone+from datetime import datetimefrom typing import TYPE_CHECKING, Literalfrom pydantic import BaseModel@@ -491,8 +491,3 @@ def _dict_to_input_bundle(data: dict) -> DreamInput:known_fact_uuids=set(data.get("known_fact_uuids") or []),known_episode_uuids=set(data.get("known_episode_uuids") or []),)---def _dummy_now() -> datetime:- """Stub kept for symmetry with Step 4b; never called."""- return datetime.now(timezone.utc)diff --git a/autogpt_platform/backend/backend/copilot/dream/billing.py b/autogpt_platform/backend/backend/copilot/dream/billing.pyindex 1a3a4a687f..6dcd241426 100644--- a/autogpt_platform/backend/backend/copilot/dream/billing.py+++ b/autogpt_platform/backend/backend/copilot/dream/billing.py@@ -55,14 +55,13 @@ logger = logging.getLogger(__name__)# :func:`_provider_for_execution_path` below)._PROVIDER_BY_BATCH_PATH: dict[ExecutionPath, str] = {"anthropic_batch": "anthropic",- "openai_batch": "openai",}def _provider_for_execution_path(execution_path: ExecutionPath) -> str:"""Resolve the ``PlatformCostLog.provider`` label for a phase row.- Batch paths are pinned to their provider (Anthropic / OpenAI). The+ The batch path is pinned to Anthropic. Thesync_baseline path follows the active chat transport — so alocal-Ollama install logs ``provider="ollama"``, a subscriptionor direct-Anthropic install logs ``"anthropic"``, and the clouddiff --git a/autogpt_platform/backend/backend/copilot/dream/billing_test.py b/autogpt_platform/backend/backend/copilot/dream/billing_test.pyindex fc24d5531b..23b3e11350 100644--- a/autogpt_platform/backend/backend/copilot/dream/billing_test.py+++ b/autogpt_platform/backend/backend/copilot/dream/billing_test.py@@ -202,19 +202,6 @@ async def test_record_phase_cost_tags_provider_anthropic_for_batch_path():assert spy.await_args.kwargs["provider"] == "anthropic"-async def test_record_phase_cost_tags_provider_openai_for_openai_batch_path():- spy = AsyncMock()- with patch.object(billing_mod, "persist_and_record_usage", new=spy):- await billing_mod.record_phase_cost(- user_id="u1",- pass_id="p",- phase_usage=PhaseUsage(phase="sanitize", model="gpt-5", cost_usd=0.005),- execution_path="openai_batch",- )- assert spy.await_args.kwargs["provider"] == "openai"--@pytest.mark.asyncioasync def test_record_phase_cost_uses_dream_block_name_and_passes_pass_id_as_graph_exec_id():"""Block name must distinguish dream from chat, and pass_id is thediff --git a/autogpt_platform/backend/backend/copilot/dream/conftest.py b/autogpt_platform/backend/backend/copilot/dream/conftest.pynew file mode 100644index 0000000000..4bfb5f3243--- /dev/null+++ b/autogpt_platform/backend/backend/copilot/dream/conftest.py@@ -0,0 +1,197 @@+"""Local conftest for copilot/dream tests.++Overrides the session-scoped ``server`` and ``graph_cleanup`` autouse fixtures+from backend/conftest.py so the dream unit tests do not boot the full+SpinTestServer (Postgres, RabbitMQ and every service). Mirrors+copilot/tools/conftest.py, and applies to the ``webcheck/`` tests too, since+pytest inherits conftests by directory.++Without the server there is no Redis either, and ``get_redis_async`` retries+for close to an hour before giving up, so every test in this directory gets an+in-memory stand-in by default. Tests that need their own fake keep patching+``backend.data.redis_client.get_redis_async`` as before; a later patch wins.+"""++from __future__ import annotations++from typing import Any++import pytest+import pytest_asyncio+++@pytest_asyncio.fixture(scope="session", loop_scope="session")+async def server():+ """No-op server stub — dream tests don't need the full backend."""+ return None+++@pytest_asyncio.fixture(scope="session", loop_scope="session", autouse=True)+async def graph_cleanup():+ """No-op graph cleanup stub."""+ yield+++class FakeAsyncRedis:+ """In-memory stand-in for the ``decode_responses=True`` async client.++ Covers the surface the dream code uses: ``get``/``set`` (with ``nx``,+ ``xx`` and ``ex``), ``delete``, ``expire``, ``ttl``, ``exists``, ``incr``,+ the hash commands, and ``eval`` for the two single-key lock scripts in+ ``locks.py`` (compare-and-delete, compare-and-extend). TTLs are recorded,+ not enforced.+ """++ def __init__(self) -> None:+ self.store: dict[str, str] = {}+ self.hashes: dict[str, dict[str, str]] = {}+ self.ttls: dict[str, int] = {}++ @staticmethod+ def _s(value: Any) -> str:+ return value.decode() if isinstance(value, bytes) else str(value)++ async def get(self, key: str) -> str | None:+ return self.store.get(key)++ async def set(+ self,+ key: str,+ value: Any,+ *,+ nx: bool = False,+ xx: bool = False,+ ex: int | None = None,+ px: int | None = None,+ **_: Any,+ ) -> bool | None:+ if nx and key in self.store:+ return None+ if xx and key not in self.store:+ return None+ self.store[key] = self._s(value)+ if ex is not None:+ self.ttls[key] = int(ex)+ elif px is not None:+ self.ttls[key] = int(px) // 1000+ else:+ # A plain SET drops any expiry the key had, as Redis does.+ self.ttls.pop(key, None)+ return True++ async def delete(self, *keys: str) -> int:+ removed = 0+ for key in keys:+ if self.store.pop(key, None) is not None:+ removed += 1+ if self.hashes.pop(key, None) is not None:+ removed += 1+ self.ttls.pop(key, None)+ return removed++ async def expire(self, key: str, ttl_seconds: int) -> bool:+ if key not in self.store and key not in self.hashes:+ return False+ self.ttls[key] = int(ttl_seconds)+ return True++ async def ttl(self, key: str) -> int:+ if key not in self.store and key not in self.hashes:+ return -2+ return self.ttls.get(key, -1)++ async def exists(self, *keys: str) -> int:+ return sum(1 for key in keys if key in self.store or key in self.hashes)++ async def incr(self, key: str) -> int:+ value = int(self.store.get(key, "0")) + 1+ self.store[key] = str(value)+ return value++ async def hset(+ self,+ name: str,+ key: str | None = None,+ value: Any = None,+ mapping: dict[str, Any] | None = None,+ ) -> int:+ bucket = self.hashes.setdefault(name, {})+ added = 0+ items = dict(mapping or {})+ if key is not None:+ items[key] = value+ for field, item in items.items():+ if field not in bucket:+ added += 1+ bucket[field] = self._s(item)+ return added++ async def hget(self, name: str, key: str) -> str | None:+ return self.hashes.get(name, {}).get(key)++ async def hgetall(self, name: str) -> dict[str, str]:+ return dict(self.hashes.get(name, {}))++ async def hdel(self, name: str, *keys: str) -> int:+ bucket = self.hashes.get(name, {})+ removed = sum(1 for key in keys if bucket.pop(key, None) is not None)+ if not bucket:+ # Redis removes a hash once its last field is gone.+ self.hashes.pop(name, None)+ self.ttls.pop(name, None)+ return removed++ async def eval(self, script: str, numkeys: int, *args: Any) -> int:+ keys = [self._s(a) for a in args[:numkeys]]+ argv = [self._s(a) for a in args[numkeys:]]+ if numkeys != 1 or not argv:+ raise NotImplementedError(+ "FakeAsyncRedis.eval only models the lock scripts"+ )+ key, token = keys[0], argv[0]+ if self.store.get(key) != token:+ return 0+ if '"del"' in script:+ del self.store[key]+ self.ttls.pop(key, None)+ return 1+ if '"expire"' in script:+ self.ttls[key] = int(argv[1])+ return 1+ raise NotImplementedError(f"FakeAsyncRedis.eval: unknown script {script!r}")++ async def aclose(self) -> None:+ return None++[email protected](autouse=True)+def fake_dream_redis(monkeypatch: pytest.MonkeyPatch) -> FakeAsyncRedis:+ """Give every dream test an in-memory Redis unless it patches its own."""+ fake = FakeAsyncRedis()++ async def _get_redis_async() -> FakeAsyncRedis:+ return fake++ monkeypatch.setattr(+ "backend.data.redis_client.get_redis_async", _get_redis_async, raising=True+ )+ return fake++[email protected](autouse=True)+def stub_dream_session_route(monkeypatch: pytest.MonkeyPatch) -> None:+ """Pin the dream summary session to the platform route.++ ``apply._create_dream_session`` resolves the owner's default chat route,+ which reads the user row through the database accessors. Without the+ test server those fall back to the DatabaseManager RPC client, whose+ connection retry runs for close to an hour. No dream test asserts on the+ route, so answer "platform, no credential" up front.+ """++ async def _platform_route(user_id: str) -> tuple[str, None]:+ return ("platform", None)++ monkeypatch.setattr(+ "backend.copilot.dream.apply.resolve_default_chat_route", _platform_route+ )diff --git a/autogpt_platform/backend/backend/copilot/dream/fake_redis_test.py b/autogpt_platform/backend/backend/copilot/dream/fake_redis_test.pynew file mode 100644index 0000000000..3fe9656b64--- /dev/null+++ b/autogpt_platform/backend/backend/copilot/dream/fake_redis_test.py@@ -0,0 +1,76 @@+"""Pin the semantics of the conftest's in-memory Redis stand-in.++The dream tests lean on ``FakeAsyncRedis`` for locks, markers, hit counters+and batch bookkeeping, so its behaviour on the calls the dream code makes+(NX/XX sets, TTLs, hashes and the two single-key lock scripts) is worth+asserting directly rather than only through the tests that happen to use+each call.+"""++import pytest++from .conftest import FakeAsyncRedis+from .locks import _EXTEND_SCRIPT, _UNLOCK_SCRIPT+++async def test_set_honours_nx_xx_and_ttl_arguments():+ redis = FakeAsyncRedis()+ assert await redis.set("k", "v1", nx=True, ex=30) is True+ assert await redis.set("k", "v2", nx=True) is None+ assert await redis.get("k") == "v1"+ assert await redis.ttl("k") == 30+ assert await redis.set("missing", "v", xx=True) is None+ assert await redis.set("k", "v3", xx=True, px=5000) is True+ assert await redis.get("k") == "v3"+ assert await redis.ttl("k") == 5+ assert await redis.set("k", "v4") is True+ assert await redis.ttl("k") == -1+ assert await redis.set("b", b"bytes") is True+ assert await redis.get("b") == "bytes"+++async def test_delete_expire_exists_and_incr():+ redis = FakeAsyncRedis()+ assert await redis.expire("nope", 10) is False+ assert await redis.ttl("nope") == -2+ assert await redis.incr("counter") == 1+ assert await redis.incr("counter") == 2+ assert await redis.ttl("counter") == -1+ assert await redis.expire("counter", 60) is True+ assert await redis.exists("counter", "nope") == 1+ assert await redis.delete("counter", "nope") == 1+ assert await redis.exists("counter") == 0+++async def test_hash_commands():+ redis = FakeAsyncRedis()+ assert await redis.hset("h", "a", 1) == 1+ assert await redis.hset("h", mapping={"a": "x", "b": b"y"}) == 1+ assert await redis.hget("h", "a") == "x"+ assert await redis.hgetall("h") == {"a": "x", "b": "y"}+ assert await redis.hdel("h", "a", "zzz") == 1+ assert await redis.exists("h") == 1+ assert await redis.hdel("h", "b") == 1+ assert await redis.exists("h") == 0+ assert await redis.hgetall("h") == {}+++async def test_eval_models_the_lock_scripts():+ redis = FakeAsyncRedis()+ await redis.set("dream:inflight:u1", "token-a", nx=True, ex=1800)+ assert await redis.eval(_EXTEND_SCRIPT, 1, "dream:inflight:u1", "token-b", 60) == 0+ assert await redis.eval(_EXTEND_SCRIPT, 1, "dream:inflight:u1", "token-a", 60) == 1+ assert await redis.ttl("dream:inflight:u1") == 60+ assert await redis.eval(_UNLOCK_SCRIPT, 1, "dream:inflight:u1", "token-b") == 0+ assert await redis.eval(_UNLOCK_SCRIPT, 1, "dream:inflight:u1", "token-a") == 1+ assert await redis.get("dream:inflight:u1") is None+ with pytest.raises(NotImplementedError):+ await redis.eval("return 1", 2, "a", "b", "c")+ await redis.set("k", "t")+ with pytest.raises(NotImplementedError):+ await redis.eval('redis.call("incr", KEYS[1])', 1, "k", "t")+ await redis.aclose()diff --git a/autogpt_platform/backend/backend/copilot/dream/locks.py b/autogpt_platform/backend/backend/copilot/dream/locks.pyindex a7f9db1cde..4f37c492d4 100644--- a/autogpt_platform/backend/backend/copilot/dream/locks.py+++ b/autogpt_platform/backend/backend/copilot/dream/locks.py@@ -17,11 +17,8 @@ in cluster mode, so everything here stays single-key: SET NX plussingle-key Lua scripts, no multi-key scripts and no cross-keytransactions.-TTL is transport-aware per ``dream/p0-spec.md`` §13:- * Cloud (OpenRouter / Anthropic direct): 1800 s (30 min)- * Local (Ollama / vLLM / LM Studio): 7200 s (2 hr)-The longer local TTL accommodates CPU-only inference timelines for-the three-phase pipeline.+The sync-path TTL is 1800 s (30 min), sized to the scheduler's job+timeout; the batch path extends it (see ``BATCH_LOCK_TTL_SECONDS``)."""from __future__ import annotations@@ -37,9 +34,8 @@ logger = logging.getLogger(__name__)DREAM_LOCK_KEY_PREFIX = "dream:inflight:"-# Default TTLs. Callers can override per-transport when local.+# Sync-path lock TTL (30 min).DEFAULT_LOCK_TTL_SECONDS = 1800-LOCAL_LOCK_TTL_SECONDS = 7200# Batch path: the dream pass is async and stays in flight up to the# BatchExecutor's MAX_BATCH_LIFETIME_SECONDS (24h). The lock must outlive thediff --git a/autogpt_platform/backend/backend/copilot/dream/model_pricing.py b/autogpt_platform/backend/backend/copilot/dream/model_pricing.pyindex b48283109d..4ee0fc3021 100644--- a/autogpt_platform/backend/backend/copilot/dream/model_pricing.py+++ b/autogpt_platform/backend/backend/copilot/dream/model_pricing.py@@ -10,19 +10,19 @@ file; we'd rather fail loud on an unknown model than silently bill atzero. The OpenRouter path bypasses this entirely because OpenRouteralready returns the real spot price as ``usage.cost``.-When the Anthropic + OpenAI direct batch paths land (P0.1), the-``batch_discount`` factor in ``ExecutionPathDiscount`` is multiplied-into the computed cost so the savings flow through to the user via the-shared cost ledger.+On the Anthropic batch path the 50% discount from+``execution_path_discount`` is multiplied into the computed cost so the+savings flow through to the user via the shared cost ledger."""from __future__ import annotationsimport logging-from typing import Literalfrom pydantic.dataclasses import dataclass+from .routing import ExecutionPath+logger = logging.getLogger(__name__)@@ -104,17 +104,12 @@ _RATES: dict[str, ModelRate] = {}-ExecutionPath = Literal["sync_baseline", "anthropic_batch", "openai_batch"]---# Both Anthropic and OpenAI batch APIs offer a 50% discount on the-# normal rate for asynchronous batch processing. We pass that savings-# through to the user — recorded in the cost ledger so the discount is-# auditable.+# Anthropic's Message Batches API offers a 50% discount on the normal+# rate for asynchronous batch processing. We pass that savings through+# to the user — recorded in the cost ledger so the discount is auditable._BATCH_DISCOUNTS: dict[ExecutionPath, float] = {"sync_baseline": 0.0,"anthropic_batch": 0.5,- "openai_batch": 0.5,}diff --git a/autogpt_platform/backend/backend/copilot/dream/model_pricing_test.py b/autogpt_platform/backend/backend/copilot/dream/model_pricing_test.pyindex 9fce66cad8..631f2fc7bc 100644--- a/autogpt_platform/backend/backend/copilot/dream/model_pricing_test.py+++ b/autogpt_platform/backend/backend/copilot/dream/model_pricing_test.py@@ -42,7 +42,6 @@ def test_cache_tokens_priced_separately():[("sync_baseline", 0.0),("anthropic_batch", 0.5),- ("openai_batch", 0.5),],)def test_execution_path_discount(path, expected_discount):diff --git a/autogpt_platform/backend/backend/copilot/dream/nightly_batch.py b/autogpt_platform/backend/backend/copilot/dream/nightly_batch.pyindex 520469398c..4878b4bfce 100644--- a/autogpt_platform/backend/backend/copilot/dream/nightly_batch.py+++ b/autogpt_platform/backend/backend/copilot/dream/nightly_batch.py@@ -12,8 +12,7 @@ submitter:P11 threat rehearsal land as additional submitters hereEach submitter is fast to ENQUEUE (seconds) but may take up to ~1h to-COMPLETE when running against a real batch provider (Anthropic /-OpenAI batch API). The submitters fire in sequence at cron time; their+COMPLETE when running against the Anthropic batch API. The submitters fire in sequence at cron time; theirbatch results land asynchronously via the separate``copilot_batch_executor`` poller service that dispatches by``custom_id`` to per-stage apply handlers.diff --git a/autogpt_platform/backend/backend/copilot/dream/nightly_batch_test.py b/autogpt_platform/backend/backend/copilot/dream/nightly_batch_test.pyindex 68a485d3f4..624f2052ef 100644--- a/autogpt_platform/backend/backend/copilot/dream/nightly_batch_test.py+++ b/autogpt_platform/backend/backend/copilot/dream/nightly_batch_test.py@@ -35,9 +35,7 @@ def _dream_result(*,error: str | None = None,skipped: bool = False,- execution_path: Literal[- "sync_baseline", "anthropic_batch", "openai_batch"- ] = "sync_baseline",+ execution_path: Literal["sync_baseline", "anthropic_batch"] = "sync_baseline",) -> DreamPassResult:return DreamPassResult(user_id="u",diff --git a/autogpt_platform/backend/backend/copilot/dream/orchestrator.py b/autogpt_platform/backend/backend/copilot/dream/orchestrator.pyindex b74d3eae1c..e99e6bef0b 100644--- a/autogpt_platform/backend/backend/copilot/dream/orchestrator.py+++ b/autogpt_platform/backend/backend/copilot/dream/orchestrator.py@@ -46,7 +46,6 @@ from .llm import (from .locks import (BATCH_LOCK_TTL_SECONDS,DEFAULT_LOCK_TTL_SECONDS,- LOCAL_LOCK_TTL_SECONDS,DreamLockHandle,DreamLockHeld,dream_lock,@@ -157,10 +156,6 @@ LAST_COMPLETED_KEY_PREFIX = "dream:last_completed:"LAST_COMPLETED_TTL_SECONDS = 35 * 24 * 60 * 60-def _resolve_lock_ttl(transport_is_local: bool) -> int:- return LOCAL_LOCK_TTL_SECONDS if transport_is_local else DEFAULT_LOCK_TTL_SECONDS--# High-precision filter for "transient intent" facts — content that# records what the user is ASKING/wants to KNOW rather than a durable# fact about them. The sanitize prompt is told to drop these, but@@ -741,7 +736,6 @@ async def _execute_dream_pass_async(user_id: str,*,expert_id: str | None = None,- transport_is_local: bool = False,config: ChatConfig | None = None,status_id: str | None = None,) -> DreamPassResult:@@ -772,7 +766,7 @@ async def _execute_dream_pass_async(transport_name=config.transport.name,)- ttl = _resolve_lock_ttl(transport_is_local)+ ttl = DEFAULT_LOCK_TTL_SECONDStry:lock_context = dream_lock(user_id, ttl_seconds=ttl, expert_id=expert_id)async with lock_context as dream_lock_handle:diff --git a/autogpt_platform/backend/backend/copilot/dream/routing.py b/autogpt_platform/backend/backend/copilot/dream/routing.pyindex e751e4dcb2..5adce76e4e 100644--- a/autogpt_platform/backend/backend/copilot/dream/routing.py+++ b/autogpt_platform/backend/backend/copilot/dream/routing.py@@ -1,15 +1,11 @@"""Decide which execution path a dream pass runs through.Per ``dream/p0-spec.md`` §13, the dream pass must work on every-transport (openrouter / subscription / openai_compat / local). Two-batch APIs are supported (both Anthropic and OpenAI offer a 50%-discount); we route to whichever has a direct API key present + the-batch flag on. Anything else falls back to the synchronous baseline-path through the existing ``copilot_executor``.--Slice 1 of P-0 ships sync-baseline only. Both batch paths land in-task #33 (P0.1). This resolver is wired from day one so adding the-batch executors is just flipping the conditional below.+transport (openrouter / subscription / openai_compat / local). The one+batch path is Anthropic's Message Batches API (50% discount); it is+chosen when a direct Anthropic key is present and the batch flag is on.+Anything else falls back to the synchronous baseline path through the+existing ``copilot_executor``."""from __future__ import annotations@@ -18,14 +14,13 @@ from typing import Literalfrom backend.copilot.config import TransportName-# Kept in sync with ``model_pricing.ExecutionPath`` so the discount-# table in model_pricing.py reads our chosen path directly. If you add-# a new path here, mirror it there.-ExecutionPath = Literal["sync_baseline", "anthropic_batch", "openai_batch"]+# The single source of truth for execution paths; ``model_pricing``,+# ``billing`` and ``schemas`` import it from here.+ExecutionPath = Literal["sync_baseline", "anthropic_batch"]-# Transports that cannot honour a batch path even when an Anthropic /-# OpenAI key is configured separately.+# Transports that cannot honour the batch path even when an Anthropic key+# is configured separately.## - ``"local"`` — local backends (Ollama, vLLM, …) don't expose batch# endpoints; even if the operator set ``ANTHROPIC_API_KEY`` for some@@ -44,18 +39,15 @@ _TRANSPORTS_FORCE_SYNC: frozenset[TransportName] = frozenset({"local", "subscripdef resolve_dream_execution_path(*,has_anthropic_key: bool,- has_openai_key: bool = False,batch_processing_enabled: bool = False,transport_name: TransportName | None = None,) -> ExecutionPath:"""Pick the dream pass execution path.- Both batch paths require their respective provider API key AND the- ``batch_processing_enabled`` flag. Anthropic batch is preferred- when both keys are present (better cache pricing for the consolidation- + sanitization phases that share context). Falls back to sync_baseline- when no batch path is viable — slower and pricier per pass, but- works on every transport.+ The batch path requires a direct Anthropic API key AND the+ ``batch_processing_enabled`` flag. Falls back to sync_baseline+ otherwise — slower and pricier per pass, but works on every+ transport.``transport_name`` (when provided) takes precedence over the keyflags: ``"local"`` and ``"subscription"`` always force@@ -66,9 +58,6 @@ def resolve_dream_execution_path("""if transport_name in _TRANSPORTS_FORCE_SYNC:return "sync_baseline"- if batch_processing_enabled:- if has_anthropic_key:- return "anthropic_batch"- if has_openai_key:- return "openai_batch"+ if batch_processing_enabled and has_anthropic_key:+ return "anthropic_batch"return "sync_baseline"diff --git a/autogpt_platform/backend/backend/copilot/dream/routing_test.py b/autogpt_platform/backend/backend/copilot/dream/routing_test.pyindex a1161e5c87..c810c06122 100644--- a/autogpt_platform/backend/backend/copilot/dream/routing_test.py+++ b/autogpt_platform/backend/backend/copilot/dream/routing_test.py@@ -8,46 +8,27 @@ from .routing import resolve_dream_execution_path@pytest.mark.parametrize(- "has_anthropic_key,has_openai_key,batch_enabled,expected",+ "has_anthropic_key,batch_enabled,expected",[- # Both keys + batch on: Anthropic wins (better cache pricing).- (True, True, True, "anthropic_batch"),- # Anthropic only + batch on: anthropic_batch.- (True, False, True, "anthropic_batch"),- # OpenAI only + batch on: openai_batch.- (False, True, True, "openai_batch"),- # Batch flag off — every combination falls back to sync_baseline.- (True, True, False, "sync_baseline"),- (True, False, False, "sync_baseline"),- (False, True, False, "sync_baseline"),- (False, False, True, "sync_baseline"),- (False, False, False, "sync_baseline"),+ # Anthropic key + batch on: anthropic_batch.+ (True, True, "anthropic_batch"),+ # Batch flag off — falls back to sync_baseline with or without a key.+ (True, False, "sync_baseline"),+ (False, False, "sync_baseline"),+ # No key — the flag alone cannot open the batch path.+ (False, True, "sync_baseline"),],)-def test_routing_branches(has_anthropic_key, has_openai_key, batch_enabled, expected):+def test_routing_branches(has_anthropic_key, batch_enabled, expected):assert (resolve_dream_execution_path(has_anthropic_key=has_anthropic_key,- has_openai_key=has_openai_key,batch_processing_enabled=batch_enabled,)== expected)-def test_has_openai_key_defaults_to_false_for_backward_compat():- """Callers from before the multi-provider expansion only passed- ``has_anthropic_key``. Keep that working by defaulting- ``has_openai_key`` to False — they'll still route correctly to- anthropic_batch or sync_baseline."""- assert (- resolve_dream_execution_path(- has_anthropic_key=True, batch_processing_enabled=True- )- == "anthropic_batch"- )--@pytest.mark.parametrize("transport_name", ["local", "subscription"])def test_local_and_subscription_transports_force_sync_baseline(transport_name):"""Local installs have no batch endpoint; subscription users@@ -59,7 +40,6 @@ def test_local_and_subscription_transports_force_sync_baseline(transport_name):assert (resolve_dream_execution_path(has_anthropic_key=True,- has_openai_key=True,batch_processing_enabled=True,transport_name=transport_name,)@@ -70,7 +50,7 @@ def test_local_and_subscription_transports_force_sync_baseline(transport_name):@pytest.mark.parametrize("transport_name", ["openrouter", "direct_anthropic", None])def test_batch_eligible_transports_unaffected(transport_name):"""openrouter / direct_anthropic / ``None`` (no override) preserve- the historical key-driven behaviour — the new ``transport_name``+ the historical key-driven behaviour — the ``transport_name``gate only fires for ``local`` and ``subscription``."""assert (resolve_dream_execution_path(diff --git a/autogpt_platform/backend/backend/copilot/dream/schemas.py b/autogpt_platform/backend/backend/copilot/dream/schemas.pyindex d10fe8b74c..30f2421ace 100644--- a/autogpt_platform/backend/backend/copilot/dream/schemas.py+++ b/autogpt_platform/backend/backend/copilot/dream/schemas.py@@ -19,6 +19,8 @@ from pydantic import BaseModel, Field, model_validatorfrom backend.copilot.graphiti.memory_model import MemoryKind+from .routing import ExecutionPath+logger = logging.getLogger(__name__)@@ -305,7 +307,7 @@ class DreamPassUsage(BaseModel):"""Sum of phase cost_usd values; ``None`` if any phase was unknown."""discount_applied: float = 0.0"""Execution-path discount factor in [0, 1] — 0.0 for sync_baseline,- 0.5 for anthropic_batch / openai_batch. The ``total_cost_usd``+ 0.5 for anthropic_batch. The ``total_cost_usd``above already has this factored in; recorded separately so thecost ledger can audit the savings."""@@ -322,9 +324,7 @@ class DreamPassResult(BaseModel):started_at: datetime | None = Nonecompleted_at: datetime | None = Noneelapsed_seconds: float | None = None- execution_path: Literal["sync_baseline", "anthropic_batch", "openai_batch"] = (- "sync_baseline"- )+ execution_path: ExecutionPath = "sync_baseline"# Per-phase telemetry — null when the phase did not run.consolidated_count: int = 0diff --git a/autogpt_platform/backend/backend/executor/batch_executor.py b/autogpt_platform/backend/backend/executor/batch_executor.pyindex cf60a36e5e..9b46b813ad 100644--- a/autogpt_platform/backend/backend/executor/batch_executor.py+++ b/autogpt_platform/backend/backend/executor/batch_executor.py@@ -1,7 +1,7 @@"""Background service that polls submitted LLM batches and dispatches results.The dream-pass orchestrator (and any future server-side batch caller)-submits requests to Anthropic / OpenAI batch APIs via+submits requests to the Anthropic batch API via``backend/util/llm/providers.call_provider(execution_mode="batch")``.Submissions return immediately with a ``BatchSubmissionRef``; resultsarrive asynchronously up to ~24h later. This service owns:diff --git a/autogpt_platform/frontend/src/app/api/openapi.json b/autogpt_platform/frontend/src/app/api/openapi.jsonindex 23f4b771ba..78737c227f 100644--- a/autogpt_platform/frontend/src/app/api/openapi.json+++ b/autogpt_platform/frontend/src/app/api/openapi.json@@ -21416,7 +21416,7 @@},"execution_path": {"type": "string",- "enum": ["sync_baseline", "anthropic_batch", "openai_batch"],+ "enum": ["sync_baseline", "anthropic_batch"],"title": "Execution Path","default": "sync_baseline"},