-
Notifications
You must be signed in to change notification settings - Fork 5
feat: Agent Adapter Architecture — delegate to frontier coding agents (#408) #428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2a5ad4d
feat(adapters): add AgentAdapter protocol, AgentResult, and AgentEven…
f349edd
feat(adapters): add TaskContextPackager for rich prompt assembly (#410)
02b8d16
feat(adapters): add SubprocessAdapter base class for external agent CLIs
cb4f09b
feat(adapters): add VerificationWrapper for post-execution gate check…
bfe8cf4
feat(adapters): add builtin React and Plan adapter shims
724e7ab
feat(adapters): add Claude Code CLI adapter (#411)
bcfbe1a
feat(adapters): add OpenCode CLI adapter (#416)
ae71ce2
feat(adapters): add engine registry for adapter lookup and resolution…
74cc141
feat(core): wire external engine adapters into runtime and CLI (#408)
c679406
fix(adapters): prevent subprocess deadlock and add timeout support
a02cd8e
fix: remove unused imports flagged by CI lint
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| from codeframe.core.adapters.agent_adapter import ( | ||
| AgentAdapter, | ||
| AgentEvent, | ||
| AgentResult, | ||
| ) | ||
| from codeframe.core.adapters.builtin import ( | ||
| BuiltinPlanAdapter, | ||
| BuiltinReactAdapter, | ||
| ) | ||
| from codeframe.core.adapters.claude_code import ClaudeCodeAdapter | ||
| from codeframe.core.adapters.opencode import OpenCodeAdapter | ||
| from codeframe.core.adapters.subprocess_adapter import SubprocessAdapter | ||
| from codeframe.core.adapters.verification_wrapper import VerificationWrapper | ||
|
|
||
| __all__ = [ | ||
| "AgentAdapter", | ||
| "AgentEvent", | ||
| "AgentResult", | ||
| "BuiltinPlanAdapter", | ||
| "BuiltinReactAdapter", | ||
| "ClaudeCodeAdapter", | ||
| "OpenCodeAdapter", | ||
| "SubprocessAdapter", | ||
| "VerificationWrapper", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| """Agent adapter protocol for delegating task execution to external coding agents.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass, field | ||
| from pathlib import Path | ||
| from typing import Callable, Literal, Protocol, runtime_checkable | ||
|
|
||
|
|
||
| @dataclass | ||
| class AgentResult: | ||
| """Result from an agent adapter execution.""" | ||
|
|
||
| status: Literal["completed", "failed", "blocked"] | ||
| output: str = "" | ||
| modified_files: list[str] = field(default_factory=list) | ||
| error: str | None = None | ||
| blocker_question: str | None = None | ||
|
|
||
|
|
||
| @dataclass | ||
| class AgentEvent: | ||
| """Progress event emitted during agent execution.""" | ||
|
|
||
| type: str # "progress", "tool_call", "output", "error" | ||
| data: dict = field(default_factory=dict) | ||
|
|
||
|
|
||
| @runtime_checkable | ||
| class AgentAdapter(Protocol): | ||
| """Protocol for agent execution engines. | ||
|
|
||
| Any coding agent (Claude Code, OpenCode, Codex, etc.) must implement | ||
| this interface to be used as a CodeFRAME execution engine. | ||
| """ | ||
|
|
||
| @property | ||
| def name(self) -> str: | ||
| """Engine name (e.g., 'claude-code', 'opencode').""" | ||
| ... | ||
|
|
||
| def run( | ||
| self, | ||
| task_id: str, | ||
| prompt: str, | ||
| workspace_path: Path, | ||
| on_event: Callable[[AgentEvent], None] | None = None, | ||
| ) -> AgentResult: | ||
| """Execute a task and return the result. | ||
|
|
||
| Args: | ||
| task_id: CodeFRAME task identifier | ||
| prompt: Rich context prompt assembled by TaskContextPackager | ||
| workspace_path: Path to the workspace/repo root | ||
| on_event: Optional callback for streaming progress events | ||
|
|
||
| Returns: | ||
| AgentResult with status, output, and modified files | ||
| """ | ||
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| """Builtin adapter shims wrapping ReactAgent and Agent behind AgentAdapter protocol.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
| from typing import TYPE_CHECKING, Callable, Optional | ||
|
|
||
| from codeframe.core.adapters.agent_adapter import AgentEvent, AgentResult | ||
|
|
||
| if TYPE_CHECKING: | ||
| from codeframe.adapters.llm.base import LLMProvider | ||
| from codeframe.core.conductor import GlobalFixCoordinator | ||
| from codeframe.core.stall_detector import StallAction | ||
| from codeframe.core.streaming import EventPublisher, RunOutputLogger | ||
| from codeframe.core.workspace import Workspace | ||
|
|
||
|
|
||
| class BuiltinReactAdapter: | ||
| """Wraps the existing ReactAgent behind the AgentAdapter interface. | ||
|
|
||
| This shim allows the ReactAgent to be used through the unified | ||
| engine registry without modifying the ReactAgent class itself. | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| workspace: Workspace, | ||
| llm_provider: LLMProvider, | ||
| *, | ||
| stall_timeout_s: float = 300, | ||
| stall_action: Optional[StallAction] = None, | ||
| event_publisher: Optional[EventPublisher] = None, | ||
| dry_run: bool = False, | ||
| verbose: bool = False, | ||
| debug: bool = False, | ||
| output_logger: Optional[RunOutputLogger] = None, | ||
| fix_coordinator: Optional[GlobalFixCoordinator] = None, | ||
| ) -> None: | ||
| self._workspace = workspace | ||
| self._llm_provider = llm_provider | ||
| self._stall_timeout_s = stall_timeout_s | ||
| self._stall_action = stall_action | ||
| self._event_publisher = event_publisher | ||
| self._dry_run = dry_run | ||
| self._verbose = verbose | ||
| self._debug = debug | ||
| self._output_logger = output_logger | ||
| self._fix_coordinator = fix_coordinator | ||
|
|
||
| @property | ||
| def name(self) -> str: | ||
| return "react" | ||
|
|
||
| def run( | ||
| self, | ||
| task_id: str, | ||
| prompt: str, | ||
| workspace_path: Path, | ||
| on_event: Callable[[AgentEvent], None] | None = None, | ||
| ) -> AgentResult: | ||
| """Run the ReactAgent and map its AgentStatus to AgentResult.""" | ||
| from codeframe.core.react_agent import ReactAgent | ||
|
|
||
| def _bridge_event(event_type: str, data: dict) -> None: | ||
| if on_event: | ||
| on_event(AgentEvent(type=event_type, data=data)) | ||
|
|
||
| kwargs: dict = { | ||
| "workspace": self._workspace, | ||
| "llm_provider": self._llm_provider, | ||
| "stall_timeout_s": self._stall_timeout_s, | ||
| "event_publisher": self._event_publisher, | ||
| "dry_run": self._dry_run, | ||
| "verbose": self._verbose, | ||
| "on_event": _bridge_event, | ||
| "debug": self._debug, | ||
| "output_logger": self._output_logger, | ||
| "fix_coordinator": self._fix_coordinator, | ||
| } | ||
| if self._stall_action is not None: | ||
| kwargs["stall_action"] = self._stall_action | ||
|
|
||
| agent = ReactAgent(**kwargs) | ||
| status = agent.run(task_id) | ||
| return self._map_status(status) | ||
|
|
||
| @staticmethod | ||
| def _map_status(status: object) -> AgentResult: | ||
| """Map AgentStatus enum to AgentResult.""" | ||
| from codeframe.core.agent import AgentStatus | ||
|
|
||
| status_map = { | ||
| AgentStatus.COMPLETED: "completed", | ||
| AgentStatus.FAILED: "failed", | ||
| AgentStatus.BLOCKED: "blocked", | ||
| } | ||
| result_status = status_map.get(status, "failed") # type: ignore[arg-type] | ||
| return AgentResult( | ||
| status=result_status, | ||
| output=f"ReactAgent finished with status: {status.value}", # type: ignore[union-attr] | ||
| ) | ||
|
|
||
|
|
||
| class BuiltinPlanAdapter: | ||
| """Wraps the existing plan-based Agent behind the AgentAdapter interface.""" | ||
|
|
||
| def __init__( | ||
| self, | ||
| workspace: Workspace, | ||
| llm_provider: LLMProvider, | ||
| *, | ||
| dry_run: bool = False, | ||
| verbose: bool = False, | ||
| debug: bool = False, | ||
| output_logger: Optional[RunOutputLogger] = None, | ||
| fix_coordinator: Optional[GlobalFixCoordinator] = None, | ||
| event_publisher: Optional[EventPublisher] = None, | ||
| ) -> None: | ||
| self._workspace = workspace | ||
| self._llm_provider = llm_provider | ||
| self._dry_run = dry_run | ||
| self._verbose = verbose | ||
| self._debug = debug | ||
| self._output_logger = output_logger | ||
| self._fix_coordinator = fix_coordinator | ||
| self._event_publisher = event_publisher | ||
|
|
||
| @property | ||
| def name(self) -> str: | ||
| return "plan" | ||
|
|
||
| def run( | ||
| self, | ||
| task_id: str, | ||
| prompt: str, | ||
| workspace_path: Path, | ||
| on_event: Callable[[AgentEvent], None] | None = None, | ||
| ) -> AgentResult: | ||
| """Run the plan-based Agent and map its AgentState to AgentResult.""" | ||
| from codeframe.core.agent import Agent | ||
|
|
||
| def _bridge_event(event_type: str, data: dict) -> None: | ||
| if on_event: | ||
| on_event(AgentEvent(type=event_type, data=data)) | ||
|
|
||
| agent = Agent( | ||
| workspace=self._workspace, | ||
| llm_provider=self._llm_provider, | ||
| dry_run=self._dry_run, | ||
| on_event=_bridge_event, | ||
| debug=self._debug, | ||
| verbose=self._verbose, | ||
| fix_coordinator=self._fix_coordinator, | ||
| output_logger=self._output_logger, | ||
| event_publisher=self._event_publisher, | ||
| ) | ||
| state = agent.run(task_id) | ||
| return self._map_state(state) | ||
|
|
||
| @staticmethod | ||
| def _map_state(state: object) -> AgentResult: | ||
| """Map AgentState dataclass to AgentResult.""" | ||
| from codeframe.core.agent import AgentStatus | ||
|
|
||
| status_map = { | ||
| AgentStatus.COMPLETED: "completed", | ||
| AgentStatus.FAILED: "failed", | ||
| AgentStatus.BLOCKED: "blocked", | ||
| } | ||
| result_status = status_map.get(state.status, "failed") # type: ignore[union-attr] | ||
|
|
||
| blocker_question = None | ||
| if state.status == AgentStatus.BLOCKED: # type: ignore[union-attr] | ||
| blocker = getattr(state, "blocker", None) | ||
| if blocker: | ||
| blocker_question = getattr(blocker, "question", None) or getattr( | ||
| blocker, "reason", None | ||
| ) | ||
|
|
||
| error = None | ||
| if state.status == AgentStatus.FAILED: # type: ignore[union-attr] | ||
| gate_results = getattr(state, "gate_results", None) or [] | ||
| error_parts: list[str] = [] | ||
| for gr in gate_results: | ||
| for check in getattr(gr, "checks", []): | ||
| output = getattr(check, "output", None) | ||
| if output: | ||
| error_parts.append(output) | ||
| if error_parts: | ||
| error = "\n".join(error_parts[:3]) | ||
|
|
||
| return AgentResult( | ||
| status=result_status, | ||
| output=f"PlanAgent finished with status: {state.status.value}", # type: ignore[union-attr] | ||
| blocker_question=blocker_question, | ||
| error=error, | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate
enginebefore deciding which credentials to require.An unknown engine currently falls through
is_external_engine()as “builtin”, sowork start --engine typoandwork batch run --engine typocan fail with anANTHROPIC_API_KEYerror instead of the real invalid-engine error whenever the key is unset. Resolve or validate the engine first, then branch on external vs builtin.Suggested fix
Also applies to: 2972-2977
🤖 Prompt for AI Agents