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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user