remove unused create_analysis_toolset and AnalysisResult
This commit is contained in:
parent
1049586469
commit
499a843a43
6 changed files with 1 additions and 165 deletions
|
|
@ -27,6 +27,7 @@
|
|||
- **`context_radius` config**: Replaced by automatic section-bounded expansion. Context expansion no longer requires configuration.
|
||||
- **DoclingDocument LRU cache**: No longer needed — the document_items table replaces in-memory caching for context expansion
|
||||
- **`cachetools` dependency**: No longer used
|
||||
- **`create_analysis_toolset()`**: Removed unused `tools/analysis.py` module.
|
||||
|
||||
## [0.39.0] - 2026-04-09
|
||||
|
||||
|
|
|
|||
|
|
@ -59,22 +59,6 @@ docs = create_document_toolset(config)
|
|||
- `get_document(query)` — Retrieve a document by title or URI.
|
||||
- `summarize_document(query)` — Generate an LLM summary of a document's content.
|
||||
|
||||
### Analysis Toolset
|
||||
|
||||
`create_analysis_toolset()` provides computational analysis via the RLM agent.
|
||||
|
||||
```python
|
||||
from haiku.rag.tools import create_analysis_toolset
|
||||
|
||||
analysis = create_analysis_toolset(config)
|
||||
```
|
||||
|
||||
| Parameter | Default | Description |
|
||||
|-----------|---------|-------------|
|
||||
| `config` | required | `AppConfig` |
|
||||
| `base_filter` | `None` | SQL WHERE clause applied to searches |
|
||||
| `tool_name` | `"analyze"` | Name of the tool exposed to the agent |
|
||||
|
||||
## Filter Helpers
|
||||
|
||||
`haiku.rag.tools.filters` provides utilities for building SQL filters:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
from haiku.rag.tools.analysis import AnalysisResult, create_analysis_toolset
|
||||
from haiku.rag.tools.context import RAGDeps
|
||||
from haiku.rag.tools.document import create_document_toolset
|
||||
from haiku.rag.tools.filters import (
|
||||
|
|
@ -10,14 +9,12 @@ from haiku.rag.tools.qa import PRIOR_ANSWER_RELEVANCE_THRESHOLD, QAHistoryEntry
|
|||
from haiku.rag.tools.search import create_search_toolset
|
||||
|
||||
__all__ = [
|
||||
"AnalysisResult",
|
||||
"PRIOR_ANSWER_RELEVANCE_THRESHOLD",
|
||||
"QAHistoryEntry",
|
||||
"RAGDeps",
|
||||
"build_document_filter",
|
||||
"build_multi_document_filter",
|
||||
"combine_filters",
|
||||
"create_analysis_toolset",
|
||||
"create_document_toolset",
|
||||
"create_search_toolset",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,87 +0,0 @@
|
|||
from pydantic import BaseModel, Field
|
||||
from pydantic_ai import FunctionToolset, RunContext
|
||||
|
||||
from haiku.rag.agents.rlm.agent import create_rlm_agent
|
||||
from haiku.rag.agents.rlm.dependencies import RLMContext, RLMDeps
|
||||
from haiku.rag.agents.rlm.sandbox import Sandbox
|
||||
from haiku.rag.config.models import AppConfig
|
||||
from haiku.rag.tools.context import RAGDeps
|
||||
from haiku.rag.tools.filters import (
|
||||
build_document_filter,
|
||||
combine_filters,
|
||||
)
|
||||
|
||||
|
||||
class AnalysisResult(BaseModel):
|
||||
"""Result from the analysis toolset (RLM execution)."""
|
||||
|
||||
answer: str = Field(description="The answer produced by analysis")
|
||||
code_executed: bool = Field(
|
||||
default=True,
|
||||
description="Whether code was executed to produce this answer",
|
||||
)
|
||||
|
||||
|
||||
def create_analysis_toolset(
|
||||
config: AppConfig,
|
||||
base_filter: str | None = None,
|
||||
tool_name: str = "analyze",
|
||||
) -> FunctionToolset[RAGDeps]:
|
||||
"""Create a toolset with code analysis capabilities via RLM agent.
|
||||
|
||||
Args:
|
||||
config: Application configuration.
|
||||
base_filter: Optional base SQL WHERE clause applied to searches.
|
||||
tool_name: Name for the analyze tool. Defaults to "analyze".
|
||||
|
||||
Returns:
|
||||
FunctionToolset with an analyze tool.
|
||||
"""
|
||||
|
||||
async def analyze( # pragma: no cover
|
||||
ctx: RunContext[RAGDeps],
|
||||
task: str,
|
||||
document_name: str | None = None,
|
||||
) -> AnalysisResult:
|
||||
"""Execute a computational task via code execution.
|
||||
|
||||
Uses the RLM (Recursive Language Model) agent to write and execute
|
||||
Python code to answer the task.
|
||||
|
||||
Args:
|
||||
task: A specific, actionable instruction describing what to compute.
|
||||
document_name: Optional document name/title to focus on.
|
||||
|
||||
Returns:
|
||||
AnalysisResult with answer and execution metadata.
|
||||
"""
|
||||
client = ctx.deps.client
|
||||
|
||||
doc_filter = build_document_filter(document_name) if document_name else None
|
||||
effective_filter = combine_filters(base_filter, doc_filter)
|
||||
|
||||
rlm_context = RLMContext(filter=effective_filter)
|
||||
|
||||
sandbox = Sandbox(
|
||||
client=client,
|
||||
config=config,
|
||||
context=rlm_context,
|
||||
)
|
||||
deps = RLMDeps(
|
||||
sandbox=sandbox,
|
||||
context=rlm_context,
|
||||
)
|
||||
|
||||
rlm_agent = create_rlm_agent(config)
|
||||
result = await rlm_agent.run(task, deps=deps)
|
||||
|
||||
program = result.output.program
|
||||
|
||||
return AnalysisResult(
|
||||
answer=result.output.answer,
|
||||
code_executed=bool(program),
|
||||
)
|
||||
|
||||
toolset: FunctionToolset[RAGDeps] = FunctionToolset()
|
||||
toolset.add_function(analyze, name=tool_name)
|
||||
return toolset
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
import pytest
|
||||
|
||||
from haiku.rag.tools.analysis import create_analysis_toolset
|
||||
|
||||
|
||||
class TestAnalysisToolset:
|
||||
"""Tests for create_analysis_toolset."""
|
||||
|
||||
def test_create_analysis_toolset_returns_function_toolset(self, analysis_config):
|
||||
"""create_analysis_toolset returns a FunctionToolset."""
|
||||
from pydantic_ai import FunctionToolset
|
||||
|
||||
toolset = create_analysis_toolset(analysis_config)
|
||||
assert isinstance(toolset, FunctionToolset)
|
||||
|
||||
def test_analysis_toolset_has_analyze_tool(self, analysis_config):
|
||||
"""The toolset includes an 'analyze' tool."""
|
||||
toolset = create_analysis_toolset(analysis_config)
|
||||
assert "analyze" in toolset.tools
|
||||
|
||||
def test_analysis_toolset_custom_tool_name(self, analysis_config):
|
||||
"""Toolset supports custom tool name."""
|
||||
toolset = create_analysis_toolset(analysis_config, tool_name="run_code")
|
||||
assert "run_code" in toolset.tools
|
||||
assert "analyze" not in toolset.tools
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def analysis_client(temp_db_path):
|
||||
"""Create a HaikuRAG client for analysis tests."""
|
||||
from haiku.rag.client import HaikuRAG
|
||||
|
||||
async with HaikuRAG(temp_db_path, create=True) as rag:
|
||||
yield rag
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def analysis_config():
|
||||
"""Default AppConfig for analysis tests."""
|
||||
from haiku.rag.config import Config
|
||||
|
||||
return Config
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
from haiku.rag.tools.analysis import AnalysisResult
|
||||
|
||||
|
||||
def test_analysis_result_defaults():
|
||||
"""Test AnalysisResult has sensible defaults."""
|
||||
result = AnalysisResult(answer="The result is 42")
|
||||
assert result.code_executed is True
|
||||
|
||||
|
||||
def test_analysis_result_with_values():
|
||||
"""Test AnalysisResult with explicit values."""
|
||||
result = AnalysisResult(
|
||||
answer="The result is 42",
|
||||
code_executed=True,
|
||||
)
|
||||
assert result.answer == "The result is 42"
|
||||
assert result.code_executed is True
|
||||
Loading…
Reference in a new issue