Repository: langchain
Issue: TypeError: Additional kwargs key total_tokens already exists in left dict and value has unsupported type <class 'decimal.Decimal'>.
Labels: 🤖:bug,investigate

### 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.
- [X] The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

### Example Code

The error is thrown while using long conversations on Claude models. This is how the model is invoked:

```
conversation = RunnableWithMessageHistory(
            chain,
            lambda session_id: self.chat_history,
            history_messages_key="chat_history",
            input_messages_key="input",
            output_messages_key="output",
        )
        
for chunk in conversation.stream(
                    input={"input": user_prompt}, config=config
                ):
                    logger.debug("chunk", chunk=chunk)
                    if "answer" in chunk:
                        answer = answer + chunk["answer"]
                    elif isinstance(chunk, AIMessageChunk):
                        for c in chunk.content:
                            if "text" in c:
                                answer = answer + c.get("text")
```

### Error Message and Stack Trace (if applicable)

```
    "stack_trace": {
        "type": "TypeError",
        "value": "Additional kwargs key total_tokens already exists in left dict and value has unsupported type <class 'decimal.Decimal'>.",
        "module": "builtins",
        "frames": [
            {
                "file": "/var/task/adapters/base/base.py",
                "line": 183,
                "function": "run_with_chain_v2",
                "statement": "for chunk in conversation.stream("
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 5525,
                "function": "stream",
                "statement": "yield from self.bound.stream("
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 5525,
                "function": "stream",
                "statement": "yield from self.bound.stream("
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 3407,
                "function": "stream",
                "statement": "yield from self.transform(iter([input]), config, **kwargs)"
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 3394,
                "function": "transform",
                "statement": "yield from self._transform_stream_with_config("
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 2197,
                "function": "_transform_stream_with_config",
                "statement": "chunk: Output = context.run(next, iterator)  # type: ignore"
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 3357,
                "function": "_transform",
                "statement": "yield from final_pipeline"
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 5561,
                "function": "transform",
                "statement": "yield from self.bound.transform("
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 4820,
                "function": "transform",
                "statement": "yield from self._transform_stream_with_config("
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 2197,
                "function": "_transform_stream_with_config",
                "statement": "chunk: Output = context.run(next, iterator)  # type: ignore"
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 4800,
                "function": "_transform",
                "statement": "for chunk in output.stream("
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 5525,
                "function": "stream",
                "statement": "yield from self.bound.stream("
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 3407,
                "function": "stream",
                "statement": "yield from self.transform(iter([input]), config, **kwargs)"
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 3394,
                "function": "transform",
                "statement": "yield from self._transform_stream_with_config("
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 2197,
                "function": "_transform_stream_with_config",
                "statement": "chunk: Output = context.run(next, iterator)  # type: ignore"
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 3357,
                "function": "_transform",
                "statement": "yield from final_pipeline"
            },
            {
                "file": "/opt/python/langchain_core/runnables/passthrough.py",
                "line": 576,
                "function": "transform",
                "statement": "yield from self._transform_stream_with_config("
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 2197,
                "function": "_transform_stream_with_config",
                "statement": "chunk: Output = context.run(next, iterator)  # type: ignore"
            },
            {
                "file": "/opt/python/langchain_core/runnables/passthrough.py",
                "line": 555,
                "function": "_transform",
                "statement": "for chunk in for_passthrough:"
            },
            {
                "file": "/opt/python/langchain_core/utils/iter.py",
                "line": 61,
                "function": "tee_peer",
                "statement": "item = next(iterator)"
            },
            {
                "file": "/opt/python/langchain_core/runnables/passthrough.py",
                "line": 576,
                "function": "transform",
                "statement": "yield from self._transform_stream_with_config("
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 2197,
                "function": "_transform_stream_with_config",
                "statement": "chunk: Output = context.run(next, iterator)  # type: ignore"
            },
            {
                "file": "/opt/python/langchain_core/runnables/passthrough.py",
                "line": 566,
                "function": "_transform",
                "statement": "yield cast(dict[str, Any], first_map_chunk_future.result())"
            },
            {
                "file": "/var/lang/lib/python3.11/concurrent/futures/_base.py",
                "line": 456,
                "function": "result",
                "statement": "return self.__get_result()"
            },
            {
                "file": "/var/lang/lib/python3.11/concurrent/futures/_base.py",
                "line": 401,
                "function": "__get_result",
                "statement": "raise self._exception"
            },
            {
                "file": "/var/lang/lib/python3.11/concurrent/futures/thread.py",
                "line": 58,
                "function": "run",
                "statement": "result = self.fn(*self.args, **self.kwargs)"
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 3847,
                "function": "transform",
                "statement": "yield from self._transform_stream_with_config("
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 2197,
                "function": "_transform_stream_with_config",
                "statement": "chunk: Output = context.run(next, iterator)  # type: ignore"
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 3832,
                "function": "_transform",
                "statement": "chunk = AddableDict({step_name: future.result()})"
            },
            {
                "file": "/var/lang/lib/python3.11/concurrent/futures/_base.py",
                "line": 449,
                "function": "result",
                "statement": "return self.__get_result()"
            },
            {
                "file": "/var/lang/lib/python3.11/concurrent/futures/_base.py",
                "line": 401,
                "function": "__get_result",
                "statement": "raise self._exception"
            },
            {
                "file": "/var/lang/lib/python3.11/concurrent/futures/thread.py",
                "line": 58,
                "function": "run",
                "statement": "result = self.fn(*self.args, **self.kwargs)"
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 5561,
                "function": "transform",
                "statement": "yield from self.bound.transform("
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 1431,
                "function": "transform",
                "statement": "yield from self.stream(final, config, **kwargs)"
            },
            {
                "file": "/opt/python/langchain_core/runnables/branch.py",
                "line": 367,
                "function": "stream",
                "statement": "for chunk in self.default.stream("
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 3407,
                "function": "stream",
                "statement": "yield from self.transform(iter([input]), config, **kwargs)"
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 3394,
                "function": "transform",
                "statement": "yield from self._transform_stream_with_config("
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 2197,
                "function": "_transform_stream_with_config",
                "statement": "chunk: Output = context.run(next, iterator)  # type: ignore"
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 3357,
                "function": "_transform",
                "statement": "yield from final_pipeline"
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 1413,
                "function": "transform",
                "statement": "for ichunk in input:"
            },
            {
                "file": "/opt/python/langchain_core/output_parsers/transform.py",
                "line": 64,
                "function": "transform",
                "statement": "yield from self._transform_stream_with_config("
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 2161,
                "function": "_transform_stream_with_config",
                "statement": "final_input: Optional[Input] = next(input_for_tracing, None)"
            },
            {
                "file": "/opt/python/langchain_core/runnables/base.py",
                "line": 1431,
                "function": "transform",
                "statement": "yield from self.stream(final, config, **kwargs)"
            },
            {
                "file": "/opt/python/langchain_core/language_models/chat_models.py",
                "line": 365,
                "function": "stream",
                "statement": "BaseMessageChunk, self.invoke(input, config=config, stop=stop, **kwargs)"
            },
            {
                "file": "/opt/python/langchain_core/language_models/chat_models.py",
                "line": 286,
                "function": "invoke",
                "statement": "self.generate_prompt("
            },
            {
                "file": "/opt/python/langchain_core/language_models/chat_models.py",
                "line": 786,
                "function": "generate_prompt",
                "statement": "return self.generate(prompt_messages, stop=stop, callbacks=callbacks, **kwargs)"
            },
            {
                "file": "/opt/python/langchain_core/language_models/chat_models.py",
                "line": 643,
                "function": "generate",
                "statement": "raise e"
            },
            {
                "file": "/opt/python/langchain_core/language_models/chat_models.py",
                "line": 633,
                "function": "generate",
                "statement": "self._generate_with_cache("
            },
            {
                "file": "/opt/python/langchain_core/language_models/chat_models.py",
                "line": 851,
                "function": "_generate_with_cache",
                "statement": "result = self._generate("
            },
            {
                "file": "/opt/python/langchain_aws/chat_models/bedrock_converse.py",
                "line": 491,
                "function": "_generate",
                "statement": "bedrock_messages, system = _messages_to_bedrock(messages)"
            },
            {
                "file": "/opt/python/langchain_aws/chat_models/bedrock_converse.py",
                "line": 685,
                "function": "_messages_to_bedrock",
                "statement": "messages = merge_message_runs(messages)"
            },
            {
                "file": "/opt/python/langchain_core/messages/utils.py",
                "line": 381,
                "function": "wrapped",
                "statement": "return func(messages, **kwargs)"
            },
            {
                "file": "/opt/python/langchain_core/messages/utils.py",
                "line": 571,
                "function": "merge_message_runs",
                "statement": "merged.append(_chunk_to_msg(last_chunk + curr_chunk))"
            },
            {
                "file": "/opt/python/langchain_core/messages/ai.py",
                "line": 395,
                "function": "__add__",
                "statement": "return add_ai_message_chunks(self, other)"
            },
            {
                "file": "/opt/python/langchain_core/messages/ai.py",
                "line": 412,
                "function": "add_ai_message_chunks",
                "statement": "additional_kwargs = merge_dicts("
            },
            {
                "file": "/opt/python/langchain_core/utils/_merge.py",
                "line": 58,
                "function": "merge_dicts",
                "statement": "merged[right_k] = merge_dicts(merged[right_k], right_v)"
            },
            {
                "file": "/opt/python/langchain_core/utils/_merge.py",
                "line": 68,
                "function": "merge_dicts",
                "statement": "raise TypeError(msg)"
            }
        ]
    }
```

### Description

I am getting the this error when the conversation becomes lengthy and while using RAG flow. I am using the `anthropic.claude-3-5-sonnet-20240620-v1:0` model

Following are the versions of langchain libraries:
```
langchain==0.3.13
langchain-core==0.3.28
langchain-community==0.3.13
```


### System Info

```
System Information
------------------
> OS:  Linux
> OS Version:  #1 SMP Mon Oct 28 22:41:53 UTC 2024
> Python Version:  3.11.10 (main, Sep 24 2024, 11:02:55) [GCC 7.3.1 20180712 (Red Hat 7.3.1-17)]
Package Information
-------------------
> langchain_core: 0.3.28
> langchain: 0.3.13
> langchain_community: 0.3.13
> langsmith: 0.2.10
> langchain_aws: 0.2.10
> langchain_openai: 0.2.14
> langchain_text_splitters: 0.3.4
Optional packages not installed
-------------------------------
> langserve
Other Dependencies
------------------
> aiohttp: 3.11.11
> async-timeout: Installed. No version info available.
> boto3: 1.34.145
> dataclasses-json: 0.6.7
> httpx: 0.28.1
> httpx-sse: 0.4.0
> jsonpatch: 1.33
> langsmith-pyo3: Installed. No version info available.
> numpy: 1.26.0
> openai: 1.59.3
> orjson: 3.10.13
> packaging: 24.2
> pydantic: 2.10.4
> pydantic-settings: 2.7.1
> PyYAML: 6.0.2
> requests: 2.31.0
> requests-toolbelt: 1.0.0
> SQLAlchemy: 2.0.36
> tenacity: 9.0.0
> tiktoken: 0.8.0
> typing-extensions: 4.12.2
> zstandard: Installed. No version info available.
System Information
------------------
> OS:  Linux
> OS Version:  #1 SMP Mon Oct 28 22:41:53 UTC 2024
> Python Version:  3.11.10 (main, Sep 24 2024, 11:02:55) [GCC 7.3.1 20180712 (Red Hat 7.3.1-17)]
Package Information
-------------------
> langchain_core: 0.3.28
> langchain: 0.3.13
> langchain_community: 0.3.13
> langsmith: 0.2.10
> langchain_aws: 0.2.10
> langchain_openai: 0.2.14
> langchain_text_splitters: 0.3.4
Optional packages not installed
-------------------------------
> langserve
Other Dependencies
------------------
> aiohttp: 3.11.11
> async-timeout: Installed. No version info available.
> boto3: 1.34.145
> dataclasses-json: 0.6.7
> httpx: 0.28.1
> httpx-sse: 0.4.0
> jsonpatch: 1.33
> langsmith-pyo3: Installed. No version info available.
> numpy: 1.26.0
> openai: 1.59.3
> orjson: 3.10.13
> packaging: 24.2
> pydantic: 2.10.4
> pydantic-settings: 2.7.1
> PyYAML: 6.0.2
> requests: 2.31.0
> requests-toolbelt: 1.0.0
> SQLAlchemy: 2.0.36
> tenacity: 9.0.0
> tiktoken: 0.8.0
> typing-extensions: 4.12.2
> zstandard: Installed. No version info available.
```