From 499a843a43023962ecd34701af623f8cd6422f05 Mon Sep 17 00:00:00 2001 From: Yiorgis Gozadinos Date: Thu, 9 Apr 2026 13:56:09 +0300 Subject: [PATCH] remove unused create_analysis_toolset and AnalysisResult --- CHANGELOG.md | 1 + docs/tools.md | 16 ---- haiku_rag_slim/haiku/rag/tools/__init__.py | 3 - haiku_rag_slim/haiku/rag/tools/analysis.py | 87 ---------------------- tests/tools/test_analysis.py | 42 ----------- tests/tools/test_models.py | 17 ----- 6 files changed, 1 insertion(+), 165 deletions(-) delete mode 100644 haiku_rag_slim/haiku/rag/tools/analysis.py delete mode 100644 tests/tools/test_analysis.py delete mode 100644 tests/tools/test_models.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cebaa24..4fa6289d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/tools.md b/docs/tools.md index 378d967d..b552a6fe 100644 --- a/docs/tools.md +++ b/docs/tools.md @@ -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: diff --git a/haiku_rag_slim/haiku/rag/tools/__init__.py b/haiku_rag_slim/haiku/rag/tools/__init__.py index a9237d80..def2e88c 100644 --- a/haiku_rag_slim/haiku/rag/tools/__init__.py +++ b/haiku_rag_slim/haiku/rag/tools/__init__.py @@ -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", ] diff --git a/haiku_rag_slim/haiku/rag/tools/analysis.py b/haiku_rag_slim/haiku/rag/tools/analysis.py deleted file mode 100644 index fd9b54a5..00000000 --- a/haiku_rag_slim/haiku/rag/tools/analysis.py +++ /dev/null @@ -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 diff --git a/tests/tools/test_analysis.py b/tests/tools/test_analysis.py deleted file mode 100644 index 30dd6bbb..00000000 --- a/tests/tools/test_analysis.py +++ /dev/null @@ -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 diff --git a/tests/tools/test_models.py b/tests/tools/test_models.py deleted file mode 100644 index 9d055dcc..00000000 --- a/tests/tools/test_models.py +++ /dev/null @@ -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