diff --git a/notebooks/skills.ipynb b/notebooks/skills.ipynb new file mode 100644 index 0000000..3396ee4 --- /dev/null +++ b/notebooks/skills.ipynb @@ -0,0 +1,223 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "b1bed39d", + "metadata": {}, + "source": [ + "# Skills Example\n", + "\n", + "This notebook demonstrates how to use a `SKILL.md` file with Wags-LLM." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "e9161ef9", + "metadata": {}, + "outputs": [], + "source": [ + "import logging\n", + "import sys\n", + "from collections.abc import Mapping\n", + "from pathlib import Path\n", + "from typing import Any\n", + "\n", + "from pydantic import BaseModel, ConfigDict\n", + "\n", + "from wags_llm.client.bedrock import BedrockClaudeJsonClient\n", + "from wags_llm.services.structured_task import StructuredTaskRunner\n", + "from wags_llm.skills.base import BaseSkillTemplate\n", + "from wags_llm.skills.registry import SkillRegistry\n", + "\n", + "logging.basicConfig(\n", + " stream=sys.stdout,\n", + " level=logging.WARNING,\n", + " format=\"%(name)s - %(levelname)s - %(message)s\",\n", + ")\n", + "logging.getLogger(\"wags_llm\").setLevel(logging.DEBUG)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "1e9131aa", + "metadata": {}, + "outputs": [], + "source": [ + "class VariantCurationSkill(BaseSkillTemplate):\n", + " skill_path = Path(\"skills/variant_curation_0.1.0.md\")\n", + "\n", + " def build_user_prompt(self, payload: Mapping[str, Any]) -> str:\n", + " variant = payload[\"variant\"]\n", + " disease = payload.get(\"disease\", \"cancer\")\n", + "\n", + " return f\"\"\"Curate the following variant for {disease}.\n", + "Variant:\n", + "{variant}\n", + "\n", + "Return concise JSON matching the provided schema:\n", + "- clinical_significance: one short sentence\n", + "- evidence_level: short label\n", + "- supporting_rationale: 2-3 short sentences maximum\n", + "\"\"\"\n", + "\n", + "\n", + "class VariantCurationResult(BaseModel):\n", + " model_config = ConfigDict(extra=\"forbid\", use_enum_values=True) # Required\n", + "\n", + " clinical_significance: str | None = None\n", + " evidence_level: str | None = None\n", + " supporting_rationale: str | None = None\n", + " error_message: str | None = None" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "3c719fca", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('variant_curation', '0.1.0')" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "skill = VariantCurationSkill()\n", + "skill.name, skill.version" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "c44eeb11", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wags_llm.skills.registry - DEBUG - Registering skill: name='variant_curation', version='0.1.0'\n", + "wags_llm.client.bedrock - DEBUG - BedrockClaudeJsonClient config: model_id='us.anthropic.claude-sonnet-4-6', region_name='us-east-1', profile_name='dev-account', max_tokens=350, temperature=0.000000\n", + "wags_llm.client.bedrock - INFO - BedrockClaudeJsonClient successfully initialized for model_id='us.anthropic.claude-sonnet-4-6'\n" + ] + } + ], + "source": [ + "registry = SkillRegistry()\n", + "registry.register(skill)\n", + "\n", + "MODEL_ID = \"us.anthropic.claude-sonnet-4-6\"\n", + "REGION_NAME = \"us-east-1\"\n", + "PROFILE_NAME = \"dev-account\"\n", + "MAX_TOKENS = 350\n", + "\n", + "llm_client = BedrockClaudeJsonClient(\n", + " model_id=MODEL_ID,\n", + " region_name=REGION_NAME,\n", + " profile_name=PROFILE_NAME,\n", + " max_tokens=MAX_TOKENS,\n", + " temperature=0,\n", + ")\n", + "\n", + "task_runner = StructuredTaskRunner(\n", + " client=llm_client,\n", + " skill_registry=registry,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "d045cf30", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wags_llm.skills.base - DEBUG - Loading skill from path: skills/variant_curation_0.1.0.md\n", + "wags_llm.skills.base - INFO - Loaded skill from path: skills/variant_curation_0.1.0.md\n", + "wags_llm.client.bedrock - DEBUG - Bedrock Claude usage={'inputTokens': 576, 'outputTokens': 185, 'totalTokens': 761, 'cacheReadInputTokens': 0, 'cacheWriteInputTokens': 0}\n", + "wags_llm.client.bedrock - DEBUG - Bedrock Claude metrics={'latencyMs': 4014}\n", + "wags_llm.client.bedrock - DEBUG - Bedrock Claude content=[{'text': '{\"clinical_significance\":\"BRAF V600E is a pathogenic, therapeutically actionable variant in melanoma associated with sensitivity to BRAF and MEK inhibitors.\",\"evidence_level\":\"Level A (Validated association)\",\"supporting_rationale\":\"BRAF V600E is the most common activating mutation in melanoma, present in approximately 50% of cases, and constitutively activates the MAPK signaling pathway. FDA-approved targeted therapies including vemurafenib, dabrafenib (BRAF inhibitors), and trametinib (MEK inhibitor) demonstrate significant clinical benefit in BRAF V600E-positive melanoma patients. Multiple phase III clinical trials support improved progression-free and overall survival with BRAF/MEK inhibitor combinations compared to chemotherapy.\",\"error_message\":null}'}]\n" + ] + }, + { + "data": { + "text/plain": [ + "VariantCurationResult(clinical_significance='BRAF V600E is a pathogenic, therapeutically actionable variant in melanoma associated with sensitivity to BRAF and MEK inhibitors.', evidence_level='Level A (Validated association)', supporting_rationale='BRAF V600E is the most common activating mutation in melanoma, present in approximately 50% of cases, and constitutively activates the MAPK signaling pathway. FDA-approved targeted therapies including vemurafenib, dabrafenib (BRAF inhibitors), and trametinib (MEK inhibitor) demonstrate significant clinical benefit in BRAF V600E-positive melanoma patients. Multiple phase III clinical trials support improved progression-free and overall survival with BRAF/MEK inhibitor combinations compared to chemotherapy.', error_message=None)" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "result = task_runner.execute_skill(\n", + " skill_name=\"variant_curation\",\n", + " skill_version=\"0.1.0\",\n", + " payload={\n", + " \"variant\": \"BRAF V600E\",\n", + " \"disease\": \"melanoma\",\n", + " },\n", + " response_model=VariantCurationResult,\n", + ")\n", + "result" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "2ac3d498", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'clinical_significance': 'BRAF V600E is a pathogenic, therapeutically actionable variant in melanoma associated with sensitivity to BRAF and MEK inhibitors.',\n", + " 'evidence_level': 'Level A (Validated association)',\n", + " 'supporting_rationale': 'BRAF V600E is the most common activating mutation in melanoma, present in approximately 50% of cases, and constitutively activates the MAPK signaling pathway. FDA-approved targeted therapies including vemurafenib, dabrafenib (BRAF inhibitors), and trametinib (MEK inhibitor) demonstrate significant clinical benefit in BRAF V600E-positive melanoma patients. Multiple phase III clinical trials support improved progression-free and overall survival with BRAF/MEK inhibitor combinations compared to chemotherapy.',\n", + " 'error_message': None}" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "result.model_dump()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "wags-llm (3.13.5)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/notebooks/skills/variant_curation_0.1.0.md b/notebooks/skills/variant_curation_0.1.0.md new file mode 100644 index 0000000..9fa0840 --- /dev/null +++ b/notebooks/skills/variant_curation_0.1.0.md @@ -0,0 +1,23 @@ +--- +name: variant-curation +description: Assess clinical significance of a genomic variant in a specified disease context. +--- + +# Variant Curation + +## Inputs +- variant +- disease + +## Instructions +- Follow CIViC-style evidence reasoning. +- Be precise. +- Do not invent evidence. +- Flag uncertainty clearly. + +## Output +Return a `VariantCurationResult` object containing: +- clinical_significance +- evidence_level +- supporting_rationale +- error_message