Skip to content

feat(agents): SDK Migration Phase 3 - Agent Pattern Migration - #34

Merged
frankbria merged 3 commits into
mainfrom
feature/sdk-migration-phase-3
Dec 2, 2025
Merged

feat(agents): SDK Migration Phase 3 - Agent Pattern Migration#34
frankbria merged 3 commits into
mainfrom
feature/sdk-migration-phase-3

Conversation

@frankbria

@frankbria frankbria commented Dec 2, 2025

Copy link
Copy Markdown
Owner

Summary

Phase 3 of the Claude Agent SDK Migration implements the hybrid agent pattern that bridges YAML-defined agents with the SDK's execution model while preserving CodeFRAME's unique features.

New Components

  • SubagentGenerator (codeframe/agents/subagent_generator.py): Generates SDK-compatible markdown from YAML agent definitions with tool mapping and maturity-specific capabilities
  • HybridWorkerAgent (codeframe/agents/hybrid_worker.py): SDK execution with CodeFRAME coordination, context management, and token tracking
  • Generated Subagents (.claude/agents/*.md): 7 SDK-compatible markdown files for backend, frontend, test, and review agents

Updated Components

  • AgentPoolManager: Added use_sdk feature flag, hybrid agent creation, per-agent SDK override
  • LeadAgent: Added SDK coordination with session ID tracking and persistence

Key Features

  • ✅ Preserves CodeFRAME's maturity levels (D1-D4 Situational Leadership)
  • ✅ Maintains tiered context management (HOT/WARM/COLD)
  • ✅ Integrates with existing quality gates
  • ✅ Backward compatible (use_sdk=False by default)
  • ✅ Session ID tracking for conversation resume capability

Test plan

  • SubagentGenerator tests (37 tests) - validates YAML → markdown conversion
  • HybridWorkerAgent tests (33 tests) - validates SDK execution integration
  • AgentPoolManager SDK tests (29 tests) - validates hybrid agent creation
  • LeadAgent SDK coordination tests (10 tests) - validates session tracking
  • All 109 new tests passing
  • Ruff linting clean
  • Existing tests unaffected

Files Changed

New Files (11):

  • codeframe/agents/subagent_generator.py (380+ lines)
  • codeframe/agents/hybrid_worker.py (420 lines)
  • tests/agents/test_subagent_generator.py
  • tests/agents/test_hybrid_worker.py
  • .claude/agents/backend-worker.md
  • .claude/agents/backend-architect.md
  • .claude/agents/frontend-worker.md
  • .claude/agents/frontend-specialist.md
  • .claude/agents/test-worker.md
  • .claude/agents/test-engineer.md
  • .claude/agents/code-reviewer.md

Modified Files (6):

  • codeframe/agents/agent_pool_manager.py (+180 lines)
  • codeframe/agents/lead_agent.py (+55 lines)
  • tests/agents/test_agent_pool_manager.py (+141 lines)
  • tests/agents/test_lead_agent_session.py (+183 lines)
  • pytest.ini (+3 lines - asyncio config)
  • claudedocs/SESSION.md (session documentation)

Related Issues

Part of SDK Migration Implementation Plan (Phase 3 of 5)

Summary by CodeRabbit

  • New Features

    • SDK-backed hybrid agent execution with per-agent hybrid/session tracking; subagent generator to produce SDK-compatible agent specs; lead agent and pool manager updated to support SDK workflows.
  • Tests

    • Extensive test suites added for hybrid agents, pool manager, subagent generator, and lead-agent session handling; async test mode enabled.
  • Documentation

    • New agent role/spec documentation and Phase 3: Agent Pattern Migration session notes.

✏️ Tip: You can customize this high-level summary in your review settings.

Phase 3 implements the hybrid agent pattern that bridges YAML-defined agents
with the Claude Agent SDK's execution model, while preserving CodeFRAME's
unique features (maturity levels, project scoping, context management).

New Components:
- SubagentGenerator: Generates SDK-compatible markdown from YAML definitions
  - Tool mapping (file_operations -> Read/Write, test_runner -> Bash, etc.)
  - Maturity-specific capabilities (D1-D4)
  - Output to .claude/agents/ directory
  - 37 tests (100% pass)

- HybridWorkerAgent: SDK execution with CodeFRAME coordination
  - execute_task(): Context-aware SDK execution
  - execute_with_streaming(): Real-time UI updates
  - Token tracking via MetricsTracker
  - Session ID management for resume capability
  - 33 tests (100% pass)

Updated Components:
- AgentPoolManager: SDK mode support
  - use_sdk flag for SDK vs traditional mode
  - _create_hybrid_agent() for SDK agents
  - Per-agent SDK override capability
  - Pool status includes is_hybrid and session_id
  - 29 tests (100% pass)

- LeadAgent: SDK coordination
  - use_sdk and project_root parameters
  - _sdk_sessions tracking throughout execution
  - _get_sdk_sessions() for pool-wide session gathering
  - Session persistence for conversation resume
  - 10 tests (100% pass)

Generated Artifacts:
- .claude/agents/*.md: SDK-compatible subagent markdown files

Testing:
- 109 new tests total, all passing
- pytest-asyncio configuration added
- Ruff linting clean

Phase 3 Tasks Complete:
- Task 3.1: SubagentGenerator ✅
- Task 3.2: HybridWorkerAgent ✅
- Task 3.3: AgentPoolManager SDK support ✅
- Task 3.4: LeadAgent SDK coordination ✅
@coderabbitai

coderabbitai Bot commented Dec 2, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds SDK-backed hybrid agents and orchestration: new HybridWorkerAgent, SubagentGenerator, AgentPoolManager branching for SDK vs traditional agents, LeadAgent SDK session tracking and persistence, multiple agent-spec documents, async test support, and extensive tests for hybrid flows and generation.

Changes

Cohort / File(s) Summary
Agent spec docs
\.claude/agents/backend-architect.md, \.claude/agents/backend-worker.md, \.claude/agents/code-reviewer.md, \.claude/agents/frontend-specialist.md, \.claude/agents/frontend-worker.md, \.claude/agents/test-engineer.md, \.claude/agents/test-worker.md
Added seven agent specification documents (YAML-like frontmatter + role, capabilities, workflows, error-recovery and output formats).
Session docs
claudedocs/SESSION.md
Added Phase 3: Agent Pattern Migration notes (objectives, tasks, architecture decisions, execution plan, risks, deliverables).
Hybrid worker
codeframe/agents/hybrid_worker.py
New HybridWorkerAgent implementing SDK execution and streaming, HOT/WARM context handling, prompt construction, result summarization, changed-file extraction, token usage recording, session resume support, and Metrics tracking.
Agent pool manager
codeframe/agents/agent_pool_manager.py
AgentPoolManager extended with constructor args (use_sdk, model, cwd, codebase_index), per-call use_sdk override in create_agent, _create_hybrid_agent and _create_traditional_agent helpers, pool entries now include is_hybrid and session_id, async lifecycle broadcasting, and structured logging.
Lead agent
codeframe/agents/lead_agent.py
LeadAgent constructor adds use_sdk and project_root; internal _sdk_sessions tracking, _get_sdk_sessions helper, and session persistence now includes sdk_sessions.
Subagent generator
codeframe/agents/subagent_generator.py
New SubagentGenerator to convert YAML agent definitions into SDK-compatible markdown; public API for generate/list/get/reload; maturity config dataclass and YAML→SDK tool mapping.
Tests config
pytest.ini
Added asyncio_mode = auto for pytest-asyncio support.
AgentPoolManager tests
tests/agents/test_agent_pool_manager.py
Tests for SDK mode initialization, hybrid vs traditional creation, per-agent use_sdk override, and presence of is_hybrid/session_id in statuses (uses mocks).
HybridWorker tests
tests/agents/test_hybrid_worker.py
Extensive tests covering HybridWorkerAgent initialization, SDK execution, streaming, context management, token recording, prompt building, file extraction, session handling, and summarization.
LeadAgent session tests
tests/agents/test_lead_agent_session.py
Tests for LeadAgent SDK coordination: use_sdk/project_root propagation, _sdk_sessions behavior, and session persistence.
SubagentGenerator tests
tests/agents/test_subagent_generator.py
Tests for YAML definition loading, markdown generation, tool mapping, maturity handling, edge cases, and output validation.

Sequence Diagram(s)

sequenceDiagram
    participant LeadAgent
    participant AgentPoolManager
    participant HybridWorkerAgent
    participant SDKClient
    participant Database
    participant Context

    LeadAgent->>AgentPoolManager: create_agent(agent_type, use_sdk=True)
    AgentPoolManager->>AgentPoolManager: decide hybrid vs traditional
    alt hybrid
        AgentPoolManager->>HybridWorkerAgent: instantiate with sdk_client & session_id
        AgentPoolManager->>AgentPoolManager: pool[id] = {is_hybrid: true, session_id}
    else traditional
        AgentPoolManager->>AgentPoolManager: instantiate traditional worker
    end

    LeadAgent->>HybridWorkerAgent: execute_task(task)
    HybridWorkerAgent->>Context: load HOT/WARM context
    Context-->>HybridWorkerAgent: context items
    HybridWorkerAgent->>HybridWorkerAgent: build prompt
    HybridWorkerAgent->>SDKClient: call SDK with prompt
    SDKClient-->>HybridWorkerAgent: response (content, usage, session_id)
    HybridWorkerAgent->>HybridWorkerAgent: extract changed files, summarize
    HybridWorkerAgent->>Database: record token usage & persist result
    HybridWorkerAgent->>Context: save result/context items
    HybridWorkerAgent-->>LeadAgent: result + session_id
    LeadAgent->>LeadAgent: update _sdk_sessions[agent_id] = session_id
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Review focus:
    • HybridWorkerAgent execution/streaming flow, prompt building, error handling, and token recording.
    • AgentPoolManager branching logic and per-call use_sdk overrides.
    • LeadAgent SDK session collection, persistence, and resume behavior.
    • SubagentGenerator tool mapping and generated markdown correctness.
    • Test suites: mocks, async behavior, and alignment with real SDK/db interfaces.

Possibly related PRs

Poem

🐰 I hopped a path from prompt to stream,

SDK seeds in every dream.
Context warm, sessions snug and neat,
Agents hum and files repeat.
Tokens counted — hop, deploy, repeat!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(agents): SDK Migration Phase 3 - Agent Pattern Migration' directly and clearly describes the main change: introducing Phase 3 of the SDK migration with the hybrid agent pattern. It is specific, concise, and aligns with the primary objective of the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 99.27% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/sdk-migration-phase-3

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@claude

claude Bot commented Dec 2, 2025

Copy link
Copy Markdown

Code Review - PR #34: SDK Migration Phase 3 - Agent Pattern Migration

Overview

This PR implements Phase 3 of the Claude Agent SDK migration, introducing a hybrid agent pattern that bridges YAML-defined agents with the SDK's execution model. The implementation is well-structured and comprehensive, with 109 new tests and strong documentation.


✅ Strengths

1. Excellent Architecture & Design

  • Hybrid approach is pragmatic - preserves existing YAML configurations while enabling SDK execution
  • Clean separation of concerns between SubagentGenerator, HybridWorkerAgent, and coordination layers
  • Backward compatible with feature flag (use_sdk=False by default)
  • Preserves all CodeFRAME-specific features (maturity levels, context tiers, quality gates)

2. Comprehensive Testing

  • 109 new tests across all components (37 + 33 + 29 + 10)
  • Tests cover initialization, execution, error handling, and edge cases
  • Good use of mocks and fixtures for async testing
  • Integration with existing test suite verified

3. Strong Documentation

  • Detailed docstrings with usage examples
  • Clear comments explaining complex logic
  • Updated SESSION.md with comprehensive session summary
  • Well-documented PR description with test plan

4. Code Quality

  • Type hints throughout
  • Proper error handling and logging
  • Follows project conventions (PEP 8, SOLID principles)
  • Clean, readable code structure

⚠️ Issues Found

CRITICAL: Debug Print Statements in Production Code

Severity: High
Impact: Performance degradation, log pollution, unprofessional output

Multiple production files contain print() statements that should be replaced with proper logging:

  1. codeframe/agents/agent_pool_manager.py (lines 138-487):

    • 15+ debug print statements like print("🏭 DEBUG: ...")
    • Should use logger.debug() instead
  2. codeframe/agents/lead_agent.py (lines 1063-1773):

    • 50+ debug print statements like print("🔄 DEBUG: ...")
    • Mix of legitimate UI messages and debug output
    • Should distinguish between user-facing messages and debug logs

Recommendation:

# ❌ Bad - leaves debug output in production
print("🏭 DEBUG: create_agent called...")

# ✅ Good - proper logging
logger.debug("create_agent called with agent_type=%s, use_sdk=%s", agent_type, create_hybrid)

# ✅ Good - user-facing messages (keep print for CLI output)
print("\n📋 Restoring session...\n")  # This is fine - intended for user

MEDIUM: Hardcoded Model Name

File: codeframe/agents/hybrid_worker.py:333
Issue: Model name is hardcoded with a TODO comment

model_name="claude-sonnet-4-20250514",  # TODO: Get from SDK client

Recommendation:

# Pass model from sdk_client
model_name=self.sdk_client.model or "claude-sonnet-4-20250514",

LOW: Documentation-Only Print Statement

File: codeframe/agents/subagent_generator.py:40-43
Issue: Print statements in usage example docstring

# Generate specific agent
output_path = generator.generate_agent("backend", maturity="D3")
print(f"Generated: {output_path}")  # ← This is in a docstring, so it's fine

# List available agent types
print(generator.list_available_types())  # ← Also in docstring

Status: Not a real issue - these are in documentation examples


🔍 Code Quality Observations

Positive Patterns

  1. ✅ Excellent async/await usage throughout
  2. ✅ Proper context manager usage (locks, temp directories)
  3. ✅ Good separation between traditional and hybrid agent creation
  4. ✅ Token tracking integrated correctly
  5. ✅ Session ID management well-implemented
  6. ✅ Error recovery patterns consistent

Potential Improvements

1. Tool Mapping Coverage (subagent_generator.py:56-94)

Consider adding validation for unknown tools:

def _map_tools_to_sdk(self, yaml_tools: List[str]) -> List[str]:
    sdk_tools: set[str] = set()
    unknown_tools = []
    
    for tool in yaml_tools:
        if tool in YAML_TO_SDK_TOOL_MAPPING:
            sdk_tools.update(YAML_TO_SDK_TOOL_MAPPING[tool])
        else:
            unknown_tools.append(tool)
            logger.warning(f"Unknown tool '{tool}' - not mapped to SDK")
    
    if unknown_tools and len(unknown_tools) == len(yaml_tools):
        raise ValueError(f"No valid tools mapped for: {unknown_tools}")
    
    # ... rest of method

2. File Path Extraction Regex (hybrid_worker.py:284-309)

Current regex patterns might miss some file paths. Consider adding:

# Add pattern for diff-style paths
r'^[+-]{3}\s+([ab]/)?([^\s]+)$',  # Matches +++ b/path/to/file

3. Error Handling in Token Recording

Good use of try/except to prevent task failure, but consider tracking these failures:

except Exception as e:
    logger.warning(f"Failed to record token usage: {e}")
    # Optional: increment a metrics failure counter
    self.token_recording_failures = getattr(self, 'token_recording_failures', 0) + 1

🔒 Security Review

No Critical Security Issues Found

Good Practices:

  • API keys loaded from environment variables (not hardcoded)
  • File paths validated before writing (via Path objects)
  • No SQL injection risks (using parameterized queries)
  • No XSS vulnerabilities in generated markdown
  • YAML parsing uses safe_load() (prevents code execution)

Recommendation:

Consider adding path traversal protection when writing generated files:

def _validate_output_path(self, path: Path) -> None:
    """Ensure output path doesn't escape output directory."""
    try:
        path.resolve().relative_to(self.output_dir.resolve())
    except ValueError:
        raise ValueError(f"Invalid output path: {path} escapes output directory")

📊 Performance Considerations

Good:

  • ✅ Efficient context loading (limits WARM tier to 20 items)
  • ✅ Proper use of async/await for I/O operations
  • ✅ Caching of raw YAML definitions
  • ✅ Thread-safe pool operations with RLock

Potential Optimization:

For large codebases, consider caching generated markdown:

# In SubagentGenerator
self._markdown_cache: Dict[Tuple[str, str], str] = {}  # (agent_name, maturity) -> markdown

def generate_agent(self, agent_name: str, maturity: str = "D2") -> Path:
    cache_key = (agent_name, maturity)
    if cache_key in self._markdown_cache:
        content = self._markdown_cache[cache_key]
    else:
        content = self._build_markdown(raw_def, maturity)
        self._markdown_cache[cache_key] = content
    # ... write to file

🧪 Test Coverage Assessment

Coverage Analysis:

  • Initialization tests: Complete
  • Execution paths: Covered (success, failure, streaming)
  • Edge cases: Good coverage (empty context, missing definitions)
  • Integration: Pool manager + LeadAgent coordination tested
  • ⚠️ Missing: E2E test with actual SDK execution (mock-only tests)

Recommendation:

Add at least one integration test that uses real SDK client (if available in test env):

@pytest.mark.skipif(not os.getenv("ANTHROPIC_API_KEY"), reason="No API key")
@pytest.mark.integration
async def test_hybrid_agent_real_sdk_execution():
    """Test with real SDK client (integration test)."""
    # ... test actual SDK execution

📋 Recommended Changes Before Merge

Must Fix (Blocking):

  1. Remove debug print statements from agent_pool_manager.py and lead_agent.py
    • Replace with logger.debug() calls
    • Keep user-facing print() statements for CLI output
    • Estimated effort: 15 minutes

Should Fix (Non-blocking):

  1. Resolve TODO at hybrid_worker.py:333 - get model from SDK client
  2. Add path validation in SubagentGenerator to prevent directory traversal
  3. Consider adding integration test with real SDK client (optional)

Nice to Have:

  1. Add markdown cache for performance optimization
  2. Improve file path extraction regex coverage
  3. Track token recording failures for observability

✅ Final Recommendation

Status:Approve with minor changes required

This is a well-implemented PR that successfully achieves Phase 3 goals. The architecture is sound, testing is comprehensive, and the code follows project standards.

Required before merge:

  • Remove debug print statements (15 min fix)

After fixing above:

  • ✅ Ready to merge
  • No security concerns
  • Performance is acceptable
  • Test coverage is strong
  • Documentation is excellent

💡 Future Considerations

  1. Phase 4 (Workflow Migration): This hybrid pattern provides a solid foundation
  2. Observability: Consider adding SDK execution metrics to dashboard
  3. Error Recovery: Current implementation is good, but could benefit from retry strategies in SDK client wrapper
  4. Cost Tracking: Token usage tracking is implemented - consider adding budget alerts

Great work on this phase! The hybrid approach is well-designed and sets up Phase 4 for success. 🎉


Review completed by Claude Code on 2025-12-02

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
codeframe/agents/lead_agent.py (1)

1063-1091: Remove debug print statements before merge.

There are extensive debug print statements throughout the coordination loop that should be removed or converted to proper logging. These will clutter production output.

-        print(f"\n🚀 DEBUG: start_multi_agent_execution ENTERED (timeout={timeout})")
         try:
-            print("🚀 DEBUG: Creating asyncio.timeout context...")
             async with asyncio.timeout(timeout):
-                print("🚀 DEBUG: Inside timeout context, calling _execute_coordination_loop...")
                 return await self._execute_coordination_loop(max_retries, max_concurrent)

Similar debug prints appear throughout _execute_coordination_loop (lines 1079-1282) and _all_tasks_complete (lines 1540-1572).

🧹 Nitpick comments (15)
codeframe/agents/hybrid_worker.py (1)

311-341: Address the hardcoded model name.

The token tracking implementation is solid with proper error handling that doesn't fail task execution. However, line 333 hardcodes the model name with a TODO comment.

Apply this diff to use the model name from the SDK client:

-                model_name="claude-sonnet-4-20250514",  # TODO: Get from SDK client
+                model_name=getattr(self.sdk_client, "model", "claude-sonnet-4-20250514"),

This ensures the recorded model matches the actual SDK client configuration while providing a safe fallback.

claudedocs/SESSION.md (3)

350-353: Fix markdown formatting for table.

The table on line 353 should be surrounded by blank lines per markdown conventions (markdownlint MD058).

Add blank lines before and after the table:

 ### Task Status
+
 | Task | Status | Notes |
 |------|--------|-------|
 | 3.1 Subagent Generator | ✅ Complete | 37 tests, 8 agents generated |
+

437-437: Fix markdown formatting for Phase Overview table.

The table on line 437 should be surrounded by blank lines per markdown conventions (markdownlint MD058).

Add blank lines before and after the table:

 ### Phase Overview
+
 | Phase | Goal | Agents/Skills | Complexity | Risk |
 |-------|------|---------------|------------|------|
 | **1** | Analysis & Planning | `Explore`, `claude-agent-sdk` skill | 4-6 hrs | Low |
+

456-456: Fix markdown formatting for Key Deliverables table.

The table on line 456 should be surrounded by blank lines per markdown conventions (markdownlint MD058).

Add blank lines before and after the table:

 ### Key Deliverables
+
 | Task | File | Lines |
 |------|------|-------|
 | 3.1 | `codeframe/agents/subagent_generator.py` | ~150 |
+
tests/agents/test_agent_pool_manager.py (1)

395-421: Verify session_id assertion completeness.

The test at line 411-421 verifies session_id is present in status but doesn't assert its expected value. Consider adding an explicit assertion for the expected value to ensure the field contains the correct data.

         assert agent_id in status
         assert "session_id" in status[agent_id]
+        assert status[agent_id]["session_id"] is None  # Traditional agents have no session_id
.claude/agents/backend-architect.md (1)

1-45: Consider adding output format section for consistency.

This agent specification is functional but less comprehensive than backend-worker.md. For consistency across agent definitions, consider adding:

  1. An output format section (JSON structure like other agents)
  2. Context awareness guidelines
  3. Integration points section

The tools list intentionally excludes Write, which makes sense for an architecture review/advisory role.

tests/agents/test_subagent_generator.py (1)

538-576: Consider skipping integration test by default.

The integration test at line 541-565 depends on the existence of a real definitions directory. While it properly uses pytest.skip when the directory doesn't exist, consider marking it with @pytest.mark.integration to allow selective test execution.

+    @pytest.mark.integration
     def test_with_real_definitions_dir(self, temp_output_dir):
tests/agents/test_hybrid_worker.py (1)

415-429: Consider consolidating redundant session tests.

Lines 415-420 set session_id and verify the attribute in a sync test, while lines 422-429 do the same verification in an async test. The sync test (415-420) doesn't provide additional value since it just checks attribute assignment. Consider removing it or consolidating into the async test.

codeframe/agents/agent_pool_manager.py (4)

138-142: Remove or convert debug print statements to logging.

Multiple print() statements throughout this file (Lines 138-142, 151, 154, 163, 196-210, 448-487) appear to be development artifacts. These should either be removed before merging or converted to logger.debug() for consistency with the existing logging pattern.

-        print(
-            f"\n🏭 DEBUG: create_agent called with agent_type={agent_type}, use_sdk={create_hybrid}"
-        )
+        logger.debug(
+            f"create_agent called with agent_type={agent_type}, use_sdk={create_hybrid}"
+        )
         with self.lock:
-            print("🏭 DEBUG: Acquired lock")
+            logger.debug("Acquired lock")

434-448: Add return type annotation for consistency.

The method lacks a return type annotation. Consider adding a union type or base class return type for better type safety.

-    def _create_traditional_agent(self, agent_id: str, agent_type: str):
+    def _create_traditional_agent(
+        self, agent_id: str, agent_type: str
+    ) -> BackendWorkerAgent | FrontendWorkerAgent | TestWorkerAgent | ReviewWorkerAgent:

450-488: Consider unifying agent type normalization.

_create_hybrid_agent uses agent_type.split("-")[0] (Line 396) while this method uses explicit compound checks. This inconsistency could lead to maintenance burden. Consider extracting a shared normalization helper.

# At class level or module level
def _normalize_agent_type(agent_type: str) -> str:
    """Normalize agent type to base form (e.g., 'backend-worker' -> 'backend')."""
    return agent_type.split("-")[0]

419-432: Hardcoded maturity level may limit flexibility.

The AgentMaturity.D2 default is reasonable, but consider making this configurable via create_agent() or pool initialization for workflows that need different maturity levels per agent. Based on learnings, the maturity levels D1-D4 are a key feature of the agent system.

codeframe/agents/subagent_generator.py (3)

372-372: Minor type annotation style inconsistency.

Line 372 uses set[str] (Python 3.9+ builtin syntax) while the rest of the file uses List[str], Dict[str, Any] from the typing module. Both are valid in Python 3.11+, but consistency is preferred.

-        sdk_tools: set[str] = set()
+        sdk_tools: Set[str] = set()

And add Set to the typing imports on Line 51:

-from typing import Dict, List, Optional, Any
+from typing import Any, Dict, List, Optional, Set

162-179: Good error isolation, consider exposing load failures.

The error handling correctly isolates individual file failures. For observability, consider tracking failed loads and exposing them via a property or return value, so callers can detect partial load scenarios.


425-428: Consider thread safety for reload operation.

If SubagentGenerator may be accessed concurrently, reload_definitions() could cause race conditions with other methods reading _raw_definitions. Consider adding a lock if concurrent access is expected.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ad818cf and a068c38.

📒 Files selected for processing (17)
  • .claude/agents/backend-architect.md (1 hunks)
  • .claude/agents/backend-worker.md (1 hunks)
  • .claude/agents/code-reviewer.md (1 hunks)
  • .claude/agents/frontend-specialist.md (1 hunks)
  • .claude/agents/frontend-worker.md (1 hunks)
  • .claude/agents/test-engineer.md (1 hunks)
  • .claude/agents/test-worker.md (1 hunks)
  • claudedocs/SESSION.md (1 hunks)
  • codeframe/agents/agent_pool_manager.py (9 hunks)
  • codeframe/agents/hybrid_worker.py (1 hunks)
  • codeframe/agents/lead_agent.py (6 hunks)
  • codeframe/agents/subagent_generator.py (1 hunks)
  • pytest.ini (1 hunks)
  • tests/agents/test_agent_pool_manager.py (1 hunks)
  • tests/agents/test_hybrid_worker.py (1 hunks)
  • tests/agents/test_lead_agent_session.py (1 hunks)
  • tests/agents/test_subagent_generator.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
codeframe/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

codeframe/**/*.py: Use Python 3.11+ with async/await pattern, type hints, and comprehensive tests for backend code
Use ruff for linting Python code
Use async/await pattern for promises in Python async code
Use FastAPI for backend API implementation
Use SQLite with async support (aiosqlite) for database operations
Use WebSocket for real-time updates between backend and frontend
API endpoints should accept project_id query parameter for multi-project support

Files:

  • codeframe/agents/lead_agent.py
  • codeframe/agents/agent_pool_manager.py
  • codeframe/agents/subagent_generator.py
  • codeframe/agents/hybrid_worker.py
tests/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

tests/**/*.py: Run all tests with pytest
Maintain 88%+ test coverage for Sprint 10 components and 100% pass rate

Files:

  • tests/agents/test_agent_pool_manager.py
  • tests/agents/test_subagent_generator.py
  • tests/agents/test_lead_agent_session.py
  • tests/agents/test_hybrid_worker.py
**/*.md

📄 CodeRabbit inference engine (AGENTS.md)

Documentation files must be sized to fit in a single agent context window (spec.md ~200-400 lines, plan.md ~300-600 lines, tasks.md ~400-800 lines)

Files:

  • claudedocs/SESSION.md
🧠 Learnings (10)
📓 Common learnings
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: docs/CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:37.203Z
Learning: Implement Lead Agent for orchestration and Worker Agents for specialization (Backend, Frontend, Test, Review) with maturity levels D1-D4
📚 Learning: 2025-11-25T19:08:20.036Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:20.036Z
Learning: Applies to tests/**/*.py : Run all tests with pytest

Applied to files:

  • pytest.ini
📚 Learning: 2025-11-25T19:08:54.154Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T19:08:54.154Z
Learning: Applies to {README.md,CODEFRAME_SPEC.md,CHANGELOG.md,SPRINTS.md,CLAUDE.md,AGENTS.md,TESTING.md,CONTRIBUTING.md} : Root-level documentation must include: README.md (project intro), CODEFRAME_SPEC.md (architecture, ~800 lines), CHANGELOG.md (user-facing changes), SPRINTS.md (timeline index), CLAUDE.md (coding standards), AGENTS.md (navigation guide), TESTING.md (test standards), and CONTRIBUTING.md (contribution guidelines)

Applied to files:

  • .claude/agents/backend-architect.md
  • .claude/agents/backend-worker.md
  • .claude/agents/code-reviewer.md
  • .claude/agents/frontend-worker.md
  • .claude/agents/frontend-specialist.md
  • .claude/agents/test-engineer.md
  • .claude/agents/test-worker.md
📚 Learning: 2025-11-25T19:08:37.203Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: docs/CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:37.203Z
Learning: Implement Lead Agent for orchestration and Worker Agents for specialization (Backend, Frontend, Test, Review) with maturity levels D1-D4

Applied to files:

  • .claude/agents/backend-architect.md
  • .claude/agents/backend-worker.md
  • .claude/agents/frontend-worker.md
  • codeframe/agents/lead_agent.py
  • .claude/agents/test-worker.md
  • tests/agents/test_lead_agent_session.py
  • claudedocs/SESSION.md
📚 Learning: 2025-11-25T19:08:20.036Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:20.036Z
Learning: Applies to tests/test_*worker_agent.py : Implement Worker Agent tests for async patterns

Applied to files:

  • .claude/agents/backend-worker.md
  • .claude/agents/test-worker.md
  • tests/agents/test_agent_pool_manager.py
  • tests/agents/test_lead_agent_session.py
  • tests/agents/test_hybrid_worker.py
📚 Learning: 2025-11-25T19:08:20.036Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:20.036Z
Learning: Applies to codeframe/**/*.py : Use Python 3.11+ with async/await pattern, type hints, and comprehensive tests for backend code

Applied to files:

  • .claude/agents/backend-worker.md
📚 Learning: 2025-11-25T19:08:20.036Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:20.036Z
Learning: Applies to codeframe/agents/worker_agent.py : Block task completion when quality gates fail (test failures, type errors, coverage <85%, critical review issues)

Applied to files:

  • .claude/agents/backend-worker.md
  • .claude/agents/test-worker.md
  • tests/agents/test_hybrid_worker.py
📚 Learning: 2025-11-25T19:08:20.036Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:20.036Z
Learning: Applies to web-ui/src/**/*.{ts,tsx} : Use TypeScript 5.3+ with React, strict mode, and maintain 85%+ test coverage for frontend code

Applied to files:

  • .claude/agents/frontend-worker.md
  • .claude/agents/frontend-specialist.md
📚 Learning: 2025-11-25T19:08:20.036Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:20.036Z
Learning: Applies to codeframe/agents/worker_agent.py : Each agent maintains independent context scoped by (project_id, agent_id) tuple

Applied to files:

  • codeframe/agents/lead_agent.py
  • codeframe/agents/agent_pool_manager.py
  • codeframe/agents/hybrid_worker.py
📚 Learning: 2025-11-25T19:08:20.036Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:20.036Z
Learning: Applies to codeframe/lib/quality_gates.py : Implement quality gates as multi-stage pre-completion checks: tests → type → coverage → review

Applied to files:

  • tests/agents/test_hybrid_worker.py
🧬 Code graph analysis (3)
tests/agents/test_subagent_generator.py (1)
codeframe/agents/subagent_generator.py (8)
  • SubagentGenerator (106-428)
  • list_available_types (401-407)
  • get_raw_definition (409-423)
  • reload_definitions (425-428)
  • generate_agent (203-242)
  • generate_all (181-201)
  • _map_tools_to_sdk (363-385)
  • _get_maturity_config (339-361)
tests/agents/test_lead_agent_session.py (3)
codeframe/agents/lead_agent.py (3)
  • LeadAgent (27-1835)
  • _get_sdk_sessions (1810-1835)
  • on_session_end (1783-1808)
codeframe/agents/agent_pool_manager.py (1)
  • get_agent_status (302-323)
codeframe/core/session_manager.py (2)
  • SessionManager (9-91)
  • load_session (69-83)
tests/agents/test_hybrid_worker.py (3)
codeframe/core/models.py (1)
  • ContextItemType (285-292)
codeframe/agents/worker_agent.py (3)
  • WorkerAgent (7-442)
  • load_context (163-197)
  • save_context_item (131-161)
codeframe/lib/metrics_tracker.py (1)
  • record_token_usage (130-207)
🪛 markdownlint-cli2 (0.18.1)
.claude/agents/test-worker.md

145-145: Strong style
Expected: underscore; Actual: asterisk

(MD050, strong-style)


145-145: Strong style
Expected: underscore; Actual: asterisk

(MD050, strong-style)


146-146: Strong style
Expected: underscore; Actual: asterisk

(MD050, strong-style)


146-146: Strong style
Expected: underscore; Actual: asterisk

(MD050, strong-style)


147-147: Strong style
Expected: underscore; Actual: asterisk

(MD050, strong-style)


147-147: Strong style
Expected: underscore; Actual: asterisk

(MD050, strong-style)


148-148: Strong style
Expected: underscore; Actual: asterisk

(MD050, strong-style)


148-148: Strong style
Expected: underscore; Actual: asterisk

(MD050, strong-style)


149-149: Strong style
Expected: underscore; Actual: asterisk

(MD050, strong-style)


149-149: Strong style
Expected: underscore; Actual: asterisk

(MD050, strong-style)


150-150: Strong style
Expected: underscore; Actual: asterisk

(MD050, strong-style)


150-150: Strong style
Expected: underscore; Actual: asterisk

(MD050, strong-style)

claudedocs/SESSION.md

350-350: Multiple headings with the same content

(MD024, no-duplicate-heading)


353-353: Tables should be surrounded by blank lines

(MD058, blanks-around-tables)


437-437: Tables should be surrounded by blank lines

(MD058, blanks-around-tables)


456-456: Tables should be surrounded by blank lines

(MD058, blanks-around-tables)

🔇 Additional comments (35)
pytest.ini (1)

15-16: LGTM! Proper asyncio configuration for Phase 3 async tests.

The asyncio_mode = auto configuration correctly enables pytest-asyncio to automatically detect and execute async test functions introduced in the new test suites (test_hybrid_worker.py, test_lead_agent_session.py, test_subagent_generator.py).

.claude/agents/code-reviewer.md (1)

1-54: LGTM! Comprehensive code review specialist documentation.

The documentation provides well-structured guidance covering security (OWASP Top 10), performance, architecture, best practices, and technical debt assessment. The D2 maturity level with 3 correction attempts and escalation strategy aligns with the Phase 3 agent pattern migration objectives.

.claude/agents/frontend-specialist.md (1)

1-45: LGTM! Frontend specialist documentation aligns with project standards.

The documentation properly covers modern frontend frameworks, accessibility (WCAG), performance optimization (Core Web Vitals), and TypeScript - all consistent with the coding guidelines requiring TypeScript 5.3+ with React and 85%+ frontend test coverage.

.claude/agents/frontend-worker.md (1)

1-109: LGTM! Comprehensive frontend worker agent documentation with excellent detail.

The documentation provides thorough guidance on React/TypeScript development with proper emphasis on:

  • Accessibility compliance (WCAG 2.1 AA with 4.5:1 contrast ratio)
  • Test-driven development with multiple test types (unit, integration, a11y, visual regression)
  • Modern React patterns (hooks, Context API, Suspense/lazy, React.memo)
  • Strict TypeScript with no implicit any
  • Integration with project infrastructure (database, codebase_index, Playwright, WebSocket)

The JSON output format and D2 maturity level with error recovery strategy align well with the Phase 3 hybrid agent architecture.

codeframe/agents/hybrid_worker.py (5)

82-124: LGTM! Proper initialization with comprehensive parameter support.

The constructor properly initializes all required components with appropriate type hints and defaults. The db: Any typing is acceptable here as it maintains compatibility with the parent WorkerAgent class. Session ID support enables conversation resume capability as intended for Phase 3.


126-208: LGTM! Well-structured async execution with proper error handling.

The execute_task method correctly implements the documented 6-step flow:

  1. Context loading (HOT + WARM tiers)
  2. Prompt building with context
  3. SDK execution with exception handling
  4. Result persistence to context
  5. Token usage tracking
  6. Flash save threshold check

Error handling properly catches exceptions and returns a consistent response structure. Token tracking and session ID propagation support the Phase 3 objectives.


210-309: LGTM! Well-designed helper methods with appropriate guardrails.

The helper methods implement sensible strategies:

  • _build_execution_prompt: Limits warm context to 20 items and truncates long items to 500 chars to prevent prompt bloat
  • _summarize_result: Extracts first paragraph or truncates to 500 chars for efficient context storage
  • _extract_changed_files: Uses regex patterns to extract file paths from various common formats

These implementations balance completeness with token efficiency as required for SDK integration.


402-416: LGTM! Clean session information getter.

The method provides comprehensive session metadata including agent identification, maturity level, SDK session ID, and definition name. This supports the Phase 3 session tracking and coordination requirements.


343-400: Inconsistency is intentional design, not a bug.

The different method signatures are correct by design:

  • send_message([{"role": "user", "content": prompt}]) accepts a conversation list to maintain interface compatibility with AnthropicProvider, but internally extracts just the last message's content (line 89 in sdk_client.py)
  • send_message_streaming(prompt) accepts a prompt string directly as a specialized streaming variant

Both methods ultimately call the SDK's query(prompt=..., options=self._options) function. No changes needed.

.claude/agents/test-engineer.md (1)

1-47: LGTM! Test engineer documentation aligns with project testing standards.

The documentation properly covers test automation with pytest, TDD methodology, and comprehensive test strategies (unit, integration, E2E, performance). The >80% coverage requirement aligns well with the coding guidelines requiring 88%+ test coverage for Sprint 10 components and 100% pass rate.

tests/agents/test_lead_agent_session.py (1)

335-509: LGTM! Comprehensive test coverage for SDK coordination features.

The new test class TestLeadAgentSDKCoordination provides excellent coverage of Phase 3 SDK integration:

Initialization tests (lines 356-373): Verify use_sdk and project_root parameters are properly stored

Session tracking tests (lines 375-465): Comprehensive coverage of _get_sdk_sessions including:

  • Empty state initialization
  • Gathering session IDs from hybrid agents
  • Filtering out traditional (non-hybrid) agents
  • Excluding agents without session_id
  • Graceful error handling

Persistence test (lines 466-489): Verifies end-to-end SDK session persistence via on_session_end

Integration test (lines 491-509): Confirms SDK parameters propagate to AgentPoolManager

All tests use appropriate mocking, clear assertions, and cover edge cases. This aligns with the coding guidelines requiring comprehensive test coverage.

.claude/agents/backend-worker.md (1)

1-80: LGTM! Well-structured agent specification.

The Backend Worker documentation comprehensively defines the agent's role, capabilities, output format, and integration points. The maturity level D2 and TDD workflow align with the project's agent architecture patterns. Based on learnings, this follows the expected Worker Agent specialization model.

.claude/agents/test-worker.md (1)

1-150: LGTM! Comprehensive test worker specification.

The Test Worker documentation provides excellent guidance on test pyramid strategy (70/20/10 split), TDD workflow, and framework-specific patterns for both Python/Pytest and JavaScript/Jest. The accessibility testing section and mocking strategy align with quality standards.

The static analysis warnings about markdown strong-style (asterisk vs underscore) can be safely ignored - the file uses consistent asterisk style throughout the Integration Points section.

tests/agents/test_agent_pool_manager.py (2)

281-326: LGTM! Good SDK mode initialization tests.

The test coverage for SDK mode initialization is comprehensive, verifying:

  • Default use_sdk=False behavior
  • SDK availability gating when use_sdk=True
  • Custom model and working directory propagation

328-392: LGTM! Thorough hybrid agent creation tests.

Good coverage of hybrid vs traditional agent creation paths:

  • Verifies SDK client and HybridWorkerAgent instantiation when SDK enabled
  • Confirms traditional BackendWorkerAgent creation when SDK disabled
  • Tests per-call use_sdk override allowing SDK agents in non-SDK pools

The mocking strategy correctly patches SDK_AVAILABLE, SDKClientWrapper, and HybridWorkerAgent.

tests/agents/test_subagent_generator.py (4)

1-123: LGTM! Well-designed test fixtures.

The test fixtures provide realistic YAML definitions that exercise key features:

  • Multi-line descriptions
  • Maturity progression with D1-D4 levels
  • Tool mappings
  • Error recovery and integration points

The use of tempfile.TemporaryDirectory ensures proper test isolation.


130-231: LGTM! Comprehensive definition loading and markdown generation tests.

Good coverage of:

  • YAML file loading on init and reload
  • Graceful handling of missing definitions directory
  • KeyError for unknown agent names
  • File creation, naming sanitization, and content validation

322-394: LGTM! Thorough tool mapping tests.

Excellent coverage of the YAML→SDK tool mapping logic:

  • Individual tool mappings (file_operations→Read/Write, codebase_index→Glob/Grep, etc.)
  • Deduplication of multiple tools mapping to same SDK tool
  • Alphabetical sorting
  • Warning logging for unknown tools
  • Default tools (Read, Glob) always included

448-530: LGTM! Good edge case coverage.

The edge case tests properly handle:

  • Empty capabilities and tools lists
  • Multiline description truncation in frontmatter
  • Special characters in agent names for filename sanitization
tests/agents/test_hybrid_worker.py (5)

23-89: LGTM! Well-designed test fixtures.

The mock fixtures properly set up:

  • Database with context methods returning appropriate defaults
  • SDK client with async send_message returning realistic response structure
  • Streaming mock using async generator pattern
  • Sample task with realistic fields

147-209: LGTM! Thorough task execution tests.

Good coverage of:

  • Successful execution with status/content/usage verification
  • Current task tracking during execution
  • Context loading from HOT/WARM tiers
  • Context saving with task result
  • File extraction from response content
  • Graceful SDK error handling returning failed status

The async patterns follow the coding guidelines for Python 3.11+ with async/await.


262-293: LGTM! Important resilience test.

The test at line 283-293 verifies that token tracking failures don't break task execution - this is critical for production resilience. The test correctly validates that a DB error during metrics recording still results in a completed status.


509-568: LGTM! Comprehensive integration test.

The full execution flow test properly validates:

  • Context loading (HOT/WARM tiers)
  • SDK client invocation
  • Session ID propagation in result
  • Metrics tracking and context manager integration

The test correctly uses multiple context managers for mocking.


243-255: The mock integration is correct as-is.

The test properly patches ContextManager at the module level, and since should_flash_save() (inherited from WorkerAgent) dynamically imports and instantiates ContextManager(db=self.db) on line 128 of worker_agent.py, the patched class is correctly intercepted. The mock_context_mgr_class.return_value = mock_context_mgr setup ensures the instantiation returns the mocked instance, and the assertion verifies the method is called as expected during execute_task().

codeframe/agents/lead_agent.py (5)

45-58: LGTM! Clean SDK parameter additions.

The new use_sdk and project_root parameters are well-documented with appropriate defaults. The docstring updates clearly explain their purpose for SDK execution mode.


80-99: LGTM! Proper SDK state initialization.

The SDK mode flag and session tracking are correctly initialized:

  • use_sdk stored for later reference
  • _project_root_override allows custom project root
  • _sdk_sessions dict for tracking hybrid agent sessions
  • cwd parameter correctly propagated to AgentPoolManager

1373-1377: LGTM! SDK session tracking during task execution.

Good implementation capturing session IDs from hybrid agents during task assignment. The defensive getattr with default None handles both hybrid and traditional agents safely.


1790-1806: LGTM! SDK sessions included in session state.

The session state correctly includes sdk_sessions for conversation resume capability. The log message helpfully indicates the session count.


1810-1835: LGTM! Robust SDK session gathering.

The _get_sdk_sessions method safely gathers session IDs:

  • Only includes hybrid agents with valid session IDs
  • Exception handling prevents failures from breaking session save
  • Clear logging of gathered session count
codeframe/agents/agent_pool_manager.py (2)

46-54: LGTM! Good defensive pattern for SDK availability.

The try/except pattern with a module-level flag provides clean fallback behavior when the SDK client isn't available.


97-100: LGTM! Good defensive API key handling.

The fallback to ANTHROPIC_API_KEY environment variable and the use_sdk and SDK_AVAILABLE guard ensure robust initialization.

codeframe/agents/subagent_generator.py (4)

56-94: LGTM! Comprehensive tool mapping.

The YAML_TO_SDK_TOOL_MAPPING provides clear abstraction between CodeFRAME's YAML tool names and SDK concrete tools, with sensible defaults for internal-only tools.


268-278: LGTM! Flexible error recovery parsing.

The dual-format handling (dict or list of dicts) provides good flexibility for different YAML definition structures while maintaining a sensible default.


381-385: LGTM! Sensible base tool inclusion.

Always including Read and Glob ensures agents have minimum required capabilities regardless of YAML configuration.


1-45: Excellent module documentation.

The docstring provides clear format specification, usage examples, and context for the hybrid YAML-to-SDK approach. This significantly aids maintainability.

Comment thread codeframe/agents/subagent_generator.py
CRITICAL fixes:
- Remove debug print statements from lead_agent.py (lines 1063-1572)
- Remove debug print statements from agent_pool_manager.py (lines 138-488)
- Fix YAML frontmatter tools format in subagent_generator.py (line 285)
  * Changed from Python list repr to valid YAML: [Tool1, Tool2]

SHOULD_FIX improvements:
- Fix hardcoded model name in hybrid_worker.py
  * Now uses getattr(self.sdk_client, "model", "claude-sonnet-4-20250514")
- Add type annotation to _create_traditional_agent method
  * Returns: Union[BackendWorkerAgent, FrontendWorkerAgent, TestWorkerAgent, ReviewWorkerAgent]
- Add assertion for session_id value in test_agent_pool_manager.py
  * Validates session_id is None for traditional agents
- Fix type annotation style inconsistency in subagent_generator.py
  * Changed set[str] to Set[str] for consistency

Additional fixes:
- Remove unused variable 'unblocked' in lead_agent.py (ruff F841)

Test results:
- All 92 tests passing (100% pass rate)
- All ruff linting checks passed

Addresses CodeRabbit review comments on PR #34
@claude

claude Bot commented Dec 2, 2025

Copy link
Copy Markdown

Code Review: SDK Migration Phase 3 - Agent Pattern Migration

Summary

This PR implements a well-designed hybrid agent pattern that bridges YAML-defined agents with the Claude Agent SDK. The implementation demonstrates strong software engineering practices with comprehensive testing (109 new tests, 100% pass rate), clean architecture, and thoughtful backward compatibility.

✅ Strengths

Architecture & Design

  • Excellent separation of concerns: The hybrid approach keeps YAML as source of truth while enabling SDK execution
  • Backward compatible: Feature flag use_sdk=False by default prevents breaking changes
  • Clean abstraction: HybridWorkerAgent extends WorkerAgent, preserving all CodeFRAME features (context management, quality gates, token tracking)
  • Session ID tracking: Enables conversation resume capability - important for long-running agents
  • Maturity levels preserved: D1-D4 Situational Leadership model maintained in generated markdown

Code Quality

  • Comprehensive testing: 109 new tests across all components (37 subagent generator, 33 hybrid worker, 29 pool manager, 10 lead agent)
  • Well-documented: Excellent docstrings with usage examples, clear parameter descriptions
  • Type hints: Proper type annotations throughout
  • Error handling: Graceful degradation with SDK fallback mechanism
  • Logging: Appropriate logging at INFO/DEBUG/ERROR levels

Security

  • API key handling: Properly reads from environment variables, doesn't hardcode secrets
  • Input validation: generate_agent() validates maturity levels and agent names
  • Tool mapping: Secure mapping from YAML abstract tools to concrete SDK tools
  • Error recovery: Max attempts (3) with escalation to manual intervention

⚠️ Areas for Improvement

1. SDK Client Environment Variable Mutation (Medium Priority)

File: codeframe/providers/sdk_client.py:45-46

if api_key and not os.environ.get("ANTHROPIC_API_KEY"):
    os.environ["ANTHROPIC_API_KEY"] = api_key

Issue: Mutating os.environ at runtime can cause issues in multi-threaded environments or when multiple SDK clients with different API keys are created.

Recommendation: Consider passing API key directly to SDK if supported, or document this behavior clearly with a warning about multi-client scenarios.

2. Broad Exception Catching (Low Priority)

Files:

  • codeframe/agents/hybrid_worker.py:169
  • codeframe/agents/hybrid_worker.py:339
except Exception as e:
    logger.error(...)

Issue: Catching all exceptions can mask unexpected errors.

Recommendation: Catch specific exceptions where possible (e.g., ImportError, KeyError, ValueError). For the token recording case at line 339, broad exception catching is acceptable since it's non-critical path, but consider logging with logger.exception() to include stack trace.

3. Context Length Truncation Magic Number (Low Priority)

File: codeframe/agents/hybrid_worker.py:228

for item in hot_context + warm_context[:20]:  # Limit warm context

Issue: Hard-coded limit of 20 warm context items.

Recommendation: Make this configurable via agent definition or class constant (e.g., MAX_WARM_CONTEXT_ITEMS = 20).

4. File Path Extraction Regex (Low Priority)

File: codeframe/agents/hybrid_worker.py:297-309

Issue: The regex patterns for extracting file paths may miss some valid paths or incorrectly match patterns in code comments/strings.

Recommendation:

  • Add unit tests for edge cases (paths with spaces, nested paths, false positives)
  • Consider more robust parsing (e.g., look for specific file operation indicators in structured LLM output)

5. Missing Type Annotations (Low Priority)

File: codeframe/agents/agent_pool_manager.py:103

self.agent_pool: Dict[str, Dict[str, Any]] = {}

Issue: Inner dict uses Any type.

Recommendation: Define a TypedDict or dataclass for agent info structure to improve type safety.

🔍 Additional Observations

Performance Considerations

  • Context loading: Loading HOT + WARM tiers on every task execution could be optimized with caching
  • Regex file extraction: Multiple regex passes over potentially large LLM responses (line 305-307) - consider combining patterns or limiting search scope

Test Coverage

  • Excellent coverage: 109 new tests is comprehensive
  • Missing edge cases: Consider adding tests for:
    • Concurrent agent creation in pool manager
    • Context overflow scenarios during task execution
    • SDK client failures mid-execution
    • Malformed YAML definitions

Documentation

  • Session documentation (claudedocs/SESSION.md) is exemplary - detailed phase breakdown, task status, file locations
  • Code comments are clear and helpful
  • Usage examples in docstrings are valuable

🎯 Recommendations Before Merge

Must Fix (None)

All critical issues have been addressed in the implementation.

Should Fix (Optional)

  1. Add configuration constant for warm context limit
  2. Improve exception specificity in hybrid_worker.py
  3. Add unit tests for edge cases in file path extraction

Nice to Have

  1. Document SDK client environment variable behavior in README
  2. Create TypedDict for agent pool structure
  3. Add integration test for concurrent agent execution

📊 Metrics

Metric Value Status
New Tests 109 ✅ Excellent
Pass Rate 100% ✅ Perfect
Files Changed 17 ✅ Reasonable
Lines Added 3,257 ⚠️ Large (expected for Phase 3)
Lines Deleted 117 ✅ Good cleanup

🏆 Overall Assessment

Grade: A- (Excellent)

This PR represents high-quality software engineering with:

  • ✅ Well-designed architecture
  • ✅ Comprehensive testing
  • ✅ Thoughtful backward compatibility
  • ✅ Clear documentation
  • ✅ Security best practices

The identified issues are minor and mostly stylistic. The hybrid agent pattern is a clever solution that enables gradual migration while preserving CodeFRAME's unique features.

Recommendation: APPROVE with optional improvements

The code is production-ready. The suggested improvements can be addressed in follow-up PRs without blocking this merge.


Next Steps

After merge, consider:

  1. Phase 4: Workflow Migration (Task → Plan → Execute coordination)
  2. Add monitoring/alerting for SDK fallback scenarios
  3. Performance profiling of context loading in production
  4. Documentation update for SDK migration guide

Great work on this phase! 🎉

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
codeframe/agents/subagent_generator.py (1)

280-288: LGTM! YAML tools format issue has been addressed.

The tools are now formatted as a valid YAML array using "[" + ", ".join(sdk_tools) + "]", which produces [Read, Write, Bash] format. This addresses the previous review concern about Python list repr being invalid YAML.

🧹 Nitpick comments (4)
tests/agents/test_agent_pool_manager.py (1)

395-422: Consider adding a test for hybrid agent's session_id in status.

The tests verify is_hybrid and session_id fields for traditional agents. Consider adding a test case that verifies session_id is correctly populated for hybrid agents in get_agent_status():

@patch("codeframe.agents.agent_pool_manager.SDK_AVAILABLE", True)
@patch("codeframe.agents.agent_pool_manager.SDKClientWrapper")
@patch("codeframe.agents.agent_pool_manager.HybridWorkerAgent")
def test_get_agent_status_includes_session_id_for_hybrid(
    self, mock_hybrid_class, mock_sdk_class, mock_db, mock_ws_manager
):
    """Test get_agent_status includes session_id for hybrid agents."""
    mock_sdk_class.return_value = Mock()
    mock_hybrid_class.return_value = Mock(session_id="sdk-session-123")

    manager = AgentPoolManager(
        project_id=1, db=mock_db, ws_manager=mock_ws_manager, use_sdk=True
    )
    agent_id = manager.create_agent("backend")
    status = manager.get_agent_status()

    assert status[agent_id]["session_id"] == "sdk-session-123"
codeframe/agents/lead_agent.py (1)

80-99: _project_root_override appears unused.

Line 82 stores project_root as self._project_root_override, but this attribute is never referenced elsewhere in the class. The project_root value is already passed to AgentPoolManager via cwd=project_root at line 93.

Either remove the unused attribute or document its intended purpose:

         # Store SDK mode flag
         self.use_sdk = use_sdk
-        self._project_root_override = project_root
 
         # Multi-agent coordination (Sprint 4) with SDK support (Phase 3)
codeframe/agents/subagent_generator.py (1)

234-236: Consider more robust filename sanitization.

The current sanitization only handles spaces and underscores. Agent names with special characters (e.g., Backend/API or Test@Unit) could produce invalid filenames:

         # Generate filename (sanitize agent name)
-        safe_name = agent_name.lower().replace(" ", "-").replace("_", "-")
+        import re
+        safe_name = re.sub(r'[^a-z0-9-]', '-', agent_name.lower())
+        safe_name = re.sub(r'-+', '-', safe_name).strip('-')  # Collapse multiple dashes
         output_path = self.output_dir / f"{safe_name}.md"
codeframe/agents/hybrid_worker.py (1)

228-234: Consider making context limits configurable.

The hard-coded limits (20 warm context items, 500 char truncation) work well but could be class constants or constructor parameters for flexibility:

class HybridWorkerAgent(WorkerAgent):
    MAX_WARM_CONTEXT_ITEMS = 20
    MAX_CONTEXT_ITEM_LENGTH = 500
    # ...

This is a minor improvement for maintainability.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a068c38 and a3aa709.

📒 Files selected for processing (5)
  • codeframe/agents/agent_pool_manager.py (9 hunks)
  • codeframe/agents/hybrid_worker.py (1 hunks)
  • codeframe/agents/lead_agent.py (7 hunks)
  • codeframe/agents/subagent_generator.py (1 hunks)
  • tests/agents/test_agent_pool_manager.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
tests/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

tests/**/*.py: Run all tests with pytest
Maintain 88%+ test coverage for Sprint 10 components and 100% pass rate

Files:

  • tests/agents/test_agent_pool_manager.py
codeframe/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

codeframe/**/*.py: Use Python 3.11+ with async/await pattern, type hints, and comprehensive tests for backend code
Use ruff for linting Python code
Use async/await pattern for promises in Python async code
Use FastAPI for backend API implementation
Use SQLite with async support (aiosqlite) for database operations
Use WebSocket for real-time updates between backend and frontend
API endpoints should accept project_id query parameter for multi-project support

Files:

  • codeframe/agents/hybrid_worker.py
  • codeframe/agents/agent_pool_manager.py
  • codeframe/agents/lead_agent.py
  • codeframe/agents/subagent_generator.py
🧠 Learnings (5)
📓 Common learnings
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: docs/CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:37.203Z
Learning: Implement Lead Agent for orchestration and Worker Agents for specialization (Backend, Frontend, Test, Review) with maturity levels D1-D4
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:20.036Z
Learning: Applies to tests/test_*worker_agent.py : Implement Worker Agent tests for async patterns
📚 Learning: 2025-11-25T19:08:20.036Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:20.036Z
Learning: Applies to tests/test_*worker_agent.py : Implement Worker Agent tests for async patterns

Applied to files:

  • tests/agents/test_agent_pool_manager.py
  • codeframe/agents/hybrid_worker.py
📚 Learning: 2025-11-25T19:08:20.036Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:20.036Z
Learning: Applies to codeframe/agents/worker_agent.py : Each agent maintains independent context scoped by (project_id, agent_id) tuple

Applied to files:

  • codeframe/agents/hybrid_worker.py
  • codeframe/agents/agent_pool_manager.py
  • codeframe/agents/lead_agent.py
📚 Learning: 2025-11-25T19:08:20.036Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:20.036Z
Learning: Applies to codeframe/agents/worker_agent.py : Implement flash save mechanism to archive COLD tier items when context approaches token limit (80% of 180k = 144k tokens)

Applied to files:

  • codeframe/agents/hybrid_worker.py
📚 Learning: 2025-11-25T19:08:37.203Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: docs/CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:37.203Z
Learning: Implement Lead Agent for orchestration and Worker Agents for specialization (Backend, Frontend, Test, Review) with maturity levels D1-D4

Applied to files:

  • codeframe/agents/lead_agent.py
🧬 Code graph analysis (2)
tests/agents/test_agent_pool_manager.py (1)
codeframe/agents/agent_pool_manager.py (3)
  • AgentPoolManager (56-473)
  • create_agent (120-175)
  • get_agent_status (288-309)
codeframe/agents/agent_pool_manager.py (4)
codeframe/agents/hybrid_worker.py (1)
  • HybridWorkerAgent (57-416)
codeframe/core/models.py (1)
  • AgentMaturity (21-27)
codeframe/providers/sdk_client.py (1)
  • SDKClientWrapper (25-125)
codeframe/agents/definition_loader.py (1)
  • create_agent (299-331)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Backend Unit Tests
  • GitHub Check: Frontend Unit Tests
  • GitHub Check: claude-review
🔇 Additional comments (14)
tests/agents/test_agent_pool_manager.py (2)

288-306: LGTM! SDK mode initialization tests are comprehensive.

Tests correctly verify that use_sdk defaults to False and is gated by SDK_AVAILABLE. The test at line 299 imports SDK_AVAILABLE from the module under test to validate the conjunction logic.


328-392: LGTM! Hybrid agent creation tests cover key scenarios.

Tests correctly validate:

  1. Hybrid agent creation when use_sdk=True with SDK available
  2. Traditional agent creation when use_sdk=False
  3. Per-agent use_sdk override functionality

The mock setup properly provides session_id attribute for hybrid agents.

codeframe/agents/lead_agent.py (3)

1325-1329: LGTM! SDK session tracking during task execution.

The session tracking correctly extracts session_id from hybrid agents and stores it for later persistence. The use of getattr with None fallback safely handles traditional agents.


1733-1749: LGTM! Session persistence with SDK sessions.

The on_session_end method correctly gathers SDK sessions and includes them in the persisted state for resume capability.


1753-1778: LGTM! Robust SDK session gathering.

The _get_sdk_sessions method correctly:

  • Filters for hybrid agents with valid session IDs
  • Uses defensive exception handling to prevent failures from breaking session persistence
  • Logs warnings for debugging while gracefully degrading
codeframe/agents/agent_pool_manager.py (4)

46-53: LGTM! SDK availability check with graceful fallback.

The try/except pattern for optional SDK dependency is appropriate, with a warning log for debugging when SDK is unavailable.


97-100: LGTM! SDK mode initialization with sensible defaults.

The initialization correctly:

  • Falls back to environment variable for api_key
  • Gates use_sdk on actual SDK availability
  • Defaults cwd to current working directory

135-156: Verify silent fallback behavior for per-call use_sdk=True when SDK unavailable.

When a caller passes use_sdk=True to create_agent() but SDK_AVAILABLE is False, the code silently creates a traditional agent instead. Consider whether a warning log would help users understand why their override didn't take effect:

         # Determine whether to use SDK for this agent
         create_hybrid = use_sdk if use_sdk is not None else self.use_sdk
 
+        # Warn if SDK was requested but unavailable
+        if create_hybrid and not SDK_AVAILABLE:
+            logger.warning(
+                f"SDK requested for agent {agent_type} but SDK unavailable - "
+                "falling back to traditional agent"
+            )
+
         with self.lock:

362-418: LGTM! Hybrid agent creation with appropriate configurations.

The method correctly:

  • Maps agent types to specialized system prompts
  • Assigns appropriate SDK tool sets per agent type
  • Normalizes agent type names for consistent lookup
  • Defaults to D2 maturity (coaching) which suits transitional agents
codeframe/agents/subagent_generator.py (2)

365-387: LGTM! Tool mapping with sensible defaults.

The _map_tools_to_sdk method correctly:

  • Maps YAML tool names to SDK equivalents
  • Deduplicates using a set
  • Always includes Read and Glob for basic agent functionality
  • Logs warnings for unmapped tools without failing

138-160: LGTM! Flexible definition loading with proper YAML parsing.

The loading logic correctly:

  • Handles both .yaml and .yml extensions
  • Supports a custom subdirectory for extensibility
  • Uses yaml.safe_load to prevent code execution vulnerabilities
codeframe/agents/hybrid_worker.py (3)

82-124: LGTM! Clean initialization extending WorkerAgent.

The initialization properly:

  • Calls parent constructor with required parameters
  • Stores SDK-specific attributes (sdk_client, session_id)
  • Leaves definition as None for AgentFactory to populate if using YAML definitions
  • Logs initialization state for debugging

126-208: LGTM! Comprehensive task execution with proper error handling.

The execute_task method correctly:

  1. Loads context from tiered memory (HOT + WARM)
  2. Builds contextual prompt
  3. Handles SDK errors gracefully, returning failure status
  4. Persists result summary to context
  5. Records token metrics (with non-blocking error handling)
  6. Triggers flash save when threshold exceeded

Good defensive coding throughout.


284-309: LGTM! Heuristic file extraction with reasonable patterns.

The regex patterns cover common phrases used when describing file modifications. The approach appropriately:

  • Uses multiple patterns for broader coverage
  • Deduplicates with a set
  • Returns sorted results for consistency

As a heuristic, it may have edge cases but is a pragmatic solution.

Comment thread codeframe/agents/agent_pool_manager.py
Comment on lines +343 to +400
async def execute_with_streaming(self, task: Task):
"""Execute task with streaming response.

Similar to execute_task but yields intermediate results for
real-time UI updates. This is an async generator.

Args:
task: Task to execute

Yields:
dict with keys:
- status: "streaming" for intermediate, "completed" for final
- content_chunk: Partial content (for streaming chunks)
- content: Full content (for final result)
- task_id: Task ID
- files_changed: List of modified files (final only)
- session_id: SDK session ID (final only)
"""
self.current_task = task

# Load context
hot_context = await self.load_context(tier=ContextTier.HOT)
warm_context = await self.load_context(tier=ContextTier.WARM)

# Build prompt
prompt = self._build_execution_prompt(task, hot_context, warm_context)

# Stream execution
full_content = []

async for message in self.sdk_client.send_message_streaming(prompt):
if hasattr(message, "content"):
content_chunk = str(message.content)
full_content.append(content_chunk)
yield {
"status": "streaming",
"content_chunk": content_chunk,
"task_id": task.id,
}

# Combine and yield final result
final_content = "".join(full_content)

# Save to context
result_summary = self._summarize_result(final_content)
await self.save_context_item(
item_type=ContextItemType.TASK,
content=f"Task {task.id} result: {result_summary}",
)

# Yield final result (async generators can't use return with value)
yield {
"status": "completed",
"content": final_content,
"output": final_content,
"files_changed": self._extract_changed_files(final_content),
"session_id": self.session_id,
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Missing error handling and token tracking in streaming execution.

Unlike execute_task, the execute_with_streaming method lacks:

  1. Try/except around SDK call for error handling
  2. Token usage recording via _record_token_usage
  3. Flash save threshold check

Consider adding parity with execute_task:

+        try:
             async for message in self.sdk_client.send_message_streaming(prompt):
                 if hasattr(message, "content"):
                     content_chunk = str(message.content)
                     full_content.append(content_chunk)
                     yield {
                         "status": "streaming",
                         "content_chunk": content_chunk,
                         "task_id": task.id,
                     }
+        except Exception as e:
+            logger.error(f"Streaming execution failed for task {task.id}: {e}")
+            yield {
+                "status": "failed",
+                "content": str(e),
+                "task_id": task.id,
+            }
+            return

Committable suggestion skipped: line range outside the PR's diff.

Add codebase_index parameter to AgentPoolManager.__init__ and pass it
to BackendWorkerAgent instead of None. This fixes AttributeError when
BackendWorkerAgent.gather_context() calls codebase_index.search_pattern().
@frankbria
frankbria merged commit b159d38 into main Dec 2, 2025
10 of 13 checks passed
@frankbria
frankbria deleted the feature/sdk-migration-phase-3 branch December 2, 2025 03:16

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
codeframe/agents/agent_pool_manager.py (2)

365-421: Hybrid agent construction is solid; consider centralizing prompts/tool sets

The normalization of agent_type to a base_type, the tailored system_prompts and tool_sets per role, and the encapsulation of SDK wiring via SDKClientWrapper + HybridWorkerAgent are all clean and composable.

To avoid drift with the YAML/SubagentGenerator definitions, consider pulling system_prompts and tool_sets from a shared config or helper module used both here and by the generator, so backend/frontend/test/review capabilities stay in sync over time.


423-470: Traditional agent mapping looks correct; optionally fail fast on missing codebase_index

Mapping:

  • backend/backend-worker → BackendWorkerAgent(project_id, db, codebase_index=self.codebase_index, ...)
  • frontend/frontend-specialist → FrontendWorkerAgent(...)
  • test/test-engineer → TestWorkerAgent(...)
  • review/review-worker → ReviewWorkerAgent(...)

correctly aligns with the summarized constructor signatures, and passing self.codebase_index now addresses the earlier bug where None was always passed to BackendWorkerAgent. This is a good fix relative to the past review comment.

If BackendWorkerAgent.gather_context() still assumes a non-None codebase_index, you might want to fail fast when it’s missing to avoid a later AttributeError:

-        if agent_type == "backend" or agent_type == "backend-worker":
-            return BackendWorkerAgent(
+        if agent_type == "backend" or agent_type == "backend-worker":
+            if self.codebase_index is None:
+                raise RuntimeError(
+                    "BackendWorkerAgent requires a non-None codebase_index; "
+                    "pass a CodebaseIndex into AgentPoolManager(codebase_index=...)."
+                )
+            return BackendWorkerAgent(
                 project_id=self.project_id,
                 db=self.db,
                 codebase_index=self.codebase_index,
                 provider="anthropic",
                 api_key=self.api_key,
             )

This keeps misconfiguration failures localized to agent creation instead of surfacing deep in backend processing.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a3aa709 and 4ad1f9e.

📒 Files selected for processing (1)
  • codeframe/agents/agent_pool_manager.py (9 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
codeframe/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

codeframe/**/*.py: Use Python 3.11+ with async/await pattern, type hints, and comprehensive tests for backend code
Use ruff for linting Python code
Use async/await pattern for promises in Python async code
Use FastAPI for backend API implementation
Use SQLite with async support (aiosqlite) for database operations
Use WebSocket for real-time updates between backend and frontend
API endpoints should accept project_id query parameter for multi-project support

Files:

  • codeframe/agents/agent_pool_manager.py
🧠 Learnings (5)
📓 Common learnings
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: docs/CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:37.203Z
Learning: Implement Lead Agent for orchestration and Worker Agents for specialization (Backend, Frontend, Test, Review) with maturity levels D1-D4
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:20.036Z
Learning: Applies to tests/test_*worker_agent.py : Implement Worker Agent tests for async patterns
📚 Learning: 2025-11-25T19:08:20.036Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:20.036Z
Learning: Applies to codeframe/agents/worker_agent.py : Each agent maintains independent context scoped by (project_id, agent_id) tuple

Applied to files:

  • codeframe/agents/agent_pool_manager.py
📚 Learning: 2025-11-25T19:08:20.036Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:20.036Z
Learning: Applies to codeframe/agents/worker_agent.py : Block task completion when quality gates fail (test failures, type errors, coverage <85%, critical review issues)

Applied to files:

  • codeframe/agents/agent_pool_manager.py
📚 Learning: 2025-11-25T19:08:37.203Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: docs/CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:37.203Z
Learning: Implement Lead Agent for orchestration and Worker Agents for specialization (Backend, Frontend, Test, Review) with maturity levels D1-D4

Applied to files:

  • codeframe/agents/agent_pool_manager.py
📚 Learning: 2025-11-25T19:08:20.036Z
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:20.036Z
Learning: Applies to codeframe/agents/review_agent.py : Review Agent analysis performance target: <30s per file

Applied to files:

  • codeframe/agents/agent_pool_manager.py
🧬 Code graph analysis (1)
codeframe/agents/agent_pool_manager.py (7)
codeframe/agents/backend_worker_agent.py (1)
  • BackendWorkerAgent (35-1329)
codeframe/agents/frontend_worker_agent.py (1)
  • FrontendWorkerAgent (22-866)
codeframe/agents/test_worker_agent.py (1)
  • TestWorkerAgent (25-1023)
codeframe/agents/review_worker_agent.py (1)
  • ReviewWorkerAgent (21-332)
codeframe/agents/hybrid_worker.py (1)
  • HybridWorkerAgent (57-416)
codeframe/core/models.py (1)
  • AgentMaturity (21-27)
codeframe/providers/sdk_client.py (1)
  • SDKClientWrapper (25-125)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Frontend Unit Tests
  • GitHub Check: Backend Unit Tests
  • GitHub Check: claude-review
🔇 Additional comments (3)
codeframe/agents/agent_pool_manager.py (3)

69-104: SDK feature flagging and initialization look sound

use_sdk being ANDed with SDK_AVAILABLE, the env-based api_key default, and the explicit warning when SDK is requested but unavailable give a clear, safe initialization story. The logging of the effective use_sdk mode is also helpful for debugging pool configuration.

Also applies to: 114-121


123-160: Hybrid vs traditional branching and pool metadata are well-structured

Per-call use_sdk override (create_hybrid) layered on top of the pool-level default, the guarded _create_hybrid_agent call (create_hybrid and SDK_AVAILABLE), and the is_hybrid flag stored in agent_pool collectively give a clean, predictable decision path. The split into _create_hybrid_agent / _create_traditional_agent also improves readability and future extensibility.

Also applies to: 169-171, 173-178


169-171: Make session_id in status reflect the live agent instance

Right now session_id is snapshotted once at creation time and then read back from the dict in get_agent_status. For HybridWorkerAgent, session_id is expected to be updated after SDK calls, so status will likely return a stale value (often None).

Use the live instance attribute when building the status payload so callers see the current session:

@@
-            for agent_id, agent_info in self.agent_pool.items():
-                status[agent_id] = {
+            for agent_id, agent_info in self.agent_pool.items():
+                instance = agent_info.get("instance")
+                status[agent_id] = {
@@
-                    "blocked_by": agent_info.get("blocked_by"),
-                    "is_hybrid": agent_info.get("is_hybrid", False),
-                    "session_id": agent_info.get("session_id"),
+                    "blocked_by": agent_info.get("blocked_by"),
+                    "is_hybrid": agent_info.get("is_hybrid", False),
+                    "session_id": getattr(instance, "session_id", agent_info.get("session_id")),
                 }

You can keep the stored session_id in the pool for now for backwards compatibility; this change only affects the reported status.

Also applies to: 301-310

⛔ Skipped due to learnings
Learnt from: CR
Repo: frankbria/codeframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T19:08:20.036Z
Learning: Applies to codeframe/agents/worker_agent.py : Each agent maintains independent context scoped by (project_id, agent_id) tuple

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant