# LLM-WP-0002 — Core Extensions (FR-4 + FR-3) **status:** active **owner:** llm-connect **repo:** llm-connect **created:** 2026-04-01 **depends-on:** LLM-WP-0001 (contracts and tests must exist before Core is modified) ## Purpose Implement the two IHF feature requests that touch the Core layer. FR-4 (BudgetTracker) is additive and non-breaking. FR-3 (async) extends the Core ABC with a default executor fallback — non-breaking, overridable per adapter for native async. Origin: IHUB-WP-0012 Phase 11 — Advanced AI Federation (completed 2026-04-01). ## GAAF notes Both changes are Core-layer modifications under GAAF-2026: - FR-4: new primitive (`BudgetTracker`) + new exception (`LLMBudgetExceededError`) added as optional `RunConfig` field — additive, non-breaking. - FR-3: `async_execute_prompt` added to `LLMAdapter` ABC with a default `asyncio.get_event_loop().run_in_executor(None, ...)` fallback so existing adapters remain valid; native async overrides are provided per adapter. Core contract doc (from WP-0001 T05) must be updated after each change. ## Tasks ### FR-4 — BudgetTracker | ID | Title | Priority | Status | |-----|-------|----------|--------| | T01 | `BudgetTracker` dataclass: `total`, `spent`, `remaining()`, thread-safe increment | high | todo | | T02 | `LLMBudgetExceededError(LLMError)` in `exceptions.py` | high | todo | | T03 | Optional `budget_tracker: BudgetTracker \| None` field on `RunConfig` | high | todo | | T04 | Enforcement: each adapter checks/updates tracker around call; raises on exceeded | high | todo | | T05 | Update Core contract doc | medium | todo | | T06 | Tests: single call, delegation chain (A→B→C shared tracker), exceeded error, multi-adapter | high | todo | ### FR-3 — async_execute_prompt | ID | Title | Priority | Status | |-----|-------|----------|--------| | T07 | Add `async_execute_prompt` to `LLMAdapter` ABC with default executor fallback | high | todo | | T08 | Native async override in `OpenAIAdapter`, `GeminiAdapter`, `OpenRouterAdapter` | high | todo | | T09 | Native async for `ClaudeCodeAdapter` via `asyncio.create_subprocess_exec` | high | todo | | T10 | Update Core contract doc | medium | todo | | T11 | Tests: `asyncio.gather` over N adapters, timeout propagation, budget interaction | high | todo | ## Exit criteria - `BudgetTracker` enforces caps across a delegation chain of 3 adapters in tests - `asyncio.gather` over 4 mock adapters completes without errors - All existing tests still pass (non-breaking validation) - Core contract doc reflects both additions