简介
项目地址:https://github.com/Shubhamsaboo/awesome-llm-apps
项目介绍:集合多种不同场景不同模型下Agent智能体Demo,今天主要看travel_agent
主要功能:travel agent是一个使用streamlit框架做前端展示,agno框架做的Agent,主要用于旅游规划,主要看下agno框架做Agent的主要逻辑,从中找到一些Agent的灵感和思路
解析
主要定义了两个Agent,Researcher和Planner
Researcher用于搜索网络查询相关信息:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
researcher = Agent(
name="Researcher",
role="Searches for travel destinations, activities, and accommodations based on user preferences",
model=OpenAIChat(id="gpt-4o", api_key=openai_api_key),
description=dedent(
"""\
You are a world-class travel researcher. Given a travel destination and the number of days the user wants to travel for, generate a list of search terms for finding relevant travel activities and accommodations. Then search the web for each term, analyze the results, and return the 10 most relevant results. """ ),
instructions=[
"Given a travel destination and the number of days the user wants to travel for, first generate a list of 3 search terms related to that destination and the number of days.",
"For each search term, `search_google` and analyze the results."
"From the results of all searches, return the 10 most relevant results to the user's preferences.",
"Remember: the quality of the results is important.",
],
tools=[SerpApiTools(api_key=serp_api_key)],
add_datetime_to_instructions=True,
)
|
Panner基于Researcher的结果给出规划结果
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
planner = Agent(
name="Planner",
role="Generates a draft itinerary based on user preferences and research results",
model=OpenAIChat(id="gpt-4o", api_key=openai_api_key),
description=dedent(
"""\
You are a senior travel planner. Given a travel destination, the number of days the user wants to travel for, and a list of research results, your goal is to generate a draft itinerary that meets the user's needs and preferences. """ ),
instructions=[
"Given a travel destination, the number of days the user wants to travel for, and a list of research results, generate a draft itinerary that includes suggested activities and accommodations.",
"Ensure the itinerary is well-structured, informative, and engaging.",
"Ensure you provide a nuanced and balanced itinerary, quoting facts where possible.",
"Remember: the quality of the itinerary is important.",
"Focus on clarity, coherence, and overall quality.",
"Never make up facts or plagiarize. Always provide proper attribution.",
],
add_datetime_to_instructions=True,
)
|
控制流也非常简单:Start->Researcher->Planner->End
两个Agent都使用了gpt-4o模型,
下面重点看下ango框架下Agent的定义和使用
ango是一个构建Agent/多Agent系统的python框架,主要提供了记忆、知识、推理、多Agent合作等能力封装,关于ango的具体介绍留在之后展开
针对这个具体案例,可以看到定义Agent使用了几个关键的字段name
, role
, description
, instructions
, add_datetime_toinstructions
, tools
等,这与之前gemeni构建的research agent构建提示词的理念基本相同
对于Researcher Agent,ango最终生成的prompt是:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
system:
You are a world-class travel researcher. Given a travel destination and the number of days the user wants to travel for,
generate a list of search terms for finding relevant travel activities and accommodations.
Then search the web for each term, analyze the results, and return the 10 most relevant results.
<your_role>
Searches for travel destinations, activities, and accommodations based on user preferences
</your_role>
<instructions>
- Given a travel destination and the number of days the user wants to travel for, first generate a list of 3 search terms related to that destination and the number of days.
- For each search term, `search_google` and analyze the results.From the results of all searches, return the 10 most relevant results to the user's preferences.
- Remember: the quality of the results is important.
</instructions>
<additional_information>
- The current time is 2025-06-29 10:07:40.611535.
</additional_information>
|
ango帮拼装的Agent提示词基本上按照传入的参数进行的拼装
- 角色信息:主要定义角色职能
- 任务描述:简单描述任务要求
- 任务指令:分条介绍任务的约束要求
- 附加信息:将当前时间等信息放到附加信息中
总结
- Agent框架承载很多Agent设计范式:使用ango等框架工具可以很简单的构建一个Agent,类似的其他一些框架比如CrewAI, AutoGen, LangGraph等等,这些框架的设计思路都很好的使用Agentic的思路范式
- 提示词的设计:对提示词几个基本内容大家的理解基本一致的,角色定义、任务描述、任务指令几部分描述基本都要包含,任务指令列表的形式逐条说明约束,一般会将当前时间等信息以附加信息或者任务指令的方式放到提示词中帮助llm理解基本信息
- 大模型擅长做基于主题的探索:我们看到的两个Agent智能体都在做基于主题的探索,探索类的问题有几个关键特点
- 主要是总结:基于网络上的信息进行总结,总结后根据要求输出结果
- 有一定创造性:不是严谨的推断,更多的是看模型对内容的理解
- 没有明确的对错之分:看到不同的信息,做不同的总结,得到的信息可能不一样,实际的问题的答案域里也不会有非黑即白的答案,这给了llm很大的发挥空间