-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Gemini Api 400 Invalid Argument Error #2241
Comments
Hi @AkhilmsAchu |
Hi @dirkbrnd , master = Agent( |
These are my findings after debugging the Gemini request parameters. `Content(parts=[Part(video_metadata=None, thought=None, code_execution_result=None, executable_code=None, file_data=None, function_call=None, function_response=None, inline_data=None, text='Could not find function to call.')], role='user'), Content(parts=[], role='tool')` These are the last 2 elements in formatted_messages before gemini started throwing the error. In gemini.py file, adding these lines to skip items with role = tool and not having tool_calls attributes (after line no : 432 in _format_messages fn) fixed the issue temporarily for me.
I'm not sure whether this a proper fix. Maybe this will give you a hint to the real problem. |
Skip messages with role 'tool' and no tool_calls attribute while formating messages for gemini This apparently fixes the error agno-agi#2241
@AkhilmsAchu the issue comes where Gemini makes an invalid tool call, we should just let it know that, but instead we send invalid payload. |
I found an alternative way to fix, I'll post a PR |
@dirkbrnd thankyou for addressing the issue. Hope it will be released soon 🤞 |
## Description There is a breaking issue when Gemini makes an incorrect function call. Fixes #2241 --- ## Type of change Please check the options that are relevant: - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Model update (Addition or modification of models) - [ ] Other (please describe): --- ## Checklist - [ ] Adherence to standards: Code complies with Agno’s style guidelines and best practices. - [ ] Formatting and validation: You have run `./scripts/format.sh` and `./scripts/validate.sh` to ensure code is formatted and linted. - [ ] Self-review completed: A thorough review has been performed by the contributor(s). - [ ] Documentation: Docstrings and comments have been added or updated for any complex logic. - [ ] Examples and guides: Relevant cookbook examples have been included or updated (if applicable). - [ ] Tested in a clean environment: Changes have been tested in a clean environment to confirm expected behavior. - [ ] Tests (optional): Tests have been added or updated to cover any new or changed functionality. --- ## Additional Notes Include any deployment notes, performance implications, security considerations, or other relevant information (e.g., screenshots or logs if applicable).
Description
This error just pops up very randomly.
Couldn't find function to call due to error from Gemini Api
Error from Gemini API: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Please use a valid role: user,
model.', 'status': 'INVALID_ARGUMENT'}}
Steps to Reproduce
List the steps needed to encounter this bug or issue.
Expected Behavior
It should have called the right tool
Actual Behavior
Getting Exception and tool call failed
Screenshots or Logs (if applicable)
Sorry i had to trim logs due to privacy concerns😅
DEBUG **************** METRICS ****************
DEBUG * Input tokens: 772
DEBUG * Output tokens: 28
DEBUG * Total tokens: 800
DEBUG * Time: 2.4601s
DEBUG * Tokens per second: 11.3815 tokens/s
DEBUG **************** METRICS ******************
DEBUG ============== user ==============
DEBUG Could not find function to call.
DEBUG ============== tool ==============
ERROR Error from Gemini API: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Please use a valid role: user,
model.', 'status': 'INVALID_ARGUMENT'}}
WARNING Attempt 1/1 failed: <Response [400]>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.venv\Lib\site-packages\agno\agent\agent.py", line 885, in run
raise Exception(
Exception: Failed after 1 attempts. Last error using Gemini(gemini-2.0-flash-001): <Response [400]>
Xxxxxxxxxx.venv\Lib\site-packages\agno\models\google\gemini.py", line 334, in invoke
raise ModelProviderError(
agno.exceptions.ModelProviderError: <Response [400]>
Environment
Possible Solutions (optional)
Suggest any ideas you might have to fix or address the issue.
Additional Context
Master agent is having a slave agent with multiple tools.
The text was updated successfully, but these errors were encountered: