Files
llm-connect/workplans/llm-connect-WP-0002-core-extensions.md
Bernd Worsch d71f4114d1 feat: WP-0001 foundation + WP-0002 core extensions
WP-0001 — Foundation & GAAF Baseline
- SCOPE.md, ARCHITECTURE-LAYERS.md, contracts/ tree
- .claude/rules/ stubs filled (architecture, stack, boundary)
- 57 tests (pytest), pyproject.toml with ruff+mypy, CI workflow

WP-0002 — Core Extensions (FR-4 + FR-3)
- FR-4: BudgetTracker (thread-safe) + LLMBudgetExceededError +
  optional RunConfig.budget_tracker + enforcement in all adapters
- FR-3: async_execute_prompt on LLMAdapter ABC (asyncio.to_thread
  fallback) + native asyncio.create_subprocess_exec in ClaudeCodeAdapter

81 tests passing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-01 22:24:14 +00:00

58 lines
2.5 KiB
Markdown

# 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