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]"
|
"[dim]Type /help for commands, /quit to exit.[/dim]"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
_flags: dict = {"use_tools": True}
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
user_input = session.prompt("› ").strip()
|
user_input = session.prompt("› ").strip()
|
||||||
@@ -226,7 +228,7 @@ def start_chat() -> None:
|
|||||||
history.add_user(user_input)
|
history.add_user(user_input)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response_text = _call_ai(cfg, history, registry, executor)
|
response_text = _call_ai(cfg, history, registry, executor, _flags)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
render_error(f"AI error: {exc}")
|
render_error(f"AI error: {exc}")
|
||||||
history._messages.pop()
|
history._messages.pop()
|
||||||
@@ -244,6 +246,7 @@ def _call_ai(
|
|||||||
history: ConversationHistory,
|
history: ConversationHistory,
|
||||||
registry: PluginRegistry,
|
registry: PluginRegistry,
|
||||||
executor: ToolExecutor,
|
executor: ToolExecutor,
|
||||||
|
flags: dict | None = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
from pyra.vault.reader import get_key
|
from pyra.vault.reader import get_key
|
||||||
|
|
||||||
@@ -272,8 +275,9 @@ def _call_ai(
|
|||||||
for t in tools
|
for t in tools
|
||||||
]
|
]
|
||||||
|
|
||||||
# No plugins active — use streaming (original behavior)
|
# No tools active, or provider known not to support function calling
|
||||||
if not tools_spec:
|
use_tools = flags is None or flags.get("use_tools", True)
|
||||||
|
if not tools_spec or not use_tools:
|
||||||
stream = litellm.completion(
|
stream = litellm.completion(
|
||||||
**base_kwargs,
|
**base_kwargs,
|
||||||
messages=history.build_for_api(),
|
messages=history.build_for_api(),
|
||||||
@@ -304,6 +308,8 @@ def _call_ai(
|
|||||||
return render_text_response("Error: tool-use loop exceeded maximum iterations.")
|
return render_text_response("Error: tool-use loop exceeded maximum iterations.")
|
||||||
|
|
||||||
except litellm.BadRequestError:
|
except litellm.BadRequestError:
|
||||||
|
if flags is not None:
|
||||||
|
flags["use_tools"] = False
|
||||||
render_info("This model does not support function calling — tools disabled.")
|
render_info("This model does not support function calling — tools disabled.")
|
||||||
stream = litellm.completion(
|
stream = litellm.completion(
|
||||||
**base_kwargs,
|
**base_kwargs,
|
||||||
|
|||||||
Reference in New Issue
Block a user