You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Complements PR #210 — adds a no-tools-called retry for local Ollama models (12-14B) that return a final answer without calling any tools.
Problem
After PR #210 fixed the ollama/ → ollama_chat/ rewrite and ModelBehaviorError retry, testing with local models revealed a second failure mode:
qwen2.5-coder:14b (local): add works (227s), but query returns "I cannot find relevant information" — the model didn't call read_file
gemma4:12b (local): query returns empty output ""
The KB is correctly built (wiki, concepts, entities all present), but the model doesn't initiate tool calls during query — it answers directly without reading wiki files.
This is a model capability limitation, not a transport bug. The adapter cannot force a model to call tools, but it can nudge it.
Fix
After Runner.run() completes successfully, the adapter checks result.new_items for any ToolCallItem. If the agent has tools but none were called, the adapter retries with an escalating nudge message:
Attempt 1 (gentle):
You answered without reading any wiki files. You have tools available. Call read_file with path 'summaries/index.md' first to see what documents exist, then answer the question.
Attempt 2 (firm):
You MUST use the read_file tool. Do NOT answer without reading files first. Start with read_file(path='summaries/index.md'). Available tools: read_file, get_page_content.
Attempt 3 (final):
IMPORTANT: Your previous answer was not grounded in the wiki. Call read_file now. The available tools are: read_file, get_page_content. Do not answer until you have called a tool.
If all retries are exhausted, the adapter returns the last (ungrounded) answer — no infinite loops.
This PR includes all changes from PR #210 (ollama_chat/ rewrite, ModelBehaviorError retry, parameterized timeouts, drop_params, api_base propagation) plus the no-tools-called retry. The two retry mechanisms share the same tool_call_retries budget.
Testing
73 adapter unit tests (17 new for no-tools retry) — all passing
When a local Ollama model (12-14B) returns a final answer without calling
any tools, the adapter now retries with an escalating nudge message:
Attempt 1: 'You answered without reading wiki files. Call read_file
with path summaries/index.md first.'
Attempt 2: 'You MUST use the read_file tool. Do NOT answer without
reading files first.'
Attempt 3: 'IMPORTANT: Your previous answer was not grounded. Call
read_file now. Do not answer until you have called a tool.'
Detection: _has_tool_calls() checks result.new_items for ToolCallItem.
If none found and agent has tools, nudge and retry (up to tool_call_retries).
Bounded by tool_call_retries (default 3) — no infinite loops.
Shares retry budget with ModelBehaviorError retry.
Tests: 73 adapter tests (17 new), 1148 total, 0 failures.
Docs: docs/ollama_no_tools_retry.md
Complements PR VectifyAI#210 (ollama_chat/ rewrite + ModelBehaviorError retry).
When no-tools-called retries are exhausted, the model output may contain
raw tool-call JSON (e.g. {name: read_file, ...}) or be empty.
Replace these with a clear user-facing message instead.
- Add _sanitize_ungrounded_output() to detect and replace raw JSON/empty
- Apply in both run_with_retry and arun_with_retry exhaustion paths
- Add 7 tests for sanitize behavior (80 adapter tests total)
- Document minimum model requirements based on live testing
Live test results:
qwen2.5-coder:14b — was returning raw JSON, now returns clear message
gemma4:12b — grounded answer (nudge retry works)
qwen3.5:397b-cloud — grounded answer (no retries needed)
- Add 'Minimum Model Requirements' section to ollama_tool_call_adapter.md
covering both add (low reqs) and query/chat (higher reqs) workloads
- Update tested models table with latest results including instability
notes for gemma4:12b and sanitize fallback for qwen2.5-coder:14b
- Update test counts (80 adapter, 1148 total)
- Cross-reference between the two docs
- No personal/test data in any commit
Minimum model requirements (documented in docs/ollama_tool_call_adapter.md)
OpenKB has two workloads with different LLM requirements:
add (ingestion) — direct LLM completion, no tool-calling needed. Models ≥12B work reliably.
query / chat — multi-step tool-calling loop (model must call read_file, process results, produce grounded answer). Requires strong instruction-following capability.
Model
Size
add
query
Notes
qwen3.5 (cloud)
397B
✅ stable
✅ grounded
Stable across all runs
gemma4
12B
✅
⚠️ unstable
Grounded answer on some runs; "could not retrieve" on others
qwen2.5-coder
14B
✅
❌
Model ignores nudge retries; sanitize returns clear message
Sanitize fallback (new)
When no-tools retries are exhausted, raw JSON or empty output is replaced with:
"I could not find relevant information in the knowledge base. The available tools were not used successfully. Try rephrasing your question or adding more documents."
Recommendations
For query/chat: use general-purpose models (gemma4, qwen3), not code-focused (qwen2.5-coder)
For slow hardware: ollama.timeout: 600 or higher
12B models may produce different results between runs — consider fixing temperature/seed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Complements PR #210 — adds a no-tools-called retry for local Ollama models (12-14B) that return a final answer without calling any tools.
Problem
After PR #210 fixed the
ollama/→ollama_chat/rewrite andModelBehaviorErrorretry, testing with local models revealed a second failure mode:qwen2.5-coder:14b(local):addworks (227s), butqueryreturns "I cannot find relevant information" — the model didn't callread_filegemma4:12b(local):queryreturns empty output""The KB is correctly built (wiki, concepts, entities all present), but the model doesn't initiate tool calls during query — it answers directly without reading wiki files.
This is a model capability limitation, not a transport bug. The adapter cannot force a model to call tools, but it can nudge it.
Fix
After
Runner.run()completes successfully, the adapter checksresult.new_itemsfor anyToolCallItem. If the agent has tools but none were called, the adapter retries with an escalating nudge message:Attempt 1 (gentle):
Attempt 2 (firm):
Attempt 3 (final):
If all retries are exhausted, the adapter returns the last (ungrounded) answer — no infinite loops.
Interaction with PR #210
This PR includes all changes from PR #210 (ollama_chat/ rewrite, ModelBehaviorError retry, parameterized timeouts, drop_params, api_base propagation) plus the no-tools-called retry. The two retry mechanisms share the same
tool_call_retriesbudget.Testing
Files Changed
openkb/agent/ollama_adapter.py_has_tool_calls(),_build_nudge_message(),_append_nudge(), no-tools retry looptests/test_ollama_adapter.pydocs/ollama_no_tools_retry.mdConfiguration
Same
ollama:config block as PR #210:Limitations
"") may not benefit if the empty output is caused by a timeout or inference failure.ModelBehaviorErrorretries.