fix: omit tools param entirely when empty instead of sending None (#3820)

Some providers (Fireworks AI) reject tools=null, and others (Anthropic)
reject tools=[]. The safest approach is to not include the key at all
when there are no tools — the OpenAI SDK treats a missing parameter as
NOT_GIVEN and omits it from the request entirely.

Inspired by PR #3736 (@kelsia14).
This commit is contained in:
Teknium
2026-03-29 16:12:47 -07:00
committed by GitHub
parent 252fbea005
commit 68d5472810

View File

@@ -4721,9 +4721,10 @@ class AIAgent:
api_kwargs = {
"model": self.model,
"messages": sanitized_messages,
"tools": self.tools if self.tools else None,
"timeout": float(os.getenv("HERMES_API_TIMEOUT", 1800.0)),
}
if self.tools:
api_kwargs["tools"] = self.tools
if self.max_tokens is not None:
api_kwargs.update(self._max_tokens_param(self.max_tokens))