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.

refactor(backend/copilot): remove dead dream/batch provider decoy (#13450)

Nicholas Tindleb58eca2ce258
diff --git a/autogpt_platform/backend/backend/copilot/dream/batch/__init__.py b/autogpt_platform/backend/backend/copilot/dream/batch/__init__.py
deleted file mode 100644
index 6599c39ef5..0000000000
--- a/autogpt_platform/backend/backend/copilot/dream/batch/__init__.py
+++ /dev/null
@@ -1,19 +0,0 @@
-"""Batch-API integration for dream passes.
-
-Anthropic and OpenAI both offer a Message Batch API that's 50% cheaper
-than the synchronous endpoint but takes hours instead of seconds. The
-dream pass is exactly the workload that wants this — it runs at 3 AM,
-nobody is waiting on it, and 50% off three Sonnet/Opus calls per user
-per night is meaningful at production scale.
-
-Module layout (per ``dream/p0-spec.md`` §P0.1):
- * models.py — typed BatchRequest / BatchResult / BatchStatus
- * provider.py — BatchProvider Protocol + NullBatchProvider
- * anthropic_provider.py — TODO: real Anthropic AsyncMessageBatch wrapper
- * openai_provider.py — TODO: real OpenAI client.batches wrapper
- * factory.py — pick a provider for a given ExecutionPath
-
-Today the dream orchestrator only wires sync_baseline; the
-provider-aware path is staged here so the orchestrator can adopt it
-incrementally without another big refactor.
-"""
diff --git a/autogpt_platform/backend/backend/copilot/dream/batch/anthropic_provider.py b/autogpt_platform/backend/backend/copilot/dream/batch/anthropic_provider.py
deleted file mode 100644
index e261a092ce..0000000000
--- a/autogpt_platform/backend/backend/copilot/dream/batch/anthropic_provider.py
+++ /dev/null
@@ -1,60 +0,0 @@
-"""Anthropic Message Batches adapter — IMPLEMENTATION STUB.
-
-The real adapter wraps ``anthropic.AsyncAnthropic().messages.batches``.
-That client lives behind the ``anthropic`` package; the dream pipeline
-ships with the package as a dependency (used by the SDK chat path)
-so no extra install is needed.
-
-Stub today, real impl in a follow-up PR. Filling this in is mostly
-mechanical:
-
-1. ``submit`` — call ``client.messages.batches.create(requests=[
- {"custom_id": r.custom_id, "params": {...}} for r in requests])``,
- map the returned ``Batch`` object onto ``BatchSubmission``.
-2. ``poll`` — call ``client.messages.batches.retrieve(batch_id)``,
- normalize ``processing_status`` (``in_progress`` /
- ``canceling`` / ``ended``) onto ``BatchStatus``.
-3. ``download_results`` — call
- ``client.messages.batches.results(batch_id)``; the body is JSONL
- with one line per request. Parse each line, extract
- ``result.message.content`` + ``result.message.usage``, build a
- ``BatchResult``. ``result.type == "errored"`` → set ``error``.
-
-The Pydantic models in ``models.py`` are deliberately narrower than
-Anthropic's full response shape so the adapter has freedom to drop
-fields we don't use (e.g. ``request_counts``).
-
-The ``cost_usd`` field is computed via ``model_pricing.compute_cost_usd``
-with ``execution_path="anthropic_batch"`` so the 50% discount is
-applied. Anthropic doesn't return a ``cost`` field; computing it
-from tokens against our rate card is the contract.
-"""
-
-from __future__ import annotations
-
-from typing import Sequence
-
-from .models import BatchRequest, BatchResult, BatchSubmission
-
-
-class AnthropicBatchProvider:
- """Stub placeholder. See module docstring for the implementation
- plan. Calling any method raises ``NotImplementedError`` with a
- pointer to ``p0-spec.md §P0.1``."""
-
- name = "anthropic"
-
- async def submit(self, requests: Sequence[BatchRequest]) -> BatchSubmission:
- raise NotImplementedError(
- "AnthropicBatchProvider.submit not yet implemented — "
- "see dream/p0-spec.md §P0.1 and "
- "dream/batch/anthropic_provider.py module docstring."
- )
-
- async def poll(self, submission: BatchSubmission) -> BatchSubmission:
- raise NotImplementedError("AnthropicBatchProvider.poll not yet implemented.")
-
- async def download_results(self, submission: BatchSubmission) -> list[BatchResult]:
- raise NotImplementedError(
- "AnthropicBatchProvider.download_results not yet implemented."
- )
diff --git a/autogpt_platform/backend/backend/copilot/dream/batch/batch_test.py b/autogpt_platform/backend/backend/copilot/dream/batch/batch_test.py
deleted file mode 100644
index 4cf40fb329..0000000000
--- a/autogpt_platform/backend/backend/copilot/dream/batch/batch_test.py
+++ /dev/null
@@ -1,156 +0,0 @@
-"""Batch scaffolding tests — pins the Protocol shape + factory routing.
-
-Real-provider tests land when the Anthropic / OpenAI adapters are
-filled in (currently NotImplementedError stubs). For now we only
-need to assert:
- * BatchRequest / BatchResult round-trip via Pydantic.
- * NullBatchProvider's surface matches the BatchProvider Protocol.
- * The factory routes to the right provider per ExecutionPath.
- * Stub providers raise NotImplementedError with a spec pointer
- (so anyone calling them gets a clear next step).
-"""
-
-from __future__ import annotations
-
-from datetime import datetime, timezone
-
-import pytest
-
-from .anthropic_provider import AnthropicBatchProvider
-from .factory import USE_STUB_BATCH_PROVIDERS, get_batch_provider
-from .models import BatchRequest, BatchResult, BatchStatus, BatchSubmission
-from .openai_provider import OpenAIBatchProvider
-from .provider import BatchProvider, NullBatchProvider
-
-# ---------------------------------------------------------------------------
-# Model round-trips
-# ---------------------------------------------------------------------------
-
-
-def test_batch_request_round_trips_through_pydantic_dump():
- req = BatchRequest(
- custom_id="pass-1:consolidate",
- model="anthropic/claude-sonnet-4.6",
- messages=[{"role": "user", "content": "hi"}],
- temperature=0.2,
- )
- revived = BatchRequest.model_validate(req.model_dump())
- assert revived == req
-
-
-def test_batch_result_defaults_cost_to_none_when_provider_silent():
- """``cost_usd=None`` is the documented "provider didn't return
- cost" sentinel that the orchestrator's rate-card fallback keys off."""
- r = BatchResult(custom_id="x", content="{}", model="m")
- assert r.cost_usd is None
- assert r.error is None
-
-
-def test_batch_submission_default_status_is_pending():
- sub = BatchSubmission(
- provider_batch_id="b1",
- provider="anthropic",
- submitted_at=datetime.now(timezone.utc),
- )
- assert sub.status == BatchStatus.PENDING
-
-
-# ---------------------------------------------------------------------------
-# NullBatchProvider
-# ---------------------------------------------------------------------------
-
-
-async def test_null_provider_submit_reports_failed_status_with_empty_batch_id():
- """The Null provider's contract: never succeed, fail in a way the
- orchestrator can read structurally (no exception)."""
- provider = NullBatchProvider()
- sub = await provider.submit([BatchRequest(custom_id="x", model="m")])
- assert sub.status == BatchStatus.FAILED
- assert sub.provider_batch_id == ""
- assert sub.provider == "null"
-
-
-async def test_null_provider_download_returns_empty_list():
- provider = NullBatchProvider()
- sub = BatchSubmission(
- provider_batch_id="",
- provider="null",
- submitted_at=datetime.now(timezone.utc),
- status=BatchStatus.FAILED,
- )
- assert await provider.download_results(sub) == []
-
-
-def test_null_provider_satisfies_batch_provider_protocol():
- """Protocol structural check — keeps the contract honest when
- we add methods to BatchProvider later."""
- provider: BatchProvider = NullBatchProvider()
- assert provider.name == "null"
-
-
-# ---------------------------------------------------------------------------
-# Factory routing
-# ---------------------------------------------------------------------------
-
-
-def test_factory_returns_null_for_sync_baseline():
- """sync_baseline never uses batch — orchestrator gates upstream,
- but the factory still has to handle the path without raising."""
- provider = get_batch_provider("sync_baseline")
- assert isinstance(provider, NullBatchProvider)
-
-
-def test_use_stub_batch_providers_flag_is_off():
- """Step 5 of the rollout flipped this off: the orchestrator's
- Anthropic batch path now goes directly through
- ``backend/util/llm/providers.call_provider(execution_mode="batch")``.
- The legacy factory + stub providers are kept around only for
- callers that still want the Protocol-shaped abstraction (P-0.1
- callers and the future OpenAI batch path)."""
- assert USE_STUB_BATCH_PROVIDERS is False
-
-
-def test_factory_returns_anthropic_provider_when_unstubbed():
- """With the stub flag off the factory hands back the real
- AnthropicBatchProvider for ``anthropic_batch`` paths. Today this
- is unused by the orchestrator (which calls ``call_provider``
- directly) but kept for adapter symmetry once OpenAI batch lands."""
- provider = get_batch_provider("anthropic_batch")
- # Specifically NOT NullBatchProvider — the stub-gated test above
- # would catch a regression flipping the flag back to True.
- assert not isinstance(provider, NullBatchProvider)
-
-
-def test_factory_returns_openai_provider_when_unstubbed():
- """Same contract for OpenAI."""
- provider = get_batch_provider("openai_batch")
- assert not isinstance(provider, NullBatchProvider)
-
-
-# ---------------------------------------------------------------------------
-# Stub providers raise with a clear next-step pointer
-# ---------------------------------------------------------------------------
-
-
-async def test_anthropic_stub_submit_raises_with_spec_pointer():
- """Anyone who reaches the stub gets a clear NEXT STEP, not a
- generic AttributeError or silent no-op."""
- provider = AnthropicBatchProvider()
- with pytest.raises(NotImplementedError, match="p0-spec.md §P0.1"):
- await provider.submit([])
-
-
-async def test_openai_stub_poll_raises_with_clear_message():
- provider = OpenAIBatchProvider()
- with pytest.raises(NotImplementedError, match="not yet implemented"):
- await provider.poll(
- BatchSubmission(
- provider_batch_id="b1",
- provider="openai",
- submitted_at=datetime.now(timezone.utc),
- )
- )
diff --git a/autogpt_platform/backend/backend/copilot/dream/batch/factory.py b/autogpt_platform/backend/backend/copilot/dream/batch/factory.py
deleted file mode 100644
index 3e67df2ac6..0000000000
--- a/autogpt_platform/backend/backend/copilot/dream/batch/factory.py
+++ /dev/null
@@ -1,64 +0,0 @@
-"""Pick a BatchProvider for a given ExecutionPath + config state.
-
-Single seam the orchestrator calls when it routes to a batch path.
-Today the AnthropicBatchProvider and OpenAIBatchProvider are stubs;
-this factory always returns the Null provider so the orchestrator's
-batch path short-circuits to sync_baseline cleanly when the stubs
-are detected. As soon as the real adapters land, flip the
-``USE_STUB_BATCH_PROVIDERS`` flag off and the orchestrator picks
-them up automatically.
-
-The factory deliberately does NOT read provider API keys here —
-``resolve_dream_execution_path`` in routing.py already gates on
-``has_anthropic_key`` / ``has_openai_key`` upstream. If we get to
-this factory, the routing decision said "use this batch path"; our
-job is only to hand back a working provider for that path.
-"""
-
-from __future__ import annotations
-
-import logging
-
-from ..routing import ExecutionPath
-from .anthropic_provider import AnthropicBatchProvider
-from .openai_provider import OpenAIBatchProvider
-from .provider import BatchProvider, NullBatchProvider
-
-logger = logging.getLogger(__name__)
-
-
-# The orchestrator's Anthropic batch path now goes directly through
-# ``backend/util/llm/providers.call_provider(execution_mode="batch")``;
-# this factory is preserved only for callers that still want the
-# Protocol-shaped provider abstraction (P-0.1 stub callers, future
-# OpenAI batch path). Flipped to ``False`` as of Step 5 of the
-# plan in ``plans/idempotent-launching-moth.md`` so the orchestrator
-# isn't confused into thinking the providers are stubbed.
-USE_STUB_BATCH_PROVIDERS = False
-
-
-def get_batch_provider(execution_path: ExecutionPath) -> BatchProvider:
- """Return the BatchProvider for the chosen execution path.
-
- ``sync_baseline`` always returns the Null provider — sync runs
- don't use batch at all; the orchestrator gates on the path
- before calling this. The function still accepts sync_baseline to
- avoid a special case at the call site.
- """
- if execution_path == "sync_baseline":
- return NullBatchProvider()
-
- if USE_STUB_BATCH_PROVIDERS:
- logger.info(
- "dream batch: execution_path=%s but providers are stubbed; "
- "returning NullBatchProvider — orchestrator should fall back "
- "to sync_baseline.",
- execution_path,
- )
- return NullBatchProvider()
-
- if execution_path == "anthropic_batch":
- return AnthropicBatchProvider()
- if execution_path == "openai_batch":
- return OpenAIBatchProvider()
- return NullBatchProvider()
diff --git a/autogpt_platform/backend/backend/copilot/dream/batch/models.py b/autogpt_platform/backend/backend/copilot/dream/batch/models.py
deleted file mode 100644
index 7997bbe581..0000000000
--- a/autogpt_platform/backend/backend/copilot/dream/batch/models.py
+++ /dev/null
@@ -1,102 +0,0 @@
-"""Provider-agnostic typed shapes for batch dream passes.
-
-Both Anthropic and OpenAI expose a similar API surface:
- 1. Submit N message-completion requests in one HTTP call.
- 2. Poll until the batch is processing → ended.
- 3. Download JSONL results, route per-request by ``custom_id``.
-
-These models normalize that surface so the orchestrator never knows
-which provider it's talking to. Per-provider quirks (Anthropic's
-``ended_at`` vs OpenAI's ``completed_at``, beta header requirements,
-JSONL line format) live in the per-provider adapter.
-
-The schema is intentionally narrower than either provider's full
-API — we only model what the dream pipeline uses, so neither provider
-has to be feature-complete to wire in.
-"""
-
-from __future__ import annotations
-
-from datetime import datetime
-from enum import Enum
-from typing import Any
-
-from pydantic import BaseModel, Field
-
-
-class BatchStatus(str, Enum):
- """Lifecycle states a submitted batch can be in.
-
- Both providers have richer status enums (Anthropic adds
- ``canceling``, ``expired``; OpenAI adds ``finalizing``,
- ``cancelling``). Normalize to these four because the dream
- pipeline only cares about "is this done yet" + "should I retry".
- """
-
- PENDING = "pending"
- """Submitted; provider hasn't started processing."""
- PROCESSING = "processing"
- """Provider is generating responses."""
- ENDED = "ended"
- """Finished — results ready to download."""
- FAILED = "failed"
- """Provider returned an unrecoverable error. Surfaces as ``error``."""
-
-
-class BatchRequest(BaseModel):
- """One LLM call inside a submitted batch.
-
- ``custom_id`` is opaque to the provider — we use it to route the
- response back to the correct dream pass + phase. Convention:
- ``"{pass_id}:{phase}"``. The dream pipeline only ever submits 3
- requests per pass (one per phase), so collisions are impossible.
- """
-
- custom_id: str = Field(description="Routing key the orchestrator uses.")
- model: str
- messages: list[dict[str, Any]] = Field(default_factory=list)
- response_format: dict[str, Any] | None = None
- max_output_tokens: int = 4096
- temperature: float = 0.0
-
-
-class BatchResult(BaseModel):
- """One LLM response inside a downloaded batch result.
-
- Mirrors ``StructuredCompletion`` from ``dream/llm.py`` but
- deserialized from a batch JSONL line rather than a real-time
- completion. The orchestrator hands ``content`` to the same parser
- that handles sync responses (``_strip_json_code_fence`` +
- ``_extract_first_json_object``), so phase-2/3 lenient parsing
- keeps working on batch results.
- """
-
- custom_id: str
- content: str
- """Raw response body — JSON string ready for the phase parser."""
- model: str
- input_tokens: int = 0
- output_tokens: int = 0
- cache_read_tokens: int = 0
- cache_creation_tokens: int = 0
- cost_usd: float | None = None
- error: str | None = None
- """Per-request error (e.g. moderation rejection); does NOT fail
- the whole batch. Surface so the orchestrator can record it as
- a phase failure and supersede the dream pass."""
-
-
-class BatchSubmission(BaseModel):
- """Provider's acknowledgement of a submission.
-
- ``provider_batch_id`` is what the poller uses to look up status
- later — Anthropic returns a UUID, OpenAI returns ``"batch_..."``.
- Both are opaque strings to us.
- """
-
- provider_batch_id: str
- provider: str
- """``"anthropic"`` | ``"openai"`` — the same string used as the
- ``provider`` tag on ``PlatformCostLog`` rows."""
- submitted_at: datetime
- status: BatchStatus = BatchStatus.PENDING
diff --git a/autogpt_platform/backend/backend/copilot/dream/batch/openai_provider.py b/autogpt_platform/backend/backend/copilot/dream/batch/openai_provider.py
deleted file mode 100644
index 7807b23bae..0000000000
--- a/autogpt_platform/backend/backend/copilot/dream/batch/openai_provider.py
+++ /dev/null
@@ -1,60 +0,0 @@
-"""OpenAI Batch API adapter — IMPLEMENTATION STUB.
-
-The real adapter wraps ``openai.AsyncOpenAI().batches`` + ``.files``.
-OpenAI's batch flow is two-step:
-
-1. Upload a JSONL file via ``client.files.create(purpose="batch")``.
- Each line is one ``ChatCompletion`` request with a ``custom_id``.
-2. Create a batch via ``client.batches.create(input_file_id=...,
- endpoint="/v1/chat/completions", completion_window="24h")``.
-
-Polling/downloading mirror the Anthropic flow but the JSONL line
-format differs — see https://platform.openai.com/docs/guides/batch.
-
-Stub today, real impl in a follow-up PR. Filling this in is mostly
-mechanical:
-
-1. ``submit`` — write the requests to an in-memory buffer, upload
- via ``files.create``, then ``batches.create``.
-2. ``poll`` — ``batches.retrieve(batch_id)``; normalize
- ``status`` (``validating`` / ``in_progress`` / ``finalizing`` /
- ``completed`` / ``failed``) onto ``BatchStatus``.
-3. ``download_results`` — download ``output_file_id`` via
- ``files.content(...)``, parse JSONL, extract
- ``response.body.choices[0].message.content`` +
- ``response.body.usage``. Track ``error_file_id`` separately for
- per-request errors.
-
-The ``cost_usd`` field comes from ``model_pricing.compute_cost_usd``
-with ``execution_path="openai_batch"`` (50% discount applied).
-OpenAI's batch responses don't carry a cost field either.
-"""
-
-from __future__ import annotations
-
-from typing import Sequence
-
-from .models import BatchRequest, BatchResult, BatchSubmission
-
-
-class OpenAIBatchProvider:
- """Stub placeholder. See module docstring for the implementation
- plan. Calling any method raises ``NotImplementedError`` with a
- pointer to ``p0-spec.md §P0.1``."""
-
- name = "openai"
-
- async def submit(self, requests: Sequence[BatchRequest]) -> BatchSubmission:
- raise NotImplementedError(
- "OpenAIBatchProvider.submit not yet implemented — "
- "see dream/p0-spec.md §P0.1 and "
- "dream/batch/openai_provider.py module docstring."
- )
-
- async def poll(self, submission: BatchSubmission) -> BatchSubmission:
- raise NotImplementedError("OpenAIBatchProvider.poll not yet implemented.")
-
- async def download_results(self, submission: BatchSubmission) -> list[BatchResult]:
- raise NotImplementedError(
- "OpenAIBatchProvider.download_results not yet implemented."
- )
diff --git a/autogpt_platform/backend/backend/copilot/dream/batch/provider.py b/autogpt_platform/backend/backend/copilot/dream/batch/provider.py
deleted file mode 100644
index a7cc9ba104..0000000000
--- a/autogpt_platform/backend/backend/copilot/dream/batch/provider.py
+++ /dev/null
@@ -1,84 +0,0 @@
-"""BatchProvider Protocol + a Null implementation.
-
-Every concrete batch provider (Anthropic, OpenAI) implements this
-Protocol. The Null provider always reports submission failure with a
-documented error so the orchestrator falls back to sync_baseline. The
-dream pipeline can wire BatchProvider in today and pick up
-real-Anthropic / real-OpenAI when those adapters land.
-"""
-
-from __future__ import annotations
-
-import logging
-from datetime import datetime, timezone
-from typing import Protocol, Sequence
-
-from .models import BatchRequest, BatchResult, BatchStatus, BatchSubmission
-
-logger = logging.getLogger(__name__)
-
-
-class BatchProvider(Protocol):
- """What a concrete batch backend (Anthropic / OpenAI) must implement.
-
- Lifecycle:
- 1. ``submit(requests)`` → returns a ``BatchSubmission`` whose
- ``provider_batch_id`` is the lookup key.
- 2. ``poll(submission)`` → returns the same submission with an
- updated ``status``. Caller decides when to poll again.
- 3. ``download_results(submission)`` → returns the per-request
- responses. Only safe to call when status is ``ENDED``.
-
- Cancellation, retries, and exponential-backoff polling cadence
- are the *caller's* responsibility (lives in ``poller.py`` once
- that module is filled in). The provider only owns the API surface.
- """
-
- name: str
-
- async def submit(self, requests: Sequence[BatchRequest]) -> BatchSubmission: ...
-
- async def poll(self, submission: BatchSubmission) -> BatchSubmission: ...
-
- async def download_results(
- self, submission: BatchSubmission
- ) -> list[BatchResult]: ...
-
-
-class NullBatchProvider:
- """Always-fails BatchProvider.
-
- Returned by ``factory.get_batch_provider`` when neither Anthropic
- nor OpenAI is configured (no API key, or batch flag off). Surfaces
- a structured "no batch backend" error so the orchestrator's batch
- path can short-circuit to sync_baseline cleanly instead of crashing
- on a missing adapter.
-
- Submitting against this provider yields a synthetic ``FAILED``
- submission whose ``provider_batch_id`` is empty; polling and
- downloading return the same status and an empty result list. The
- orchestrator should never reach the download step against a Null
- provider, but defending against it is a one-liner so we do.
- """
-
- name = "null"
-
- async def submit(self, requests: Sequence[BatchRequest]) -> BatchSubmission:
- logger.info(
- "NullBatchProvider.submit() called with %d requests — no "
- "batch backend configured; caller should fall back to "
- "sync_baseline.",
- len(requests),
- )
- return BatchSubmission(
- provider_batch_id="",
- provider=self.name,
- submitted_at=datetime.now(timezone.utc),
- status=BatchStatus.FAILED,
- )
-
- async def poll(self, submission: BatchSubmission) -> BatchSubmission:
- return submission
-
- async def download_results(self, submission: BatchSubmission) -> list[BatchResult]:
- return []