这是indexloc提供的服务,不要输入任何密码
Skip to content

[Error ]: Chapter 5 Custom Tools Example - DuckDuckGo not returning 2025 data #93

@ksparkKJE

Description

@ksparkKJE

Describe the bug

Hello, ben
When running the example from Chapter 5 (Custom Tools), I encountered an error with "state_modifier". After making a minor modification, I was able to fix the error, but it seems that DuckDuckGo is no longer able to fetch data for 2025. Could you please update the example code?

/chapter5/custom_tools.ipynb

from langchain_community.tools import DuckDuckGoSearchRun

search = DuckDuckGoSearchRun()
question = "What is a square root of the current US president’s age multiplied by 132?"

system_hint = "Think step-by-step. Always use search to get the fresh information about events or public facts that can change over time. Now is 2025 and remember president elections in the US recently happened."

agent = create_react_agent(
    llm, [calculator, search],
    state_modifier=system_hint)

for event in agent.stream({"messages": [("user", question)]}, stream_mode="values"):
    event["messages"][-1].pretty_print()
----------------------------------------------------------------------------
TypeError: create_react_agent() got an unexpected keyword argument 'state_modifier'

[Modified Code]

from langchain_community.tools import DuckDuckGoSearchRun

search = DuckDuckGoSearchRun()
question = "What is a square root of the current US president's age multiplied by 132?"
system_hint = "Think step-by-step. Always use search to get the fresh information about events or public facts that can change over time. Now is 2025 and remember president elections in the US recently happened."

messages = [
    ("system", system_hint),
    ("user", question)
]

agent = create_react_agent(
    llm, [calculator, search]
)
for event in agent.stream({"messages": messages}, stream_mode="values"):
    event["messages"][-1].pretty_print()

print(event["messages"][-1].content)
================================ Human Message =================================

What is a square root of the current US president's age multiplied by 132?
================================== Ai Message ==================================
Tool Calls:
  duckduckgo_search (160a4ef0-dcdf-46fe-8529-9048bf3ee298)
 Call ID: 160a4ef0-dcdf-46fe-8529-9048bf3ee298
  Args:
    query: current US president age
================================= Tool Message =================================
Name: duckduckgo_search

Aug 7, 2023 · current,作名词译为(水,气,电)流;趋势;作形容词译为现在的;流通的。 读音:英[ˈkʌrənt],美[ˈkɜːrənt]。 释义: adj.现在的;流通的,通用的;最近的;草写的。 n.( … 3 days ago · January 16, 2025 The St Helena government tested the feasibility, reliability and adaptability of electric vehicle use on one of the most remote inhabited islands on the planet. … Apr 21, 2011 · Espero alguien pueda ayudarme con una traducción más exacta por "current balance" que se define en este caso así : The previous day's ending balance, plus or minus … current,present,recent在表示形容词性的时候发生的时间不同、词性不同、在句型中用法不同。 一、表示形容词性的时候,表示发生的时间不同 1、current指目前存在和发生的。 2、recent … 请问为什么电压的英文是voltage,缩写却是u,而电流英文是current,缩写是I?通常物理量和该量的单位符号使用的字母是不同的。物理量的单位符号一般使用发明(发现)该物理量的科学家的姓 …
C:\Anaconda3\envs\langchain-book\Lib\site-packages\langchain_community\utilities\duckduckgo_search.py:63: RuntimeWarning: This package (`duckduckgo_search`) has been renamed to `ddgs`! Use `pip install ddgs` instead.
  with DDGS() as ddgs:
================================== Ai Message ==================================

I cannot find the current US president's age. To calculate the square root of the current US president's age multiplied by 132, I need to know the president's age first. Once I have that information, I can use the calculator to find the answer.

Steps to reproduce

No response

Expected behavior

No response

Actual behavior

No response

Branch

None

Branch name

No response

Operating System

No response

Dependency management

No response

Python version

No response

LangChain version

No response

LLM Used

No response

Model used

No response

Additional context

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions