langchain-ai / langchain-aws

Build LangChain Applications on AWS
MIT License
71 stars 53 forks source link

raise TypeError( TypeError: Additional kwargs key generation_token_count already exists in left dict and value has unsupported type <class 'int'> #107

Closed Sai-Jahnavi-Bachu closed 2 days ago

Sai-Jahnavi-Bachu commented 2 weeks ago

from langchain.agents import AgentExecutor, create_tool_calling_agent, tool from langchain_aws import ChatBedrock from langchain_core.prompts import ChatPromptTemplate

prompt = ChatPromptTemplate.from_messages( [ ("system", "You are a helpful assistant"), ("placeholder", "{chat_history}"), ("human", "{input}"), ("placeholder", "{agent_scratchpad}"), ] ) model = ChatBedrock( model_id="meta.llama3-70b-instruct-v1:0" )

@tool def magic_function(input: int) -> int: """Applies a magic function to an input.""" return input + 2

tools = [magic_function]

agent = create_tool_calling_agent(model, tools, prompt) agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

agent_executor.invoke({"input": "what is the value of magic_function(3)?"})

Error Message and Stack Trace (if applicable)

File "/MVP/mvp/lib/python3.12/site-packages/langchain_core/messages/ai.py", line 243, in add response_metadata = merge_dicts( ^^^^^^^^^^^^ File "/MVP/mvp/lib/python3.12/site-packages/langchain_core/utils/_merge.py", line 40, in merge_dicts raise TypeError( TypeError: Additional kwargs key generation_token_count already exists in left dict and value has unsupported type <class 'int'>.

Description

I am trying out the example from the langchain website and it is giving me error as TypeError: Additional kwargs key generation_token_count already exists in left dict and value has unsupported type <class 'int'>.

I cannot solve the error, and don't understand it. can you please resolve it?

System Info

langchain==0.2.6 langchain-aws==0.1.9 langchain-community==0.2.6 langchain-core==0.2.11 langchain-text-splitters==0.2.2 Mac Python 3.12

MasciocchiReply commented 1 week ago

I'm in a similar situation, if you use "create_tool_calling_agent(...)", I think you should use "ChatBedrockConverse", instead of "ChatBedrock". But at the moment it gives me this error: "This model doesn't support tool use in streaming mode."