examples/cookbook_drive_guide.ipynb
In this cookbook, we will demonstrate how to query the distance between two locations and create a driving plan using an agent.
We will use Qwen-Agent in this book. For demonstration, we will need at least the mcp functionality of Qwen-Agent.
!pip3 install -U "qwen-agent[gui,rag,code_interpreter,mcp]"
# `pip install -U qwen-agent` will install the minimal requirements.
# The optional requirements, specified in double brackets, are:
# [gui] for Gradio-based GUI support;
# [rag] for RAG support;
# [code_interpreter] for Code Interpreter support;
# [mcp] for MCP support.
Create an agent that is capable of utilizing map functionalities provided by Amap.
An api key for Amap is needed, instructions are at https://lbs.amap.com/api/mcp-server/summary
from qwen_agent.agents import Assistant
from qwen_agent.utils.output_beautify import typewriter_print
# `typewriter_print` prints streaming messages in a non-overlapping manner for a clear view.
llm_cfg = {
'model': 'qwen3-32b',
'model_server': 'dashscope',
'api_key': '' # **fill your dashscope api key here**
# Use a model service compatible with the OpenAI API, such as vLLM or Ollama:
# 'model': 'Qwen3-8B',
# 'model_server': 'http://localhost:8000/v1', # base_url, also known as api_base
# 'api_key': 'EMPTY'
}
tools = [
{
"mcpServers": {
# enumeration of mcp server configs
"amap-amap-sse": {
"url": "https://mcp.amap.com/sse?key=YOUR_KEY" # **fill your amap mcp key**
}
}
}
]
agent = Assistant(
llm=llm_cfg,
function_list=tools
)
We can query the distance between two locations by prompting the agent, which will then provide an answer utilizing the MCP server.
query = "How far is it between Zhejiang University (more specifically, the Zijingang Campus) and Hangzhou Xiaoshan airport?"
messages = [{'role': 'user', 'content': query}]
response_plain_text = ''
for ret_messages in agent.run(messages):
response_plain_text = typewriter_print(ret_messages, response_plain_text)
messages += ret_messages # extending the context with new `ret_messages`.
We can create a drive plan by asking follow-up questions, and the agent will generate the plan for us.
messages += [{'role': 'user', 'content': 'Okay, how can i drive?'}]
response_plain_text = ''
for ret_messages in agent.run(messages):
response_plain_text = typewriter_print(ret_messages, response_plain_text)
We have explored the capabilities of the Qwen-Agent framework and Qwen models in providing travel suggestions. We can also achieve this by using the GUI.
from qwen_agent.gui import WebUI
agent = Assistant(
name="Qwen Guide",
description="I can help with your travel needs, ask me anything!",
llm=llm_cfg,
function_list=tools
)
WebUI(agent).run()