TourGuilde / manager.py
buitu0's picture
Upload 2 files
562adbd verified
Raw
History Blame Contribute Delete
2.27 kB
import time
from prompts import *
from agent import GeminiAgent
def generate_tour_script(api_key, location, interests, duration):
# Step 1: Planner
planner = GeminiAgent(api_key, system_instruction=PLANNER_PROMPT)
planner_prompt = f"Location: {location}\nInterests: {interests}\nDuration: {duration} minutes"
print("Calling Planner Agent...")
experts_str = planner.generate_content(planner_prompt)
experts = [e.strip() for e in experts_str.split(',') if e.strip()]
print(f"Experts needed: {experts}")
# Mapping experts to prompts
expert_prompts = {
"Architecture": ARCHITECTURE_PROMPT,
"Culinary": CULINARY_PROMPT,
"Culture": CULTURE_PROMPT,
"History": HISTORICAL_PROMPT
}
# Step 2: Call experts sequentially
expert_scripts = {}
for expert in experts:
# Match expert name loosely
matched_key = next((k for k in expert_prompts.keys() if k.lower() in expert.lower()), None)
if matched_key:
print(f"Calling {matched_key} Expert...")
expert_agent = GeminiAgent(api_key, system_instruction=expert_prompts[matched_key])
expert_prompt = f"Provide script for location: {location}"
script = expert_agent.generate_content(expert_prompt)
expert_scripts[matched_key] = script
# Sleep to avoid 429 Too Many Requests
time.sleep(5)
if not expert_scripts:
# Fallback if planner outputs something weird
print("Fallback to History Expert")
expert_agent = GeminiAgent(api_key, system_instruction=HISTORICAL_PROMPT)
script = expert_agent.generate_content(f"Provide historical overview for: {location}")
expert_scripts["History"] = script
time.sleep(5)
# Step 3: Orchestrator
orchestrator = GeminiAgent(api_key, system_instruction=ORCHESTRATOR_PROMPT)
orchestrator_prompt = "Combine the following expert scripts into a seamless audio tour:\n\n"
for exp, script in expert_scripts.items():
orchestrator_prompt += f"--- {exp} Expert ---\n{script}\n\n"
print("Calling Orchestrator Agent...")
final_script = orchestrator.generate_content(orchestrator_prompt)
return final_script