Add optional db_path and config params to generated skill create_skill()

This commit is contained in:
Yiorgis Gozadinos 2026-03-26 13:41:58 +02:00
parent 72cd94322c
commit 1c9035ebb5
No known key found for this signature in database
5 changed files with 31 additions and 10 deletions

View file

@ -4,6 +4,7 @@
### Added ### Added
- **Chunk visualization for generated skills**: `visualize_chunk(chunk_id)` function exposed in generated skill packages, enabling callers to render visual grounding from chunk IDs in skill state - **Chunk visualization for generated skills**: `visualize_chunk(chunk_id)` function exposed in generated skill packages, enabling callers to render visual grounding from chunk IDs in skill state
- **Configurable generated skills**: Generated skill `create_skill()` now accepts optional `db_path` and `config` parameters, enabling post-discovery reconfiguration via `skill.reconfigure()` (requires haiku.skills >= 0.11.0)
### Fixed ### Fixed

View file

@ -2,6 +2,7 @@ from pathlib import Path
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
from haiku.rag.config.models import AppConfig
from haiku.skills.models import Skill from haiku.skills.models import Skill
from haiku.skills.parser import parse_skill_md from haiku.skills.parser import parse_skill_md
{% if "ask" in tool_names or "research" in tool_names %} {% if "ask" in tool_names or "research" in tool_names %}
@ -62,12 +63,21 @@ def _get_config():
return get_config() return get_config()
def create_skill() -> Skill: def create_skill(
db_path: Path | None = None,
config: AppConfig | None = None,
) -> Skill:
from haiku.rag.skills._tools import create_skill_tools from haiku.rag.skills._tools import create_skill_tools
metadata, instructions = parse_skill_md(Path(__file__).parent / "SKILL.md") metadata, instructions = parse_skill_md(Path(__file__).parent / "SKILL.md")
config = _get_config()
tools = create_skill_tools(_DB_PATH, config, SkillState, _TOOL_NAMES) if config is None:
config = _get_config()
if db_path is None:
db_path = _DB_PATH
tools = create_skill_tools(db_path, config, SkillState, _TOOL_NAMES)
return Skill( return Skill(
metadata=metadata, metadata=metadata,
instructions=instructions, instructions=instructions,

View file

@ -1,11 +1,11 @@
import os import os
from functools import cache from functools import cache
from pathlib import Path from pathlib import Path
from typing import Any
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
from haiku.rag.agents.research.models import Citation from haiku.rag.agents.research.models import Citation
from haiku.rag.config.models import AppConfig
from haiku.rag.skills._tools import ResearchEntry from haiku.rag.skills._tools import ResearchEntry
from haiku.rag.store.models.chunk import SearchResult from haiku.rag.store.models.chunk import SearchResult
from haiku.rag.tools.document import DocumentInfo from haiku.rag.tools.document import DocumentInfo
@ -61,7 +61,7 @@ def state_metadata() -> StateMetadata:
def create_skill( def create_skill(
db_path: Path | None = None, db_path: Path | None = None,
config: Any = None, config: AppConfig | None = None,
) -> Skill: ) -> Skill:
"""Create a RAG skill for searching and analyzing documents. """Create a RAG skill for searching and analyzing documents.

View file

@ -1,10 +1,10 @@
import os import os
from functools import cache from functools import cache
from pathlib import Path from pathlib import Path
from typing import Any
from pydantic import BaseModel from pydantic import BaseModel
from haiku.rag.config.models import AppConfig
from haiku.rag.skills._tools import AnalysisEntry from haiku.rag.skills._tools import AnalysisEntry
from haiku.skills.models import Skill, SkillMetadata, SkillSource, StateMetadata from haiku.skills.models import Skill, SkillMetadata, SkillSource, StateMetadata
from haiku.skills.parser import parse_skill_md from haiku.skills.parser import parse_skill_md
@ -42,7 +42,7 @@ def state_metadata() -> StateMetadata:
def create_skill( def create_skill(
db_path: Path | None = None, db_path: Path | None = None,
config: Any = None, config: AppConfig | None = None,
) -> Skill: ) -> Skill:
"""Create an RLM analysis skill for computational document analysis. """Create an RLM analysis skill for computational document analysis.

View file

@ -142,9 +142,7 @@ class TestRenderTemplates:
) )
init = tmp_path / "docs-skill" / "docs_skill" / "__init__.py" init = tmp_path / "docs-skill" / "docs_skill" / "__init__.py"
content = init.read_text() content = init.read_text()
assert ( assert "create_skill_tools(db_path, config, SkillState, _TOOL_NAMES)" in content
"create_skill_tools(_DB_PATH, config, SkillState, _TOOL_NAMES)" in content
)
def test_tool_names_in_init(self, tmp_path): def test_tool_names_in_init(self, tmp_path):
render_templates( render_templates(
@ -273,6 +271,18 @@ class TestRenderTemplates:
assert "skill_visualize_chunk" not in content assert "skill_visualize_chunk" not in content
assert "HaikuRAG" in content assert "HaikuRAG" in content
def test_create_skill_accepts_optional_params(self, tmp_path):
render_templates(
output_dir=tmp_path,
name="docs",
description="A docs skill.",
tool_names=["search"],
)
init = tmp_path / "docs-skill" / "docs_skill" / "__init__.py"
content = init.read_text()
assert "db_path: Path | None = None" in content
assert "config: AppConfig | None = None" in content
def test_generated_python_is_valid(self, tmp_path): def test_generated_python_is_valid(self, tmp_path):
render_templates( render_templates(
output_dir=tmp_path, output_dir=tmp_path,