Repository: langchain
Issue: ReAct agent fail to correctly use multiple custom tools
Labels: 🤖:bug

### 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

# Attempt with `@tool` decorator
```python
from random_word import RandomWords

from langchain_core.tools import tool
from langchain_ollama.chat_models import ChatOllama
from langgraph.prebuilt import create_react_agent
from typing import Any, Dict


@tool(parse_docstring=True)
def generate_random_word_decorator() -> int:
  """
  Generate a random word.

  Returns:
    str: The generated random word.
  """
  r = RandomWords()
  word = r.get_random_word()
  print(f"Generated random word: {word}")
  return word

@tool(parse_docstring=True)
def construct_sentence_decorator(word: str) -> str:
  """
  Construct a sentence using the given word.

  Args:
    word: The word to use in the sentence (str).

  Returns:
    str: The constructed sentence.
  """
  sentence = f"The word is {word}."
  print(f"Constructed sentence: {sentence}")
  return sentence

print("Validate tools...")
validation_word = generate_random_word_decorator.invoke(input={})
validation_sentence = construct_sentence_decorator.invoke(input={"word": validation_word})
print(f"Generated word: {validation_word}")
print(f"Constructed sentence: {validation_sentence}")

@tool(parse_docstring=True)
def agent(state: dict) -> Dict[str, Any]:
  """
  An agent that construct a sentence using a random word.

  Args:
    state: The state of the agent calling this tool.
  """
  model = ChatOllama(
    model="llama3.2",
    temperature=0,
    base_url="http://localhost:11434"
  )
  tools = [generate_random_word_decorator, construct_sentence_decorator]
  binded_tools = model.bind_tools(tools)
  agent = create_react_agent(model=binded_tools, tools=tools)

  answer = agent.invoke(
    {
      "messages": [
        (
          "human",
          f"You're an agent, and has been given {state}, you must construct a sentence using a random word.",
        ),
      ],
    }
  )
  return answer

print("Validate agent...")
agent_message = agent.invoke(input={"state": {}})
print(f"Agent message: {agent_message}")
```
---
# Alternative with `BaseTool` Class

```python
from random_word import RandomWords

from langchain_ollama.chat_models import ChatOllama
from langgraph.prebuilt import create_react_agent
from typing import Any, Dict
from langchain_core.tools import BaseTool

class GenerateRandomWordClass(BaseTool):
    name: str = "generate_random_word_class"
    description: str = "Generate a random word without any input."
    response_format: str = "content"

    def _run(self) -> str:
        r = RandomWords()
        word = r.get_random_word()
        print(f"Generated random word: {word}")
        return word
    
class ConstructSentenceClass(BaseTool):
    name: str = "construct_sentence_class"
    description: str = "Construct a sentence using the word [word]."
    response_format: str = "content"

    def _run(self, word: str) -> str:
        sentence = f"The word is {word}."
        print(f"Constructed sentence: {sentence}")
        return sentence
    
print("Validate tools...")
rand_word = GenerateRandomWordClass()
word = rand_word.invoke(input={})
rand_sentence = ConstructSentenceClass()
sentence = rand_sentence.invoke(input={"word": word})
print(f"Generated word: {word}")
print(f"Constructed sentence: {sentence}")

@tool(parse_docstring=True)
def agent_class(state: dict) -> Dict[str, Any]:
  """
  An agent that construct a sentence using a random word.

  Args:
    state: The state of the agent calling this tool.
  """
  model = ChatOllama(
    model="llama3.2",
    temperature=0,
    base_url="http://localhost:11434"
  )
  generate_word_class = GenerateRandomWordClass()
  construct_sentence_class = ConstructSentenceClass()

  tools = [generate_word_class, construct_sentence_class]
  binded_tools = model.bind_tools(tools)
  agent = create_react_agent(model=binded_tools, tools=tools)

  answer = agent.invoke(
    {
      "messages": [
        (
          "human",
          f"You're an agent, and has been given {state}, you must construct a sentence using a random word.",
        ),
      ],
    }
  )
  return answer

print("Validate agent...")
agent_message = agent_class.invoke(input={"state": {}})
print(f"Agent message: {agent_message}")
```

---
## Jupyter notebook

Use this Jupyter notebook:
https://gist.github.com/DucretJe/8b453d6867ef4afec4e30e37f0265c3a

(outputs are included)

### Error Message and Stack Trace (if applicable)

No errors

### Description

I'm trying to create a reAct agent with multiple **custom** tools.

I declare it with the `@tool` decorator or a `BaseTool` Class.
The model is binded with the tools and the agent is created with the tools declared.

The 2 tools are bounded:
1st is standalone (in the example it allows to generate a random word)
2nd needs a string as an input, which is the output of the 1st tool.

The agent always fails to use the tools correctly, depending on the model used, it may use the first tool but will fail to use its output as an input of the 2nd tool.

### System Info

System Information
------------------
> OS:  Darwin
> OS Version:  Darwin Kernel Version 24.1.0: Thu Oct 10 21:05:23 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6031
> Python Version:  3.13.0 (main, Oct  7 2024, 05:02:14) [Clang 16.0.0 (clang-1600.0.26.3)]

Package Information
-------------------
> langchain_core: 0.3.22
> langchain: 0.3.10
> langsmith: 0.1.147
> langchain_ollama: 0.2.1
> langchain_text_splitters: 0.3.2
> langgraph_sdk: 0.1.43

Optional packages not installed
-------------------------------
> langserve

Other Dependencies
------------------
> aiohttp: 3.11.10
> async-timeout: Installed. No version info available.
> httpx: 0.27.2
> jsonpatch: 1.33
> langsmith-pyo3: Installed. No version info available.
> numpy: 2.1.3
> ollama: 0.4.4
> orjson: 3.10.12
> packaging: 24.2
> pydantic: 2.10.3
> PyYAML: 6.0.2
> requests: 2.32.3
> requests-toolbelt: 1.0.0
> SQLAlchemy: 2.0.36
> tenacity: 9.0.0
> typing-extensions: 4.12.2
multi-tool