Spaces:
Runtime error
Runtime error
add a tour guide agent
Browse files- .DS_Store +0 -0
- agents/tour_guide_agent.py +58 -0
- app.py +29 -12
- prompts_mas.ymal +38 -0
.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
agents/tour_guide_agent.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# agents/tour_guide_agent.py
|
2 |
+
from smolagents import CodeAgent
|
3 |
+
from typing import Dict, List, Optional, Any
|
4 |
+
|
5 |
+
class TourGuideAgent(CodeAgent):
|
6 |
+
"""
|
7 |
+
The Tour Guide Agent specializes in finding popular tourist destinations
|
8 |
+
for a given location using web search.
|
9 |
+
"""
|
10 |
+
|
11 |
+
def __init__(
|
12 |
+
self,
|
13 |
+
model,
|
14 |
+
tools=None,
|
15 |
+
managed_agents=None,
|
16 |
+
prompt_templates=None,
|
17 |
+
planning_interval=None,
|
18 |
+
max_steps=3,
|
19 |
+
verbosity_level=1,
|
20 |
+
name="Tour Guide Agent",
|
21 |
+
description="Recommends popular tourist destinations in a given location",
|
22 |
+
**kwargs
|
23 |
+
):
|
24 |
+
super().__init__(
|
25 |
+
model=model,
|
26 |
+
tools=tools,
|
27 |
+
managed_agents=managed_agents,
|
28 |
+
prompt_templates=prompt_templates,
|
29 |
+
planning_interval=planning_interval,
|
30 |
+
max_steps=max_steps,
|
31 |
+
verbosity_level=verbosity_level,
|
32 |
+
name=name,
|
33 |
+
description=description,
|
34 |
+
**kwargs
|
35 |
+
)
|
36 |
+
|
37 |
+
# Add specialized agent prompt
|
38 |
+
self.system_prompt_extension = """
|
39 |
+
You are the Tour Guide Agent for Journi, an AI travel companion system.
|
40 |
+
Your expertise is in finding popular tourist attractions and destinations.
|
41 |
+
|
42 |
+
When given a task from the Coordinator Agent, you should:
|
43 |
+
1. Focus on finding the most popular tourist destinations for the location
|
44 |
+
2. Use web_search to get up-to-date information about tourist spots
|
45 |
+
3. Return a concise list of the top 5-7 attractions with 1-2 sentence descriptions
|
46 |
+
4. Format your response as a bulleted list for easy reading
|
47 |
+
|
48 |
+
Only focus on actual tourist attractions and sights - not hotels, restaurants, or general travel advice.
|
49 |
+
Provide a clear, organized list of the must-see places for travelers.
|
50 |
+
"""
|
51 |
+
|
52 |
+
if prompt_templates and "system_prompt" in prompt_templates:
|
53 |
+
prompt_templates["system_prompt"] += self.system_prompt_extension
|
54 |
+
else:
|
55 |
+
if not prompt_templates:
|
56 |
+
prompt_templates = {}
|
57 |
+
prompt_templates["system_prompt"] = self.system_prompt_extension
|
58 |
+
self.prompt_templates = prompt_templates
|
app.py
CHANGED
@@ -4,11 +4,14 @@ import requests
|
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
-
from tools.web_search import DuckDuckGoSearchTool
|
8 |
-
from tools.visit_webpage import VisitWebpageTool
|
9 |
from Gradio_UI import GradioUI
|
10 |
from smolagents.agent_types import AgentImage
|
11 |
|
|
|
|
|
|
|
|
|
|
|
12 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
13 |
@tool
|
14 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
@@ -58,28 +61,42 @@ image_generation_tool = Tool.from_space(
|
|
58 |
description="Generate an image from a text prompt. The prompt should be detailed to create high-quality images."
|
59 |
)
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
# Final answer tool
|
63 |
final_answer = FinalAnswerTool()
|
64 |
|
65 |
-
with open("
|
66 |
prompt_templates = yaml.safe_load(stream)
|
67 |
|
68 |
-
|
|
|
69 |
model=model,
|
70 |
tools=[
|
71 |
final_answer,
|
72 |
-
image_generation_tool
|
73 |
-
get_current_time_in_timezone
|
74 |
],
|
|
|
|
|
|
|
75 |
max_steps=6,
|
76 |
verbosity_level=1,
|
77 |
-
|
78 |
-
|
79 |
-
name=None,
|
80 |
-
description=None,
|
81 |
prompt_templates=prompt_templates
|
82 |
)
|
83 |
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
|
7 |
from Gradio_UI import GradioUI
|
8 |
from smolagents.agent_types import AgentImage
|
9 |
|
10 |
+
# Import tools
|
11 |
+
from tools.final_answer import FinalAnswerTool
|
12 |
+
from tools.web_search import DuckDuckGoSearchTool
|
13 |
+
from agents.tour_guide_agent import TourGuideAgent
|
14 |
+
|
15 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
16 |
@tool
|
17 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
|
61 |
description="Generate an image from a text prompt. The prompt should be detailed to create high-quality images."
|
62 |
)
|
63 |
|
64 |
+
# Create the web search tool for the tour guide agent
|
65 |
+
web_search_tool = DuckDuckGoSearchTool(max_results=5)
|
66 |
+
|
67 |
+
# Initialize the tour guide agent
|
68 |
+
tour_guide_agent = TourGuideAgent(
|
69 |
+
model=model,
|
70 |
+
tools=[web_search_tool],
|
71 |
+
max_steps=3,
|
72 |
+
verbosity_level=1
|
73 |
+
)
|
74 |
|
75 |
# Final answer tool
|
76 |
final_answer = FinalAnswerTool()
|
77 |
|
78 |
+
with open("prompts_mas.ymal", 'r') as stream:
|
79 |
prompt_templates = yaml.safe_load(stream)
|
80 |
|
81 |
+
# Create the coordinator agent
|
82 |
+
coordinator_agent = CodeAgent(
|
83 |
model=model,
|
84 |
tools=[
|
85 |
final_answer,
|
86 |
+
image_generation_tool
|
|
|
87 |
],
|
88 |
+
managed_agents={
|
89 |
+
'tour_guide_agent': tour_guide_agent
|
90 |
+
},
|
91 |
max_steps=6,
|
92 |
verbosity_level=1,
|
93 |
+
name="Journi",
|
94 |
+
description="Your AI travel companion",
|
|
|
|
|
95 |
prompt_templates=prompt_templates
|
96 |
)
|
97 |
|
98 |
+
# Launch the UI
|
99 |
+
if __name__ == "__main__":
|
100 |
+
print("✈️ Launching Journi - Your AI Travel Companion")
|
101 |
+
print("Ask about any destination to see images and get tourist recommendations!")
|
102 |
+
GradioUI(coordinator_agent).launch()
|
prompts_mas.ymal
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"system_prompt": |-
|
2 |
+
You are Journi, a coordinator agent that helps travelers learn about destinations.
|
3 |
+
|
4 |
+
When a user asks about a destination, ALWAYS follow these exact steps in order:
|
5 |
+
|
6 |
+
STEP 1: Generate an image of the destination
|
7 |
+
```python
|
8 |
+
# Generate destination image first
|
9 |
+
destination = "Paris" # Extract the exact destination from user query
|
10 |
+
destination_image = image_generator(prompt=f"Beautiful travel photo of {destination}, showing iconic landmarks and scenery, high-quality professional photography")
|
11 |
+
print(f"Generated image of {destination}")
|
12 |
+
```
|
13 |
+
|
14 |
+
STEP 2: Get tourist recommendations from the tour guide agent
|
15 |
+
```python
|
16 |
+
# Get tourist recommendations
|
17 |
+
tour_info = tour_guide_agent(task=f"What are the most popular tourist attractions in {destination}?")
|
18 |
+
print(f"Found tourist information for {destination}")
|
19 |
+
```
|
20 |
+
|
21 |
+
STEP 3: Combine everything into a final answer
|
22 |
+
```python
|
23 |
+
# Create comprehensive response with both image and information
|
24 |
+
comprehensive_answer = f'''
|
25 |
+
{destination_image}
|
26 |
+
|
27 |
+
# Welcome to {destination}!
|
28 |
+
|
29 |
+
## Top Tourist Attractions:
|
30 |
+
{tour_info}
|
31 |
+
|
32 |
+
Enjoy your trip to {destination}!
|
33 |
+
'''
|
34 |
+
|
35 |
+
final_answer(comprehensive_answer)
|
36 |
+
```
|
37 |
+
|
38 |
+
This sequence must be followed for all destination queries. Always generate the image first, then get tourist information, then create the final answer.
|