fix(chat): show "tools disabled" info message only once per session

When a local model rejects function calling (BadRequestError), the flag
is set in a session-scoped dict so subsequent messages skip the tool-use
path entirely — no repeated info message on every turn.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
curo1305
2026-05-19 00:18:11 +02:00
parent bf29ffc7d8
commit 1cf7bdf908
+9 -3
View File
@@ -176,6 +176,8 @@ def start_chat() -> None:
"[dim]Type /help for commands, /quit to exit.[/dim]"
)
_flags: dict = {"use_tools": True}
while True:
try:
user_input = session.prompt(" ").strip()
@@ -226,7 +228,7 @@ def start_chat() -> None:
history.add_user(user_input)
try:
response_text = _call_ai(cfg, history, registry, executor)
response_text = _call_ai(cfg, history, registry, executor, _flags)
except Exception as exc:
render_error(f"AI error: {exc}")
history._messages.pop()
@@ -244,6 +246,7 @@ def _call_ai(
history: ConversationHistory,
registry: PluginRegistry,
executor: ToolExecutor,
flags: dict | None = None,
) -> str:
from pyra.vault.reader import get_key
@@ -272,8 +275,9 @@ def _call_ai(
for t in tools
]
# No plugins active — use streaming (original behavior)
if not tools_spec:
# No tools active, or provider known not to support function calling
use_tools = flags is None or flags.get("use_tools", True)
if not tools_spec or not use_tools:
stream = litellm.completion(
**base_kwargs,
messages=history.build_for_api(),
@@ -304,6 +308,8 @@ def _call_ai(
return render_text_response("Error: tool-use loop exceeded maximum iterations.")
except litellm.BadRequestError:
if flags is not None:
flags["use_tools"] = False
render_info("This model does not support function calling — tools disabled.")
stream = litellm.completion(
**base_kwargs,