Skip to content

fix: add configurable tool count validation to prevent empty AI responses - #7

Open
lireno wants to merge 1 commit into
mainfrom
fix/tool-count-validation
Open

fix: add configurable tool count validation to prevent empty AI responses#7
lireno wants to merge 1 commit into
mainfrom
fix/tool-count-validation

Conversation

@lireno

@lireno lireno commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Fixes aipotheosis-labs#337 — validate_tool_count() with SERVER_AGENT_MAX_TOOLS config, early 400 error, 10 unit tests. Improves on PR aipotheosis-labs#604.

…nses (aipotheosis-labs#337)

Add MAX_TOOLS validation in the /chat route and openai_chat_stream to
prevent cryptic OpenAI API errors when too many functions are selected.
OpenAI's Responses API has undocumented limits (~128 tools or ~200k
tokens of tool definitions). Exceeding them returns an unhelpful APIError
that surfaces as a 500, causing empty AI responses.

Improvements over PR aipotheosis-labs#604:
- MAX_TOOLS is configurable via SERVER_AGENT_MAX_TOOLS env var (default 64)
- Error message lists affected app names so users know which apps to disable
- Error message mentions the env var so operators can adjust the limit
- Error message truncates long app lists (>10 apps)
- Added unit tests for validate_tool_count covering under/at/over limit,
  app name extraction, env var reference, and empty tools edge case

Closes aipotheosis-labs#337
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

AI returns empty response when multiple GMAIL functions are selected

1 participant