[langchain]: Update the tool execution loop example on how to call the tools after model returns the tolls list

Open Beginner friendly
#5,949 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
82/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
documentation

Research direction

Open the Models page linked in the issue and locate the tool loop execution example. Read the section around Step 2 and update the example so it handles the returned tool call name before invoking get_weather. Done means the documentation accurately reflects how to execute the listed tool calls without changing the surrounding workflow.

Written by the indexing model from the issue text.

Description

external langchain
Type of issue

issue / bug

Language

Python

Description

There is an issue in the documentation for Tool calling in Models Page. Under tool loop execution, the model on invoke it returns the tool calls that has to be executed. But in the example, it is calling the get_weather tool without checking if the tool call name is get_weather.


# Step 2: Execute tools and collect results
for tool_call in ai_msg.tool_calls:
    # Execute the tool with the generated arguments
    tool_result = get_weather.invoke(tool_call)
    messages.append(tool_result)

But it should check before calling the tool and it should be something like:


# Step 2: Execute tools and collect results
for tool_call in ai_msg.tool_calls:
    # Execute the tool with the generated arguments
    if tool_call["name"] == "get_weather": 
       tool_result = get_weather.invoke(tool_call)
    messages.append(tool_result)
Dominant language
MDX
Stars
418
Forks
2.7k
Avg merge
1d 6h
Merged PRs (30d)
351

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from langchain-ai/docs

All issues in langchain-ai/docs

Similar issues

More Documentation issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.