Repository navigation
Description
Overview
The ollama integration tests in `packages/agent/tests/ollama_integration.rs` have significant coverage gaps: most tests only assert that the model didn't call a wrong tool (whitelist enforcement), but never assert that the correct tool was actually called. This means regressions where the model stops calling a specific tool go completely undetected.
A concrete regression is already happening: the model never calls `search_nodes` — it always reaches for `search_semantic` instead. This is caused by a prompt imbalance introduced in commit `1b833491` where `search_semantic` received 4 lines of detailed guidance (including a `DO NOT call search_nodes` phrase in context) while `search_nodes` kept its single thin line.
Problem Statement
Observed regression:
- User asks agent to find nodes by title/keyword
- Agent calls `search_semantic` repeatedly and loops to max iterations
- `search_nodes` is never called despite being the correct tool for keyword/title lookups
Root cause (prompt_assembler.rs line 259):
The Tool Strategy Guide added in `1b833491` says:
"If the top result has a non-empty 'markdown' field, that IS the full document — use it directly to answer. Do NOT call get_node or search_nodes afterward."
The model reads this and infers `search_semantic` is always preferred. `search_nodes` has no equivalent guidance explaining when to prefer it.
Test coverage gaps — tools with no "must be called" assertion:
| Tool | Test | Problem |
|---|---|---|
| `search_nodes` | `test_skill_pipeline_research_real_model` | Accepts `search_semantic` OR `search_nodes` — semantic always wins |
| `search_semantic` | Same | Allowed but never required |
| `get_node` | All tests | Allowed as fallback, never required |
| `get_related_nodes` | relationship test | Prompt uses hardcoded IDs so model skips straight to `create_relationship` |
| `find_skills` | None | Zero tests |
| `update_node` | graph editing test | Accepts `update_task_status` OR `update_node` — task status always wins |
Tests with weak assertions:
- `test_skill_pipeline_research_real_model` — comment says "both are valid", no assertion a search was called at all
- `test_skill_pipeline_node_creation_real_model` — no assertion `create_node` was actually called
- `test_skill_pipeline_node_deletion_real_model` — no assertion `delete_node` was actually called
- `test_skill_pipeline_graph_editing_real_model` — prompt uses placeholder ID `abc-123` (violates prompt rules, unpredictable behavior)
Proposed Solution
- Fix the prompt bias in `packages/agent/src/prompt_assembler.rs`: balance the `search_nodes` guidance to explain when it should be preferred (keyword/title match, known node name, type filter)
- Add dedicated tests that require each tool to be called with scenario-appropriate prompts
- Replace weak "whitelist-only" assertions with "must call this tool" assertions where applicable
Acceptance Criteria
- `prompt_assembler.rs` Tool Strategy Guide gives `search_nodes` clear guidance: use for exact title/keyword match or when filtering by type
- New test: `test_pipeline_search_nodes_keyword` — prompt like "find the task called 'Review quarterly report'" asserts `search_nodes` was called
- New test: `test_pipeline_get_related_nodes` — prompt like "what nodes are connected to X?" asserts `get_related_nodes` was called
- New test: `test_pipeline_update_node_content` — prompt like "update the title of the 'Architecture Notes' node to 'System Architecture'" asserts `update_node` was called (not `update_task_status`)
- New test: `test_pipeline_get_node_by_id` — prompt like "show me the full content of node abc-123" asserts `get_node` was called
- `test_skill_pipeline_research_real_model` strengthened: assert at least one search tool was called (not just "text is also fine")
- `test_skill_pipeline_node_creation_real_model` strengthened: assert `create_node` was called
- `test_skill_pipeline_node_deletion_real_model` strengthened: assert `delete_node` was called
- `test_skill_pipeline_graph_editing_real_model` prompt fixed: remove placeholder ID `abc-123`, use a realistic search-then-update scenario
- All new and updated tests pass with the local Ministral-3B model
- Code passes `bun run quality:fix`
Technical Specifications
Files to Modify
- Prompt assembler: `packages/agent/src/prompt_assembler.rs` — Tool Strategy Guide seed prompt (lines 254–266), balance `search_nodes` vs `search_semantic` guidance
- Integration tests: `packages/agent/tests/ollama_integration.rs` — add new pipeline scenario tests, strengthen existing assertions
Guidance Fix Pattern
Current (biased):
```
- To find nodes by meaning/topic: use search_semantic (natural language query)
- [4 lines of search_semantic detail including "Do NOT call search_nodes afterward"]
- To find nodes by exact fields: use search_nodes (keyword + type filter)
```
Target (balanced):
```
- To find nodes by exact title/keyword or filter by type: use search_nodes
- To find nodes by meaning/topic when the exact name is unknown: use search_semantic
- [guidance for each without implying the other should never be used]
```
Test Pattern
New tests should follow the existing `test_pipeline_` pattern (full `LocalAgentService` with `StubToolExecutor`), not the `test_skill_pipeline_` pattern (skill-scoped inference only), since we want to test the full intent→tool flow.
Related Issues
- Fix local agent document reading (get_node markdown, search_semantic, prompt tuning) #1081 (introduced the prompt imbalance in search_semantic guidance)
Activity