Using Autogen for AI Agent Orchestration

Gunjan
3 min readJun 12, 2024

--

AutoGen is a framework helps use multiple AI agents that can converse with each other to solve tasks.

Microsoft AutoGen is a powerful AI agent orchestration platform for building custom AI agents. In this blog post, we’ll leverage AutoGen to create your personal travel assistant dream team, that will help guide travelers wanting to discover new destinations to a fully planned itinerary.

The AI agents:

  • The City Explorer — Where should the traveller go ? Our City Explorer agent analyzes interests (beaches, adventure, culture) and suggests exciting destinations that perfectly match a travel style.
  • The Travel Advisor- Once we have the right locations, the Travel Advisor steps in. This agent crafts a personalized itinerary based on personal preferences (relaxation, adventure, budget).
  • The Local Tour Guide — I like to consider places only the locals visit. The Local Tour Guide delves into the chosen city, recommending must-see attractions and activities that will make you relive what the locals cherish in town.
import autogen as ag

# Replace with your own access key
access_key = "YOUR_ACCESS_KEY"

def create_travel_agents():
"""
Defines and configures the AI agents for travel assistance.
"""
travel_advisor = ag.Agent(
name="Travel Advisor",
description="Crafts personalized itineraries based on your preferences.",
policy={
"gpt_model": "text-davinci-003", # Choose a suitable GPT model for informative responses
"max_tokens": 1024, # Adjust the maximum response length as needed
},
)

city_explorer = ag.Agent(
name="City Explorer",
description="Discovers destinations matching your travel interests.",
policy={
"gpt_model": "text-davinci-003", # Choose a suitable GPT model for informative responses
"max_tokens": 1024, # Adjust the maximum response length as needed
},
)

local_tour_guide = ag.Agent(
name="Local Tour Guide",
description="Recommends activities and attractions within a chosen city.",
policy={
"gpt_model": "text-davinci-003", # Choose a suitable GPT model for informative responses
"max_tokens": 1024, # Adjust the maximum response length as needed
},
)

return travel_advisor, city_explorer, local_tour_guide

def recommend_destinations(interests):
"""
Uses the City Explorer agent to suggest potential travel destinations.
"""
city_explorer, _, _ = create_travel_agents()
prompt = f"As a City Explorer, suggest exciting travel destinations for someone interested in {interests}."
response = city_explorer.run(prompt, access_key=access_key)
return response

def plan_trip_itinerary(destination, preferences):
"""
Uses the Travel Advisor agent to create a personalized itinerary.
"""
travel_advisor, _, _ = create_travel_agents()
prompt = f"As a Travel Advisor, create a personalized itinerary for a trip to {destination} considering preferences like {preferences}."
response = travel_advisor.run(prompt, access_key=access_key)
return response

def find_local_activities(city):
"""
Uses the Local Tour Guide agent to recommend activities within a city.
"""
_, local_tour_guide, _ = create_travel_agents()
prompt = f"As a Local Tour Guide, recommend exciting activities and attractions in {city}."
response = local_tour_guide.run(prompt, access_key=access_key)
return response

# Example usage (replace with your Streamlit app or UI)
if __name__ == "__main__":
# Get user input (interests, destination, preferences)
user_interests = "..." # Replace with user input for interests
user_destination = "..." # Replace with user input for destination (optional)
user_preferences = "..." # Replace with user input for trip preferences

if user_destination:
# User has a specific destination in mind
itinerary = plan_trip_itinerary(user_destination, user_preferences)
print(f"Travel Advisor Itinerary:\n{itinerary}")
activities = find_local_activities(user_destination)
print(f"Local Tour Guide Recommendations:\n{activities}")
else:
# User needs help finding a destination
destinations = recommend_destinations(user_interests)
print(f"City Explorer Recommendations:\n{destinations}")

Here is a further breakdown of the code.

  1. Agent Configuration: We define three agents — City Explorer, Travel Advisor, and Local Tour Guide using AutoGen. Each agent has a specific role and utilizes a powerful GPT model to generate informative responses.
  2. Personalized Recommendations:
  • City Explorer: This agent analyzes user-provided interests and suggests potential destinations through the recommend_destinations function.
  • Travel Advisor: Tell the Travel Advisor your desired location and preferences through the plan_trip_itinerary function. It then crafts a personalized itinerary tailored to your needs.
  • Local Tour Guide: Once you have your city, discover hidden gems with the find_local_activities function. The Local Tour Guide scours the web to recommend exciting activities within your chosen destination.

Try the basic code above as a starting point.

Enhance it to make it it more intelligent.

Good luck!

--

--