# Implementation Plan: API Usage Audit and Alignment

## Phase 1: Research and Comprehensive Audit [checkpoint: 5ec4283]
Identify all points of interaction with AI SDKs and compare them with latest official documentation.

- [x] Task: List and categorize all AI SDK usage in the project.
    - [x] Search for all imports of `google.genai` and `anthropic`.
    - [x] Document specific functions and methods being called.
- [x] Task: Research latest official documentation for `google-genai` and `anthropic` Python SDKs.
    - [x] Verify latest patterns for Client initialization.
    - [x] Verify latest patterns for Context/Prompt caching.
    - [x] Verify latest patterns for Tool/Function calling.
- [x] Task: Conductor - User Manual Verification 'Phase 1: Research and Comprehensive Audit' (Protocol in workflow.md)

## Phase 2: Gemini (google-genai) Alignment [checkpoint: 842bfc4]
Align Gemini integration with documented best practices.

- [x] Task: Refactor Gemini Client and Chat initialization if needed.
    - [x] Write Tests
    - [x] Implement Feature
- [x] Task: Optimize Gemini Context Caching.
    - [x] Write Tests
    - [x] Implement Feature
- [x] Task: Align Gemini Tool Declaration and handling.
    - [x] Write Tests
    - [x] Implement Feature
- [x] Task: Conductor - User Manual Verification 'Phase 2: Gemini (google-genai) Alignment' (Protocol in workflow.md)

## Phase 3: Anthropic Alignment [checkpoint: f0eb538]
Align Anthropic integration with documented best practices.

- [x] Task: Refactor Anthropic Client and Message creation if needed.
    - [x] Write Tests
    - [x] Implement Feature
- [x] Task: Optimize Anthropic Prompt Caching (`cache_control`).
    - [x] Write Tests
    - [x] Implement Feature
- [x] Task: Align Anthropic Tool Declaration and handling.
    - [x] Write Tests
    - [x] Implement Feature
- [x] Task: Conductor - User Manual Verification 'Phase 3: Anthropic Alignment' (Protocol in workflow.md)

## Phase 4: History and Token Management [checkpoint: 0f9f235]
Ensure accurate token estimation and robust history handling.

- [x] Task: Review and align token estimation logic for both providers.
    - [x] Write Tests
    - [x] Implement Feature
- [x] Task: Audit message history truncation and context window management.
    - [x] Write Tests
    - [x] Implement Feature
- [x] Task: Conductor - User Manual Verification 'Phase 4: History and Token Management' (Protocol in workflow.md)

## Phase 5: Final Validation and Cleanup [checkpoint: e9126b4]
- [x] Task: Perform a full test run using `run_tests.py` to ensure 100% pass rate.
- [x] Task: Conductor - User Manual Verification 'Phase 5: Final Validation and Cleanup' (Protocol in workflow.md)
