-
Notifications
You must be signed in to change notification settings - Fork 5
[4.D.4] Refactor worker_agent.py to use LLMProvider abstraction #546
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or requestphase-4Phase 4: Multi-Agent CoordinationPhase 4: Multi-Agent CoordinationrefactorIssues specifically associated with the refactorIssues specifically associated with the refactor
Description
Parent
Part of #542 — Multi-provider LLM support
Depends on
#543 (OpenAI adapter), #544 (factory wiring)
What
worker_agent.py currently hardcodes AsyncAnthropic() directly. Replace with the LLMProvider abstraction so any provider can be used.
Current problem
# codeframe/agents/worker_agent.py — today
from anthropic import AsyncAnthropic, AuthenticationError, RateLimitError, APIConnectionError
class WorkerAgent:
async def execute_task(self, task, model_name="claude-sonnet-4-5"):
client = AsyncAnthropic(api_key=self.api_key)
response = await client.messages.create(...) # Anthropic-onlyTarget state
# after refactor
from codeframe.adapters.llm.base import LLMProvider, Purpose
from codeframe.adapters.llm import get_provider
class WorkerAgent:
def __init__(self, ..., llm_provider: LLMProvider | None = None):
self.llm_provider = llm_provider or get_provider()
async def execute_task(self, task, ...):
response = await self.llm_provider.async_complete(...)Files to modify
codeframe/agents/worker_agent.py— replaceAsyncAnthropicwithLLMProvidercodeframe/adapters/llm/base.py— addasync_complete()/async_stream()toLLMProviderABC if not presentcodeframe/adapters/llm/anthropic.py— implementasync_complete()wrapping existing async pathcodeframe/adapters/llm/openai.py— implementasync_complete()tests/integration/test_worker_agent_integration.py— update fixtures
Notes
- Keep
providerconstructor param for backwards compat ("anthropic","openai") - Error translation: map provider-specific errors (
openai.RateLimitError) to a commonLLMRateLimitErrorbase exception inbase.pyso callers don't need to handle per-provider exceptions - The
SUPPORTED_MODELSlist andMODEL_PRICINGdict should move to provider implementations (each knows its own models/prices)
Acceptance criteria
-
WorkerAgenthas noimport anthropicanywhere -
WorkerAgent(llm_provider=OpenAIProvider(...))works in tests - Existing integration tests still pass with Anthropic provider
- New integration test passes with OpenAI provider (or mocked OpenAI)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestphase-4Phase 4: Multi-Agent CoordinationPhase 4: Multi-Agent CoordinationrefactorIssues specifically associated with the refactorIssues specifically associated with the refactor