Deep Agents can be seen as DeepResearch produced by the LangChain team. This section tests whether Deep Agents has the ability to actively invoke search and gain deep insights by querying recent news.
This is just a quick start. For more information, please visit the official website!
# !pip install deepagents dashscope1. Load Model¶
import os
import dashscope
from datetime import datetime
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from langchain.tools import tool
from deepagents import create_deep_agent
from dashscope import Generation
# Load model configuration
_ = load_dotenv()
# Configure api_key for DashScope
dashscope.api_key=os.getenv("DASHSCOPE_API_KEY")
# Load model
llm = ChatOpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url=os.getenv("DASHSCOPE_BASE_URL"),
model="qwen3-max",
)2. Create Search Tool¶
We use the dashscope_search search tool created in the previous section.
@tool
def dashscope_search(query: str) -> str:
"""Search the internet using Quark Search API"""
response = Generation.call(
model='qwen-max',
prompt=query,
enable_search=True,
result_format='message'
)
if response.status_code == 200:
return response.output.choices[0].message.content
else:
return (
"Search failed with status code: "
f"{response.status_code}, message: {response.message}"
)3. Create Deep Agent¶
# System prompt to steer the agent to be an expert researcher
research_instructions = """You are a senior researcher. Your job is to conduct comprehensive and in-depth research, and write a concise report.
You can use the internet search tool as the primary way to gather information.
## `dashscope_search`
Use this tool to search the internet for the specified query.
"""
@tool
def get_today_date() -> str:
"""Get today's date"""
return datetime.now().strftime("%Y-%m-%d")
agent = create_deep_agent(
model=llm,
tools=[dashscope_search, get_today_date],
system_prompt=research_instructions
)4. Run Agent¶
Our question is:
Who is the newly appointed President of Bolivia? Please introduce this president.Because recently (November 8, 2025) the Bolivian President Rodrigo Paz Pereira just took office, this information is definitely not in the pre-training data. This question can be used to verify whether Deep Agents actually connects to the internet.
result = agent.invoke({"messages": [
{"role": "user", "content": "Who is the newly appointed President of Bolivia? Please introduce this president."}
]})
# Final response
print(result["messages"][-1].content)# President Luis Arce of Bolivia
As of my latest information, **Luis Arce** is the current President of Bolivia, having taken office on November 8, 2020. There has been no newly appointed president in 2024.
## Background and Biography
**Luis Arce Catacora** was born on January 27, 1963, in La Paz, Bolivia, into a middle-class family—his father was a teacher and his mother a homemaker.
### Education and Early Career
- Studied economics at Universidad Mayor de San Andrés (UMSA) in La Paz
- Later pursued advanced studies in economic development and public finance
- Worked as an economic advisor for international organizations including the UNDP and Inter-American Development Bank
### Political Rise
- Appointed Minister of Economy and Public Finance by President Evo Morales in 2006
- Served in this role until 2019, implementing policies that reduced poverty and promoted economic growth
- Played a key role in nationalizing Bolivia's natural gas industry, which became a major government revenue source
- Went into exile in Mexico following the 2019 political crisis that led to Morales' resignation
- Returned to Bolivia in 2020 to run for president
### Presidency
- Won the October 18, 2020 general election with over 55% of the vote as the Movement for Socialism (MAS) party candidate
- Became the 67th President of Bolivia on November 8, 2020
- Primary focus has been on economic recovery following the COVID-19 pandemic and 2019 political turmoil
- Continues social programs aimed at reducing poverty and improving living standards
- Working to rebuild Bolivia's international relationships through cooperation and dialogue
### Personal Life
- Married to María Fernanda Arrieta
- Has two children
His presidency represents continuity with many policies from the Morales era while addressing contemporary challenges facing Bolivia.
# Thinking process
for message in result["messages"]:
message.pretty_print()================================ Human Message =================================
Who is the newly appointed President of Bolivia? Please introduce this president.
================================== Ai Message ==================================
I'll help you find information about the newly appointed President of Bolivia. Let me search for the most current information.
Tool Calls:
dashscope_search (call_76c9b6fb13124056bedb0c2d)
Call ID: call_76c9b6fb13124056bedb0c2d
Args:
query: newly appointed President of Bolivia 2024
================================= Tool Message =================================
Name: dashscope_search
As of my last update in October 2023, there is no newly appointed President of Bolivia for the year 2024. The current president of Bolivia is Luis Arce, who took office on November 8, 2020.
For the most up-to-date information, please check the latest news sources or official government announcements. If there have been any recent changes or elections, they would be covered in those sources.
================================== Ai Message ==================================
Based on my search, there is no newly appointed President of Bolivia in 2024. The current president of Bolivia is **Luis Arce**, who has been serving since November 8, 2020.
Let me provide you with more information about President Luis Arce:
Tool Calls:
dashscope_search (call_ab5801cebb864207a3ebdb49)
Call ID: call_ab5801cebb864207a3ebdb49
Args:
query: Luis Arce Bolivia president biography background
================================= Tool Message =================================
Name: dashscope_search
Luis Arce Catacora, born on January 27, 1963, in La Paz, Bolivia, is a Bolivian economist and politician who has served as the President of Bolivia since November 8, 2020. Here is a brief overview of his background and biography:
### Early Life and Education
- **Early Life**: Luis Arce was born into a middle-class family in La Paz. His father was a teacher, and his mother was a homemaker.
- **Education**: He studied economics at the Universidad Mayor de San Andrés (UMSA) in La Paz, where he earned his bachelor's degree. He later pursued further studies in economic development and public finance.
### Professional Career
- **Economic Advisor**: Before entering politics, Arce worked as an economic advisor for various international organizations, including the United Nations Development Programme (UNDP) and the Inter-American Development Bank (IDB).
- **Minister of Economy and Public Finance**: In 2006, he was appointed as the Minister of Economy and Public Finance by then-President Evo Morales. During his tenure, he implemented several economic policies aimed at reducing poverty and inequality, and promoting economic growth.
- **Economic Policies**: Under his leadership, Bolivia experienced significant economic growth, with GDP increasing and poverty rates declining. He also played a key role in nationalizing the country's natural gas industry, which became a major source of revenue for the government.
### Political Career
- **Evo Morales' Administration**: Arce was a close ally of Evo Morales and served in his administration from 2006 to 2019. He was instrumental in formulating and implementing the economic policies that characterized Morales' time in office.
- **Exile and Return**: Following the political crisis in 2019, which led to the resignation of Evo Morales, Arce went into exile in Mexico along with other members of the Morales administration. He returned to Bolivia in 2020 to run for president.
### Presidential Campaign and Election
- **Presidential Candidacy**: In 2020, Arce was nominated as the presidential candidate for the Movement for Socialism (MAS) party, which had been founded by Evo Morales.
- **Election**: In the general election held on October 18, 2020, Arce won a decisive victory, securing more than 55% of the vote. He took office on November 8, 2020, becoming the 67th President of Bolivia.
### Presidency
- **Economic Recovery**: One of Arce's primary goals as president has been to stabilize and recover the economy, which had been affected by the COVID-19 pandemic and the political turmoil of 2019.
- **Social Policies**: He has continued to focus on social programs aimed at reducing poverty and improving the standard of living for Bolivians.
- **International Relations**: Arce has sought to rebuild Bolivia's relationships with other countries and international organizations, emphasizing the importance of cooperation and dialogue.
### Personal Life
- **Family**: Luis Arce is married to María Fernanda Arrieta, and they have two children.
Luis Arce's presidency has been marked by efforts to maintain the economic and social gains achieved during the Morales era while addressing new challenges, such as the ongoing impact of the global pandemic and the need for political stability.
================================== Ai Message ==================================
# President Luis Arce of Bolivia
As of my latest information, **Luis Arce** is the current President of Bolivia, having taken office on November 8, 2020. There has been no newly appointed president in 2024.
## Background and Biography
**Luis Arce Catacora** was born on January 27, 1963, in La Paz, Bolivia, into a middle-class family—his father was a teacher and his mother a homemaker.
### Education and Early Career
- Studied economics at Universidad Mayor de San Andrés (UMSA) in La Paz
- Later pursued advanced studies in economic development and public finance
- Worked as an economic advisor for international organizations including the UNDP and Inter-American Development Bank
### Political Rise
- Appointed Minister of Economy and Public Finance by President Evo Morales in 2006
- Served in this role until 2019, implementing policies that reduced poverty and promoted economic growth
- Played a key role in nationalizing Bolivia's natural gas industry, which became a major government revenue source
- Went into exile in Mexico following the 2019 political crisis that led to Morales' resignation
- Returned to Bolivia in 2020 to run for president
### Presidency
- Won the October 18, 2020 general election with over 55% of the vote as the Movement for Socialism (MAS) party candidate
- Became the 67th President of Bolivia on November 8, 2020
- Primary focus has been on economic recovery following the COVID-19 pandemic and 2019 political turmoil
- Continues social programs aimed at reducing poverty and improving living standards
- Working to rebuild Bolivia's international relationships through cooperation and dialogue
### Personal Life
- Married to María Fernanda Arrieta
- Has two children
His presidency represents continuity with many policies from the Morales era while addressing contemporary challenges facing Bolivia.