karenina-adapter-implement

Implements a new karenina adapter package file-by-file following a design spec.

13|3|Updated Jun 27, 2025
One-click install
npx skills add https://github.com/biocypher/karenina --skill karenina-adapter-implement-biocypher
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: karenina-adapter-implement
Source: https://github.com/biocypher/karenina/tree/main/skills/karenina-adapter-implement
Command: npx skills add https://github.com/biocypher/karenina --skill karenina-adapter-implement-biocypher

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing a new LLM/agent adapter for the karenina evaluation framework requires implementing many interdependent port protocol files correctly, and subtle mistakes (wrong message field names, missing timeout handling, broken usage extraction) silently corrupt evaluation results. ## Core Features & Use Cases - Guided file-by-file generation: Implements the adapter in dependency order, from __init__.py and availability.py through agent.py, llm.py, parser.py, and registration.py. - Convention enforcement: Applies karenina coding standards (lazy imports, PEP 604 unions, Google-style docstrings, duck-typed protocols) and registry integration via manual, built-in, or entry-point plugin paths. - Pitfall prevention: Encodes ten documented bugs found across existing adapters, including JSON serialization of structured output, turn-limit wiring, no-tools fallbacks, partial timeout recovery, and MCP session management with AsyncExitStack. - Use Case: After designing an adapter spec for a new LLM SDK, use this Skill to generate the complete adapter package with correct streaming, usage aggregation, and error mapping, ready for Phase 4 testing. ## Quick Start Implement the karenina adapter for my SDK following the design spec from the adapter-design phase.

Frequently Asked Questions about karenina-adapter-implement

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement a new karenina adapter for an LLM SDK?

Follow the file-by-file order: availability check, error mapping, message conversion, trace and usage extraction, then agent, llm, and parser port classes, finishing with registry registration. Read the port protocol files in karenina/src/karenina/ports/ first to get exact interface signatures.

What files does a karenina adapter package contain?

A typical adapter contains __init__.py with lazy exports, availability.py, errors.py, messages.py, trace.py, usage.py, agent.py, llm.py, parser.py, registration.py, and a prompts/ directory. Optional files include initialization.py and mcp.py depending on the SDK.

How do I register a karenina adapter with the AdapterRegistry?

Create a registration.py that calls AdapterRegistry.register() with an AdapterSpec defining factories and capability flags. For built-in adapters, import it in registry.py's _load_builtins(); for plugins, declare a karenina.adapters entry point in pyproject.toml.

Why does my karenina adapter report zero tokens for usage?

Zero tokens usually means usage extraction reads only the last message instead of summing across all AI messages, or with_structured_output() discarded the raw response. Use include_raw=True or the SDK equivalent to retain token counts.

How should a karenina adapter handle agent execution timeouts?

Wrap execution in asyncio.wait_for() on all paths, accumulate messages incrementally, and on TimeoutError return a partial AgentResult with timeout_reached=True if any messages exist. Raise AgentTimeoutError only when no messages were collected at all.

Does every karenina adapter need to implement streaming?

Every LLM adapter must define astream() and stream_invoke(), but adapters without SDK streaming support may raise NotImplementedError and set supports_streaming=False in PortCapabilities. Streaming enables partial content capture on request timeouts.