Skip to content

[Phase 4] Engine Registry and Runtime Selection #414

Description

@frankbria

Summary

Create an engine registry that maps engine names to AgentAdapter implementations and wire it into the runtime's execute_agent() function, replacing the current hardcoded if engine == "react" / elif engine == "plan" branching.

Parent issue: #408

Scope

New module: core/engine_registry.py

  1. EngineRegistry class:
class EngineRegistry:
    _engines: dict[str, type[AgentAdapter]] = {}
    
    @classmethod
    def register(cls, name: str, adapter_class: type[AgentAdapter]):
        cls._engines[name] = adapter_class
    
    @classmethod
    def get(cls, name: str) -> AgentAdapter:
        if name not in cls._engines:
            raise ValueError(f"Unknown engine '{name}'. Available: {cls.available()}")
        return cls._engines[name]()
    
    @classmethod
    def available(cls) -> list[str]:
        return sorted(cls._engines.keys())
    
    @classmethod
    def check_requirements(cls, name: str) -> dict[str, bool]:
        """Check if engine's requirements are met (API keys, binaries)."""
        ...
  1. Built-in registrations:

  2. BuiltInReactAdapter — wraps existing ReactAgent to satisfy AgentAdapter protocol:

    • Takes AgentContext, builds the 3-layer system prompt internally
    • Returns AgentResult from AgentStatus
    • This keeps ReactAgent working exactly as before

Changes to core/runtime.py

  1. Refactor execute_agent():
    • Replace if engine == "react" branching with registry lookup
    • Use ContextPackager to build AgentContext
    • Call adapter.execute()
    • Map AgentResult back to AgentState for runtime state management
    • Keep verification gate logic outside the adapter (CodeFrame owns gates)

Changes to cli/app.py

  1. Update --engine flag:
    • Accept any registered engine name
    • cf work start <id> --execute --engine claude-code
    • Add cf engines list command showing available engines and their requirements
    • Add cf engines check <name> to validate requirements (API keys, binaries)

Changes to AGENTS.md / CODEFRAME.md support

  1. Default engine configurable per-workspace:
    engine: claude-code  # or: built-in, codex, aider, plan

Acceptance Criteria

  • EngineRegistry maps engine names to adapter classes
  • BuiltInReactAdapter wraps ReactAgent (no behavior change)
  • execute_agent() uses registry instead of hardcoded branching
  • --engine flag accepts any registered engine
  • cf engines list shows available engines with requirement status
  • Default engine configurable via workspace config
  • Existing --engine react and --engine plan still work (mapped to built-in adapters)
  • All existing tests pass (backward compatible)

Dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    architectureSystem architecture and design patternsenhancementNew feature or requestphase-4.1Phase 4.1: Agent Adapter Foundation (protocol, registry, verification wrapper)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions