KeyError: 'chart_generator' when i run multi-agent-collaboration.ipynb with gpt-3.5-turbo-1106 #87

Closed
opened 2026-02-20 17:25:22 -05:00 by yindo · 1 comment
Owner

Originally created by @chuangzhidan on GitHub (May 13, 2024).

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.

Example Code

llm = ChatOpenAI(model="gpt-3.5-turbo-1106")
i used aboved instead of gpt4 like the one showed in the example script ,everything else is the same.

Error Message and Stack Trace (if applicable)

{'Researcher': {'messages': [AIMessage(content='I have gathered the GDP data for the UK over the past 5 years. Here are the GDP values for each year:\n\n- 2017: $2,622.43 billion\n- 2018: $2,651.38 billion\n- 2019: $2,636.29 billion\n- 2020: $2,663.99 billion\n- 2
021: $3,141.51 billion\n\nI will now proceed to create a line graph to visualize this data.', additional_kwargs={'tool_calls': [{'id': 'call_xXe0sgFx0bVlUYOKUhh8p02Q', 'function': {'arguments': '{\n "data": {\n "x": ["2017", "2018", "2019", "2020", "2021"],\n
"y": [2622.43, 2651.38, 2636.29, 2663.99, 3141.51]\n },\n "type": "line",\n "title": "UK GDP Over the Past 5 Years",\n "xLabel": "Year",\n "yLabel": "GDP (in billion USD)"\n}', 'name': 'chart_generator'}, 'type': 'function'}]}, response_metadata={'token_us
age': {'completion_tokens': 220, 'prompt_tokens': 12216, 'total_tokens': 12436}, 'model_name': 'gpt-3.5-turbo-1106', 'system_fingerprint': None, 'finish_reason': 'tool_calls', 'logprobs': None}, name='Researcher', id='run-cb9ac178-2b55-4aa4-9a14-c9adeb6582ba-0', t
ool_calls=[{'name': 'chart_generator', 'args': {'data': {'x': ['2017', '2018', '2019', '2020', '2021'], 'y': [2622.43, 2651.38, 2636.29, 2663.99, 3141.51]}, 'type': 'line', 'title': 'UK GDP Over the Past 5 Years', 'xLabel': 'Year', 'yLabel': 'GDP (in billion USD)'
output = self.tools_by_name[call["name"]].invoke(call["args"], config)
KeyError: 'chart_generator'

KeyError: 'chart_generator'

Description

it always failed the halfway,whichi is really annoying

System Info

langchainhub 0.1.15
langchain 0.1.17
langchain-text-splitters 0.0.1
langchain-openai 0.1.1
langchain-experimental 0.0.58
langchain-core 0.1.52
langchain-community 0.0.37

Originally created by @chuangzhidan on GitHub (May 13, 2024). ### Checked other resources - [X] I added a very descriptive title to this issue. - [X] I searched the LangChain documentation with the integrated search. - [X] I used the GitHub search to find a similar question and didn't find it. - [X] I am sure that this is a bug in LangChain rather than my code. ### Example Code **llm = ChatOpenAI(model="gpt-3.5-turbo-1106") i used aboved instead of gpt4 like the one showed in the example script ,everything else is the same.** ### Error Message and Stack Trace (if applicable) {'Researcher': {'messages': [AIMessage(content='I have gathered the GDP data for the UK over the past 5 years. Here are the GDP values for each year:\n\n- 2017: $2,622.43 billion\n- 2018: $2,651.38 billion\n- 2019: $2,636.29 billion\n- 2020: $2,663.99 billion\n- 2 021: $3,141.51 billion\n\nI will now proceed to create a line graph to visualize this data.', additional_kwargs={'tool_calls': [{'id': 'call_xXe0sgFx0bVlUYOKUhh8p02Q', 'function': {'arguments': '{\n "data": {\n "x": ["2017", "2018", "2019", "2020", "2021"],\n "y": [2622.43, 2651.38, 2636.29, 2663.99, 3141.51]\n },\n "type": "line",\n "title": "UK GDP Over the Past 5 Years",\n "xLabel": "Year",\n "yLabel": "GDP (in billion USD)"\n}', 'name': 'chart_generator'}, 'type': 'function'}]}, response_metadata={'token_us age': {'completion_tokens': 220, 'prompt_tokens': 12216, 'total_tokens': 12436}, 'model_name': 'gpt-3.5-turbo-1106', 'system_fingerprint': None, 'finish_reason': 'tool_calls', 'logprobs': None}, name='Researcher', id='run-cb9ac178-2b55-4aa4-9a14-c9adeb6582ba-0', t ool_calls=[{'name': 'chart_generator', 'args': {'data': {'x': ['2017', '2018', '2019', '2020', '2021'], 'y': [2622.43, 2651.38, 2636.29, 2663.99, 3141.51]}, 'type': 'line', 'title': 'UK GDP Over the Past 5 Years', 'xLabel': 'Year', 'yLabel': 'GDP (in billion USD)' output = self.tools_by_name[call["name"]].invoke(call["args"], config) KeyError: 'chart_generator' **KeyError: 'chart_generator'** ### Description **it always failed the halfway,whichi is really annoying** ### System Info langchainhub 0.1.15 langchain 0.1.17 langchain-text-splitters 0.0.1 langchain-openai 0.1.1 langchain-experimental 0.0.58 langchain-core 0.1.52 langchain-community 0.0.37
yindo closed this issue 2026-02-20 17:25:22 -05:00
Author
Owner

@hinthornw commented on GitHub (May 13, 2024):

If your model is hallucinating tools, then either update your prompt to reduce the frequency of such hallucinations, or add a fallback to handle errors like this an have it automatically handle afterwards.

The fallback would basically be to append a tool message with the invocation's ID saying that you as the bot don't have access. An example of this is in the customer support bot tutorial: https://langchain-ai.github.io/langgraph/tutorials/customer-support/customer-support/#utilities

@hinthornw commented on GitHub (May 13, 2024): If your model is hallucinating tools, then either update your prompt to reduce the frequency of such hallucinations, or add a fallback to handle errors like this an have it automatically handle afterwards. The fallback would basically be to append a tool message with the invocation's ID saying that you as the bot don't have access. An example of this is in the customer support bot tutorial: https://langchain-ai.github.io/langgraph/tutorials/customer-support/customer-support/#utilities
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#87