googleapis / python-aiplatform

A Python SDK for Vertex AI, a fully managed, end-to-end platform for data science and machine learning.
Apache License 2.0
643 stars 348 forks source link

Finish reason: 9. Finish message: Malformed function call: #4472

Open b0noI opened 1 month ago

b0noI commented 1 month ago

Environment details

Steps to reproduce

git clone git@github.com:GeminiAgentsToolkit/gemini-agents-toolkit.git pip install -r ./requirements.txt python ./examples/investing_pipeline_example.py

run the code several times, on some day it works almost all the time, today it was working 2 out of 10 times only T_T

output example:

Retrying send_message... Attempt #1, Last error: The model response did not complete successfully.
Finish reason: 9.
Finish message: Malformed function call:
print(28 > 30)
.
Safety ratings: [].
To protect the integrity of the chat session, the request and response were not added to chat history.
To skip the response validation, specify `model.start_chat(response_validation=False)`.
Note that letting blocked or otherwise incomplete responses into chat history might lead to future interactions being blocked by the service.
Retrying send_message... Attempt #1, Last error: The model response did not complete successfully.
Finish reason: 9.
Finish message: Malformed function call:
price = 121.3 * 1.04
print(default_api.set_limit_sell_order(price=price))
.
Safety ratings: [].
To protect the integrity of the chat session, the request and response were not added to chat history.
To skip the response validation, specify `model.start_chat(response_validation=False)`.
Note that letting blocked or otherwise incomplete responses into chat history might lead to future interactions being blocked by the service.
Retrying send_message... Attempt #2, Last error: The model response did not complete successfully.
Finish reason: 9.
Finish message: Malformed function call:
print(157.3 * 1.04)
.
Safety ratings: [].
To protect the integrity of the chat session, the request and response were not added to chat history.
To skip the response validation, specify `model.start_chat(response_validation=False)`.
Note that letting blocked or otherwise incomplete responses into chat history might lead to future interactions being blocked by the service.
Traceback (most recent call last):
  File "/Users/vkovalevskyi/miniforge3/envs/toolbox/lib/python3.12/site-packages/tenacity/__init__.py", line 478, in __call__
    result = fn(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^
  File "/Users/vkovalevskyi/src/gemini-toolbox/gemini_agents_toolkit/agent.py", line 201, in send_message
    response = self.chat.send_message(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/vkovalevskyi/miniforge3/envs/toolbox/lib/python3.12/site-packages/vertexai/generative_models/_generative_models.py", line 1165, in send_message
    return self._send_message(
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/vkovalevskyi/miniforge3/envs/toolbox/lib/python3.12/site-packages/vertexai/generative_models/_generative_models.py", line 1293, in _send_message
    self._response_validator(
  File "/Users/vkovalevskyi/miniforge3/envs/toolbox/lib/python3.12/site-packages/vertexai/generative_models/_generative_models.py", line 1070, in _validate_response
    raise ResponseValidationError(
vertexai.generative_models._generative_models.ResponseValidationError: The model response did not complete successfully.
Finish reason: 9.
Finish message: Malformed function call:
print(157.3 * 1.04)
.
Safety ratings: [].
To protect the integrity of the chat session, the request and response were not added to chat history.
To skip the response validation, specify `model.start_chat(response_validation=False)`.
Note that letting blocked or otherwise incomplete responses into chat history might lead to future interactions being blocked by the service.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/vkovalevskyi/src/gemini-toolbox/./examples/investing_pipeline_example.py", line 103, in <module>
    pipeline.step("set limit sell order for TQQQ for price +4% of current price", history=history)
  File "/Users/vkovalevskyi/src/gemini-toolbox/gemini_agents_toolkit/pipeline/eager_pipeline.py", line 55, in step
    self.prev_step_data = agent_to_use.send_message(prompt)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/vkovalevskyi/miniforge3/envs/toolbox/lib/python3.12/site-packages/tenacity/__init__.py", line 336, in wrapped_f
    return copy(f, *args, **kw)
           ^^^^^^^^^^^^^^^^^^^^
  File "/Users/vkovalevskyi/miniforge3/envs/toolbox/lib/python3.12/site-packages/tenacity/__init__.py", line 475, in __call__
    do = self.iter(retry_state=retry_state)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/vkovalevskyi/miniforge3/envs/toolbox/lib/python3.12/site-packages/tenacity/__init__.py", line 376, in iter
    result = action(retry_state)
             ^^^^^^^^^^^^^^^^^^^
  File "/Users/vkovalevskyi/miniforge3/envs/toolbox/lib/python3.12/site-packages/tenacity/__init__.py", line 419, in exc_check
    raise retry_exc from fut.exception()
tenacity.RetryError: RetryError[<Future at 0x10c6313d0 state=finished raised ResponseValidationError>]
b0noI commented 1 month ago

any updates?

b0noI commented 1 month ago

please use this commit for reproduction: https://github.com/GeminiAgentsToolkit/gemini-agents-toolkit/commit/c2abef95b78097c3f9e969b38fa8549d9a0a4771

in the more latest version I have remediated this with the hack (prompt that explains to the backend how NOT to call functions :) )

Ark-kun commented 1 month ago

Hello. I will forward your issue to the model quality team. The SDK cannot do anything here since the model response and the erro comes from the backend.

Finish message: Malformed function call:
print(157.3 * 1.04)

As you see, to solve your question, the model generated the following "function call": print(157.3 * 1.04), but it wasn't calling any function, just doing multiplication.

To reduce cases like this you can try using tool_config to force function calling. When using forced function calling there are additional constraint decoding features enabled that can reduce/eliminate the probability of invalid function call. https://github.com/googleapis/python-aiplatform/pull/3534