haiku.rag/docs/skills/analysis.md
2026-04-17 18:32:01 +03:00

2.3 KiB

Analysis Skill

The analysis skill provides computational analysis via code execution. It writes and runs Python code in a sandboxed interpreter to answer questions that require computation, aggregation, or data traversal.

create_skill(db_path?, config?)

from haiku.rag.skills.analysis import create_skill

skill = create_skill(db_path=db_path, config=config)
Parameter Default Description
db_path None Path to LanceDB database. Falls back to HAIKU_RAG_DB env var, then config default.
config None AppConfig instance. If None, uses get_config().

Tools

Tool Purpose
analyze(question, document?, filter?) Answer analytical questions using code execution

Parameters:

  • question — The analytical question to answer.
  • document — Optional document ID or title to pre-load for analysis.
  • filter — Optional SQL WHERE clause to filter documents.

State

The skill manages an AnalysisState under the "analysis" namespace:

class AnalysisState(BaseModel):
    document_filter: str | None = None
    analyses: list[AnalysisEntry] = []

class AnalysisEntry(BaseModel):
    question: str
    answer: str
    program: str | None = None
  • document_filter — SQL WHERE clause applied to analyze calls (combined with any explicit filter parameter). Set this to scope analysis to specific documents.
  • analyses — Each analyze call appends an AnalysisEntry with the question, answer, and executed program.

Usage with RAG Skill

Combine both skills to give the agent full RAG + analysis capabilities:

from haiku.rag.skills.rag import create_skill as create_rag_skill
from haiku.rag.skills.analysis import create_skill as create_analysis_skill
from haiku.skills.agent import SkillToolset
from haiku.skills.prompts import build_system_prompt
from pydantic_ai import Agent

rag = create_rag_skill(db_path=db_path)
analysis = create_analysis_skill(db_path=db_path)
toolset = SkillToolset(skills=[rag, analysis])

agent = Agent(
    "openai:gpt-4o",
    instructions=build_system_prompt(toolset.skill_catalog),
    toolsets=[toolset],
)

See the Analysis Agent documentation for details on how the underlying agent works.