Wire harness to Claude API for skill invocation#22
Conversation
Implement production-ready skill invocation infrastructure to enable
programmatic execution of curator and harmonizer skills via Claude API.
Replaces placeholder implementations with fully functional code.
## Core Infrastructure
**skill_invoker.py** (new, 413 lines)
- Generic SkillInvoker class for Claude API communication
- Loads skill definitions from skills/*/SKILL.md files
- Parses YAML frontmatter and extracts system prompts
- Manages context files with automatic exemplar pool filtering
- Validates outputs against Pydantic schemas
- Handles JSON extraction from multiple response formats
**run_skill1.py** (updated)
- invoke_curator() now fully implemented (was placeholder)
- Builds curator-specific prompts with exemplar pool filtering
- Validates output as CuratorBundle schema
- Saves bundle JSON + full transcript for audit trail
**run_skill2.py** (updated)
- invoke_harmonizer() now fully implemented (was placeholder)
- Loads exemplar code from data/gold/expert_code/
- Prioritizes similar dataset code from curator bundle
- Extracts Python code and mapping JSON separately
- Validates both outputs against schemas
## Key Features
- **Exemplar pool filtering**: Critical for leave-one-out cross-validation
- **Schema validation**: Catches malformed outputs early via Pydantic
- **Full audit trail**: Saves transcripts (prompt, response, usage) for every invocation
- **Reproducible**: Deterministic run IDs, all parameters logged
- **Modular**: Skills are self-contained SKILL.md files
## Documentation
**RUNNING_EXPERIMENTS.md** (new, 338 lines)
- Complete usage guide with examples
- Architecture diagrams
- Code samples for all experiment types
- Cost estimation (~$41 for full Phase A)
- Troubleshooting guide
**HARNESS_IMPLEMENTATION.md** (new, 326 lines)
- Technical implementation summary
- Design decisions and rationale
- File changes overview
- Known limitations and next steps
**tests/test_harness.py** (new, 277 lines)
- Validation test suite
- Tests skill loading, context prep, schemas, gold data
- All tests passing ✓
- Can run without API key to verify infrastructure
## Dependencies
**pyproject.toml** (updated)
- Added anthropic>=0.18.0
## Usage
```python
from pathlib import Path
from src.harness.run_skill1 import invoke_curator
bundle = invoke_curator(
identifier="doi:10.15485/2566877",
exemplar_pool=[0, 2, 3, 4, 5],
skill_version="0.1",
model_id="claude-sonnet-4-5",
random_seed=42,
output_dir=Path("output/test"),
)
```
## Validation
All infrastructure tests pass:
✓ Skill loading
✓ Context loading with exemplar pool filtering
✓ Schema validation
✓ Gold data accessibility
Ready for production use with ANTHROPIC_API_KEY set.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
Claude finished @hmworsham's task —— View job PR Review: Wire harness to Claude API for skill invocationTasks:
Overall this is a solid implementation that cleanly wires the evaluation harness to the Claude API. The architecture is well-structured and the modular skill-based design is good. Below are specific findings organized by category. Bugs / Correctness Issues1. raise ValidationError(
f"Could not extract valid {schema.__name__} from response.\n"
...
)
2.
3. Regex for JSON object extraction is fragile ( json_objects = re.findall(
r'\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}',
response_text,
re.DOTALL
)This only handles one level of nesting and will silently fail on any moderately complex JSON schema (e.g., nested objects like 4. json_blocks = re.findall(
r'```(?:json)?\n(\{.*?\})\n``\`',
...
)The 5. The Security6. API key stored in instance variable as plain string ( self.api_key = api_key or os.environ.get("ANTHROPIC_API_KEY")Storing the raw key on 7. Prompt injection risk in user-controlled The Code Quality8. Custom YAML parser is fragile and unnecessary (
9. Context files are embedded verbatim with no truncation or size check. If a mapping JSON or exemplar code file is large, this could silently push the request well over the model's context window, causing an API error that's hard to diagnose. Add a guard or at minimum log the total prompt size. 10. Path resolution relies on project_root = Path(__file__).parent.parent.parentThis works when the file is at 11. for key, value in result.items():
if isinstance(value, list) and all(isinstance(v, str) for v in value):
result[key] = ' '.join(value)This means a YAML list like Performance12. Skill definition re-read from disk on every API call (
13. All exemplar code files read sequentially ( Minor: this is fine for the current scale but noted for when the pool grows. Test Coverage14. Tests are integration/smoke tests, not unit tests ( The test file is written as a standalone script ( Refactor to use 15. No test for the failure/error path There are no tests for what happens when Claude returns malformed JSON, when the API is rate-limited, or when a skill file is missing a system prompt section. Given that 16. No test for exemplar pool filtering edge cases The filter check at Minor
SummaryThe core design is sound and this is a meaningful step toward a functional evaluation harness. The most important issues to address before merge are #1 (the broken |
Summary
Implements production-ready skill invocation infrastructure to enable programmatic execution of curator and harmonizer skills via Claude API. This completes the evaluation harness by replacing placeholder implementations with fully functional code.
Core Changes
New Infrastructure (
src/harness/skill_invoker.py) - 413 linesSkillInvokerclass for Claude API communicationskills/*/SKILL.mdfilesCurator Skill Wiring (
src/harness/run_skill1.py)invoke_curator()fully implemented (replaced placeholder)CuratorBundleschemaHarmonizer Skill Wiring (
src/harness/run_skill2.py)invoke_harmonizer()fully implemented (replaced placeholder)data/gold/expert_code/Key Features
✅ Exemplar pool filtering - Critical for leave-one-out cross-validation
✅ Schema validation - Catches malformed outputs early via Pydantic
✅ Full audit trail - Saves transcripts (prompt, response, usage) for every invocation
✅ Reproducible - Deterministic run IDs, all parameters logged
✅ Modular - Skills are self-contained SKILL.md files
✅ Ready for automation - Can be orchestrated by another Claude instance
Documentation
RUNNING_EXPERIMENTS.md(new, 338 lines)HARNESS_IMPLEMENTATION.md(new, 326 lines)tests/test_harness.py(new, 277 lines)Usage Example
Validation
Ran
python tests/test_harness.py:Files Changed
src/harness/skill_invoker.py(+413 lines)RUNNING_EXPERIMENTS.md(+338 lines)HARNESS_IMPLEMENTATION.md(+326 lines)tests/test_harness.py(+277 lines)src/harness/run_skill1.py(replaced placeholder)src/harness/run_skill2.py(replaced placeholder)pyproject.toml(addedanthropic>=0.18.0)Total: +1,684 lines, -79 lines
Next Steps
After merge:
ANTHROPIC_API_KEYenvironment variableCost Estimate
22K tokens/run ($0.05/run)44K tokens/run ($0.10/run)🤖 Generated with Claude Code