70 lines
2.3 KiB
Markdown
70 lines
2.3 KiB
Markdown
# 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?)`
|
|
|
|
```python
|
|
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:
|
|
|
|
```python
|
|
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:
|
|
|
|
```python
|
|
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](../agents/analysis.md) documentation for details on how the underlying agent works.
|