fix: add tool count validation with env-configurable MAX_TOOLS - #3
Closed
lireno wants to merge 1 commit into
Closed
Conversation
Prevents cryptic 'There was an issue with your request' errors from OpenAI's API when too many functions are selected (e.g., enabling all Gmail functions in the playground). Changes: - Add MAX_TOOLS=64 default in config.py, overridable via SERVER_MAX_TOOLS - Add ToolCountExceeded exception with actionable 400 response - Add early validation in /chat route before any API call is made - Add defensive warning log in openai_chat_stream for other call-sites - Add comprehensive tests for exception, config, and /chat endpoint Closes aipotheosis-labs#337 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes aipotheosis-labs#337 — prevents cryptic OpenAI API errors when too many functions are selected (e.g., enabling all Gmail functions in the playground).
This is a cleaner, improved version of PR aipotheosis-labs#604 that adds env-var configurability, better error messaging, and comprehensive tests.
What changed
Core changes
Improvements over PR aipotheosis-labs#604
Why this fix works
Validates tool count before making the API call. Returns a 400 with a clear message telling users to reduce selected functions. The default limit of 64 is conservative — the actual OpenAI limit is closer to 128 or ~200k tokens of tool definitions, but this provides a safe margin.
Risk assessment
Closes aipotheosis-labs#337