Skip to content

Tool calling issue with Amazon Nova models caused by stop sequence behavior #420

Open
@aristsakpinis93

Description

@aristsakpinis93

Tool calling issue with Amazon Nova models caused by stop sequence behavior

Background

When using the LangChain ReAct agent implementation with Amazon Nova models, there are inconsistencies in handling stop sequences compared to other LLMs (e.g., Claude), affecting tool calling capabilities.

Current Behavior

  • LangChain ReAct agent uses ["\nObservation"] as a stop sequence when calling a model
  • The aim is to prohibit the model from continued generation. The fields Action and Action Input can then used to call the right tool with the right input (see below in example)
  • Nova models include the stop sequence itself in their output, while other models do not. The LangChain implementation is expecting a behavior like the latter.
  • This causes issues with the standard ReAct pattern implementation, particularly affecting:
    • Tool calling completion
    • Final answer generation
    • Observation handling

Example

When using the standard ReAct prompt pattern prompt:

Answer the following questions as best you can. You have access to the following tools:

tool(input1: data_type) -> data_type - description
Use the following format:

Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [...tools...]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question

Begin!

Question: ...
Thought:
Nova Pro output:
Thought: [thought process]
Action: [action]
Action Input: [input]
Observation:  # <-- Stop sequence included

Claude output (expected by LC):
Thought: [thought process]
Action: [action]
Action Input: [input]
# <-- No stop sequence included

This can be replicated by using the following prompt:

Answer the following questions as best you can. You have access to the following tools:

calculate_total_cost(num_days: int) -> int - Calculates the total cost for the trip. Returns the cost in dollars

Use the following format:

Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [calculate_total_cost]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question

Begin!

Question: How much will a 10 day trip cost?
Thought:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions