Skills documentation
This commit is contained in:
parent
a1c09e1a47
commit
11534bf686
6 changed files with 196 additions and 81 deletions
|
|
@ -6,7 +6,7 @@ Three agentic flows are provided by haiku.rag:
|
|||
- **Research Graph** — a multi-step research workflow with question decomposition
|
||||
- **RLM Agent** — complex analytical tasks via sandboxed Python code execution (see [RLM Agent](rlm.md))
|
||||
|
||||
For multi-turn conversational RAG, haiku.rag provides a [RAG skill](../tools.md#rag-skill) built on [haiku.skills](https://github.com/ggozad/haiku.skills). The skill bundles search, Q&A, analysis, and research tools with session state management.
|
||||
For multi-turn conversational RAG, haiku.rag provides [skills](../skills/index.md) built on [haiku.skills](https://github.com/ggozad/haiku.skills). The skills bundle search, Q&A, analysis, and research tools with session state management.
|
||||
|
||||
See [QA and Research Configuration](../configuration/qa-research.md) for configuring model, iterations, concurrency, and other settings.
|
||||
|
||||
|
|
|
|||
72
docs/skills/index.md
Normal file
72
docs/skills/index.md
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
# Skills
|
||||
|
||||
haiku.rag exposes its RAG capabilities as [haiku.skills](https://github.com/ggozad/haiku.skills) skills. Skills are self-contained units that bundle tools, instructions, and state — they can be composed into any pydantic-ai agent via `SkillToolset`.
|
||||
|
||||
## Available Skills
|
||||
|
||||
| Skill | Description |
|
||||
|-------|-------------|
|
||||
| [`rag`](rag.md) | Search, retrieve, and answer questions from the knowledge base |
|
||||
| [`rag-rlm`](rlm.md) | Computational analysis via code execution (requires Docker) |
|
||||
|
||||
## Discovery
|
||||
|
||||
Skills are registered as Python entrypoints under `haiku.skills`. They are discovered automatically by `haiku.skills`:
|
||||
|
||||
```bash
|
||||
haiku-skills list --use-entrypoints
|
||||
# rag — Search, retrieve and analyze documents using RAG.
|
||||
# rag-rlm — Analyze documents using code execution in a Docker sandbox.
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```python
|
||||
from haiku.rag.skills.rag import create_skill
|
||||
from haiku.skills.agent import SkillToolset
|
||||
from pydantic_ai import Agent
|
||||
|
||||
skill = create_skill(db_path=db_path, config=config)
|
||||
toolset = SkillToolset(skills=[skill])
|
||||
|
||||
agent = Agent(
|
||||
"openai:gpt-4o",
|
||||
instructions=toolset.system_prompt,
|
||||
toolsets=[toolset],
|
||||
)
|
||||
|
||||
result = await agent.run("What documents do we have?")
|
||||
```
|
||||
|
||||
## Database Path Resolution
|
||||
|
||||
Both skills resolve the database path in the same order:
|
||||
|
||||
1. `db_path` argument passed to `create_skill()`
|
||||
2. `HAIKU_RAG_DB` environment variable
|
||||
3. Config default (`config.storage.data_dir / "haiku.rag.lancedb"`)
|
||||
|
||||
## State Management
|
||||
|
||||
Each skill manages its own state under a dedicated namespace. State is automatically synced via the AG-UI protocol when using `AGUIAdapter`.
|
||||
|
||||
```python
|
||||
rag_state = toolset.get_namespace("rag")
|
||||
rlm_state = toolset.get_namespace("rlm")
|
||||
```
|
||||
|
||||
See the individual skill pages for state model details.
|
||||
|
||||
## AG-UI Streaming
|
||||
|
||||
For web applications, use pydantic-ai's `AGUIAdapter` to stream tool calls, text, and state deltas:
|
||||
|
||||
```python
|
||||
from pydantic_ai.ag_ui import AGUIAdapter
|
||||
|
||||
adapter = AGUIAdapter(agent=agent, run_input=run_input)
|
||||
event_stream = adapter.run_stream()
|
||||
sse_event_stream = adapter.encode_stream(event_stream)
|
||||
```
|
||||
|
||||
See the [Web Application](../apps.md#web-application) for a complete implementation.
|
||||
47
docs/skills/rag.md
Normal file
47
docs/skills/rag.md
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# RAG Skill
|
||||
|
||||
The RAG skill is the primary way to use haiku.rag tools. It bundles search, Q&A, document browsing, and research into a single skill with managed state.
|
||||
|
||||
## `create_skill(db_path?, config?)`
|
||||
|
||||
```python
|
||||
from haiku.rag.skills.rag 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 |
|
||||
|------|---------|
|
||||
| `search(query, limit?)` | Hybrid search (vector + full-text) with context expansion |
|
||||
| `list_documents(limit?, offset?, filter?)` | Paginated document listing |
|
||||
| `get_document(query)` | Retrieve a document by ID, title, or URI |
|
||||
| `ask(question)` | Q&A with citations via the QA agent |
|
||||
| `research(question)` | Deep multi-agent research producing comprehensive reports |
|
||||
|
||||
## State
|
||||
|
||||
The skill manages a `RAGState` under the `"rag"` namespace:
|
||||
|
||||
```python
|
||||
class RAGState(BaseModel):
|
||||
citations: list[Citation] = []
|
||||
qa_history: list[QAHistoryEntry] = []
|
||||
document_filter: str | None = None
|
||||
searches: dict[str, list[SearchResult]] = {}
|
||||
documents: list[DocumentInfo] = []
|
||||
reports: list[ResearchEntry] = []
|
||||
```
|
||||
|
||||
- **citations** — Accumulated citations from `ask` calls, with sequential indexing across calls.
|
||||
- **qa_history** — Questions and answers from `ask` calls. Prior Q&A is used as context for follow-up questions when embeddings are similar.
|
||||
- **document_filter** — SQL WHERE clause applied to `search`, `ask`, and `research` calls. Set this to scope queries to specific documents.
|
||||
- **searches** — Search results keyed by query string.
|
||||
- **documents** — Documents seen via `list_documents` or `get_document` (deduplicated by ID).
|
||||
- **reports** — Research reports from `research` calls.
|
||||
70
docs/skills/rlm.md
Normal file
70
docs/skills/rlm.md
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
# RLM Skill
|
||||
|
||||
The RLM (Reflexion Language Model) skill provides computational analysis via code execution. It writes and runs Python code in an isolated Docker sandbox to answer questions that require computation, aggregation, or data traversal.
|
||||
|
||||
!!! warning "Requires Docker"
|
||||
The `analyze` tool executes code in a Docker sandbox. Docker must be running on the host machine. This skill is not suitable for Docker-deployed applications — use the [`rag`](rag.md) skill alone in those environments.
|
||||
|
||||
## `create_skill(db_path?, config?)`
|
||||
|
||||
```python
|
||||
from haiku.rag.skills.rlm 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 `RLMState` under the `"rlm"` namespace:
|
||||
|
||||
```python
|
||||
class RLMState(BaseModel):
|
||||
analyses: list[AnalysisEntry] = []
|
||||
|
||||
class AnalysisEntry(BaseModel):
|
||||
question: str
|
||||
answer: str
|
||||
program: str | None = None
|
||||
```
|
||||
|
||||
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.rlm import create_skill as create_rlm_skill
|
||||
from haiku.skills.agent import SkillToolset
|
||||
from pydantic_ai import Agent
|
||||
|
||||
rag = create_rag_skill(db_path=db_path)
|
||||
rlm = create_rlm_skill(db_path=db_path)
|
||||
toolset = SkillToolset(skills=[rag, rlm])
|
||||
|
||||
agent = Agent(
|
||||
"openai:gpt-4o",
|
||||
instructions=toolset.system_prompt,
|
||||
toolsets=[toolset],
|
||||
)
|
||||
```
|
||||
|
||||
See the [RLM Agent](../agents/rlm.md) documentation for details on how the underlying agent works.
|
||||
|
|
@ -1,87 +1,9 @@
|
|||
# Tools & Skills
|
||||
# Toolsets
|
||||
|
||||
haiku.rag exposes its RAG capabilities through a [haiku.skills](https://github.com/ggozad/haiku.skills) skill. The skill provides tools for search, Q&A, analysis, and research that can be composed into any pydantic-ai agent via `SkillToolset`.
|
||||
haiku.rag exposes its RAG capabilities as [haiku.skills](https://github.com/ggozad/haiku.skills) skills. See the [Skills](skills/index.md) section for the primary way to use haiku.rag tools.
|
||||
|
||||
For lower-level access, `haiku.rag.tools` provides individual `FunctionToolset` factories used internally by agents.
|
||||
|
||||
## RAG Skill
|
||||
|
||||
The RAG skill is the primary way to use haiku.rag tools. It bundles all capabilities into a single skill with managed state.
|
||||
|
||||
```python
|
||||
from haiku.rag.skills.rag import create_skill
|
||||
from haiku.skills.agent import SkillToolset
|
||||
from pydantic_ai import Agent
|
||||
|
||||
skill = create_skill(db_path=db_path, config=config)
|
||||
toolset = SkillToolset(skills=[skill])
|
||||
|
||||
agent = Agent(
|
||||
"openai:gpt-4o",
|
||||
instructions=toolset.system_prompt,
|
||||
toolsets=[toolset],
|
||||
)
|
||||
|
||||
result = await agent.run("What documents do we have?")
|
||||
```
|
||||
|
||||
### `create_skill(db_path?, config?)`
|
||||
|
||||
Creates a RAG skill instance.
|
||||
|
||||
| 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 |
|
||||
|------|---------|
|
||||
| `search(query, limit?)` | Hybrid search (vector + full-text) with context expansion |
|
||||
| `list_documents(limit?, offset?, filter?)` | Paginated document listing |
|
||||
| `get_document(query)` | Retrieve a document by ID, title, or URI |
|
||||
| `ask(question)` | Q&A with citations via the QA agent |
|
||||
| `analyze(question, document?, filter?)` | Computational analysis via code execution (requires Docker) |
|
||||
| `research(question)` | Deep multi-agent research producing comprehensive reports |
|
||||
|
||||
### State
|
||||
|
||||
The skill manages a `RAGState` under the `"rag"` namespace:
|
||||
|
||||
```python
|
||||
class RAGState(BaseModel):
|
||||
citations: list[Any] = []
|
||||
qa_history: list[QAHistoryEntry] = []
|
||||
document_filter: str | None = None
|
||||
searches: dict[str, list[SearchResult]] = {}
|
||||
documents: list[DocumentInfo] = []
|
||||
reports: list[ResearchEntry] = []
|
||||
```
|
||||
|
||||
State is automatically synced via the AG-UI protocol when using `AGUIAdapter`. Access it programmatically:
|
||||
|
||||
```python
|
||||
rag_state = toolset.get_namespace("rag")
|
||||
if rag_state:
|
||||
print(f"Citations: {len(rag_state.citations)}")
|
||||
print(f"Q&A history: {len(rag_state.qa_history)}")
|
||||
```
|
||||
|
||||
### AG-UI Streaming
|
||||
|
||||
For web applications, use pydantic-ai's `AGUIAdapter` to stream tool calls, text, and state deltas:
|
||||
|
||||
```python
|
||||
from pydantic_ai.ag_ui import AGUIAdapter
|
||||
|
||||
adapter = AGUIAdapter(agent=agent, run_input=run_input)
|
||||
event_stream = adapter.run_stream()
|
||||
sse_event_stream = adapter.encode_stream(event_stream)
|
||||
```
|
||||
|
||||
See the [Web Application](apps.md#web-application) for a complete implementation.
|
||||
|
||||
## Low-Level Toolsets
|
||||
|
||||
For advanced use cases, individual toolset factories are available in `haiku.rag.tools`. These are used internally by the QA agent and can be composed into custom agents.
|
||||
|
|
|
|||
|
|
@ -74,6 +74,10 @@ nav:
|
|||
- Agents:
|
||||
- agents/index.md
|
||||
- RLM Agent: agents/rlm.md
|
||||
- Skills:
|
||||
- skills/index.md
|
||||
- RAG: skills/rag.md
|
||||
- RLM: skills/rlm.md
|
||||
- Toolsets: tools.md
|
||||
- Applications: apps.md
|
||||
- Server: server.md
|
||||
|
|
|
|||
Loading…
Reference in a new issue