crewAI: Using openAI chat.completion as a tool raises openai.APIError: The model produced invalid content. Consider modifying your prompt if you are seeing this error persistently
I am trying to use small summarizer as a tool for my task. But at the > Entering new CrewAgentExecutor chain…
I am getting provided error 8 of 10 times (which is also weird):
Traceback (most recent call last):
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/BSP/test.py", line 85, in <module>
result = legal_crew.run()
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/BSP/Crews/LegalCrews.py", line 42, in run
result = crew.kickoff()
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/crewai/crew.py", line 264, in kickoff
result = self._run_sequential_process()
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/crewai/crew.py", line 305, in _run_sequential_process
output = task.execute(context=task_output)
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/crewai/task.py", line 183, in execute
result = self._execute(
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/crewai/task.py", line 192, in _execute
result = agent.execute_task(
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/crewai/agent.py", line 236, in execute_task
result = self.agent_executor.invoke(
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/langchain/chains/base.py", line 163, in invoke
raise e
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/langchain/chains/base.py", line 153, in invoke
self._call(inputs, run_manager=run_manager)
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/crewai/agents/executor.py", line 128, in _call
next_step_output = self._take_next_step(
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/langchain/agents/agent.py", line 1138, in _take_next_step
[
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/langchain/agents/agent.py", line 1138, in <listcomp>
[
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/crewai/agents/executor.py", line 192, in _iter_next_step
output = self.agent.plan( # type: ignore # Incompatible types in assignment (expression has type "AgentAction | AgentFinish | list[AgentAction]", variable has type "AgentAction")
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/langchain/agents/agent.py", line 397, in plan
for chunk in self.runnable.stream(inputs, config={"callbacks": callbacks}):
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/langchain_core/runnables/base.py", line 2875, in stream
yield from self.transform(iter([input]), config, **kwargs)
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/langchain_core/runnables/base.py", line 2862, in transform
yield from self._transform_stream_with_config(
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/langchain_core/runnables/base.py", line 1881, in _transform_stream_with_config
chunk: Output = context.run(next, iterator) # type: ignore
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/langchain_core/runnables/base.py", line 2826, in _transform
for output in final_pipeline:
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/langchain_core/runnables/base.py", line 1282, in transform
for ichunk in input:
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/langchain_core/runnables/base.py", line 4736, in transform
yield from self.bound.transform(
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/langchain_core/runnables/base.py", line 1300, in transform
yield from self.stream(final, config, **kwargs)
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py", line 249, in stream
raise e
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py", line 229, in stream
for chunk in self._stream(messages, stop=stop, **kwargs):
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/langchain_openai/chat_models/base.py", line 408, in _stream
for chunk in self.client.create(messages=message_dicts, **params):
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/openai/_streaming.py", line 46, in __iter__
for item in self._iterator:
File "/home/lapups/pycharmProjects/LAWrence-PoC/code/lawrence_poc/.venv/lib/python3.10/site-packages/openai/_streaming.py", line 72, in __stream__
raise APIError(
openai.APIError: The model produced invalid content. Consider modifying your prompt if you are seeing this error persistently.
Upade using the Claude 3 models as a tool also raises the same error
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 21
Possibly – but I’ve been using gpt4o for several weeks now. The issues just started in the last 24-48hrs. Possible that OpenAI changed something on their end as well
Seeing this same issue as well, using
It seems like gpt-4o is more strict regarding function calling. Could it be how crewai is passing function to the API?
I have a sequence of 3 seemingly simple agents and 3 seemingly simple tasks with one agent per task. The program seems to randomly fail on different agents in the sequence on different runs with:
openai.APIError: The model produced invalid content. Consider modifying your prompt if you are seeing this error persistently.
Update: I consistently get this error when using the agents with model ‘gpt-4o’. However, changing the agent’s model to ‘gpt-3.5-turbo’ all works well. And progresses through the sequence much faster.