Skip to content

[Agent|Engine] Give the agent only to models that can call tools - #2150

Merged
CREDO23 merged 2 commits into
devfrom
feat/agent-tool-support-check
Oct 2, 2026
Merged

CREDO23 merged 2 commits into
devfrom
feat/agent-tool-support-check

Conversation

@CREDO23

@CREDO23 CREDO23 commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • A new thread is the agent's only when the selected model is tested (or the developer switch is on) and is known to call tools: llama-server reports supports_tool_calls for a local model's template, or the remote catalog records tool_call: true under the connection's catalog provider. Unknown or unreadable counts as no, and the thread opens as a chat.
  • agent_answers is renamed selected_model_can_run_agent, after what it decides.
  • A turn sent to an agent thread after the selected model changes to one that fails the check is refused with 409 before any prompt is sent. A thread left with no model still gets the existing "no chat model selected" answer.
  • llama.cpp capabilities now read supports_tool_calls beside supports_tools: a template can render tools while llama-server parses none of its calls.
  • Tests: test_engine_choice.py covers each case against the real catalog and a stand-in llama-server; the agent-thread fixture now selects gpt-4o-mini (catalog provider openai), and a new test checks the send-time refusal.
  • Docs: agent.md, chat.md, 01-which-engine.md and the proposal README. The old Known gap is gone; a new one records that the composer shows the refusal as an error rather than offering a new thread.

Follows #2135

High-level PR Summary

This PR modifies the agent engine selection logic to ensure only models that can actually call tools are assigned to agent threads. It adds checks for both local models (via llama-server's supports_tool_calls capability) and remote models (via catalog's tool_call field), preventing the agent from being assigned to models that would fail to execute tool calls. The change includes runtime validation that refuses turns sent to agent threads when the selected model changes to one without tool-calling support.

⏱️ Estimated Review Time: 15-30 minutes

💡 Review Order Suggestion
Order File Path
1 surfsense_local/backend/modules/llm/providers/llamacpp/capabilities.py
2 surfsense_local/backend/modules/agent/engine_choice.py
3 surfsense_local/backend/modules/agent/agent_threads/turn.py
4 surfsense_local/backend/modules/chat/router.py
5 surfsense_local/backend/tests/integration/agent/conftest.py
6 surfsense_local/backend/tests/integration/agent/test_agent_threads.py
7 surfsense_local/backend/tests/integration/agent/test_engine_choice.py
8 surfsense_local/backend/tests/unit/llm/test_system_role.py
9 docs/proposals/agent/01-which-engine.md
10 docs/architecture/agent.md
11 docs/architecture/chat.md
12 docs/proposals/agent/README.md

Need help? Join our Discord

@vercel

vercel Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
surf-sense-frontend Error Error Oct 2, 2026 3:36pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 2, 2026

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Repository: MODSetter/SurfSense/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 6a37f051-eeb6-4777-931a-fd7307301a7d

📥 Commits

Reviewing files that changed from the base of the PR and between 4dc375e and 59949ad.

📒 Files selected for processing (12)
  • docs/architecture/agent.md
  • docs/architecture/chat.md
  • docs/proposals/agent/01-which-engine.md
  • docs/proposals/agent/README.md
  • surfsense_local/backend/modules/agent/agent_threads/turn.py
  • surfsense_local/backend/modules/agent/engine_choice.py
  • surfsense_local/backend/modules/chat/router.py
  • surfsense_local/backend/modules/llm/providers/llamacpp/capabilities.py
  • surfsense_local/backend/tests/integration/agent/conftest.py
  • surfsense_local/backend/tests/integration/agent/test_agent_threads.py
  • surfsense_local/backend/tests/integration/agent/test_engine_choice.py
  • surfsense_local/backend/tests/unit/llm/test_system_role.py
 __________________________________________
< Performing energy-intensive code review. >
 ------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@CREDO23
CREDO23 merged commit 7ca2cb9 into dev Oct 2, 2026
21 of 24 checks passed

This branch had an error being deployed

1 failed deployment
Preview — 59949ad0 Deployed Oct 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant