Skip to content

Commit

Permalink
cleanup streamlit examples
Browse files Browse the repository at this point in the history
  • Loading branch information
cornelcroi committed Dec 24, 2024
1 parent 51f90a9 commit 455a897
Show file tree
Hide file tree
Showing 23 changed files with 252 additions and 111 deletions.
4 changes: 2 additions & 2 deletions examples/streamlit/imports.py → examples/python/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# caution: path[0] is reserved for script path (or '' in REPL)

# import your demo here
sys.path.insert(1, '../movie-production')
sys.path.insert(1, '../travel-planner')
sys.path.insert(1, './movie-production')
sys.path.insert(1, './travel-planner')
15 changes: 15 additions & 0 deletions examples/python/main-app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import imports
import streamlit as st

st.set_page_config(
page_title="AWS Multi-Agent Orchestrator Demos",
page_icon="👋",
)

pg = st.navigation(
[
st.Page("pages/home.py", title="Home", icon="🏠"),
st.Page("movie-production/movie-production-demo.py", title="AI Movie Production Demo" ,icon="🎬"),
st.Page("travel-planner/travel-planner-demo.py", title="AI Travel Planner Demo" ,icon="✈️"),
])
pg.run()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import asyncio
import streamlit as st
import os
from search_web import tool_handler
import boto3
from botocore.exceptions import NoRegionError, NoCredentialsError, PartialCredentialsError
from search_web import tool_handler
from tool import Tool
from multi_agent_orchestrator.orchestrator import MultiAgentOrchestrator, OrchestratorConfig
from multi_agent_orchestrator.agents import (
Expand All @@ -14,21 +16,40 @@
from multi_agent_orchestrator.classifiers import ClassifierResult
from supervisor_agent import SupervisorAgent, SupervisorAgentOptions

# Function to test AWS connection
def test_aws_connection():
"""Test the AWS connection and return a status message."""
try:
# Attempt to create an S3 client as a test
boto3.client('s3').list_buckets()
return True
except Exception as e:
print(f"Incomplete AWS credentials. Please check your AWS configuration.")

return False

# Set up the Streamlit app
st.title("AI Movie Production Demo 🎬")
st.caption("Bring your movie ideas to life with the teams of script writing and casting AI agents")
st.caption("Bring your movie ideas to life with AI Movie Production by collaborating with AI agents powered by Anthropic's Claude for script writing and casting.")

# Check AWS connection
if not test_aws_connection():
st.error("AWS connection failed. Please check your AWS credentials and region configuration.")
st.warning("Visit the AWS documentation for guidance on setting up your credentials and region.")
st.stop()

# Define the tools
search_web_tool = Tool(name='search_web',
description='Search Web for information',
properties={
'query': {
'type': 'string',
'description': 'The search query'
}
},
required=['query'])

description='Search Web for information',
properties={
'query': {
'type': 'string',
'description': 'The search query'
}
},
required=['query'])

# Define the agents
script_writer_agent = BedrockLLMAgent(BedrockLLMAgentOptions(
model_id='us.anthropic.claude-3-sonnet-20240229-v1:0',
name="ScriptWriterAgent",
Expand All @@ -37,10 +58,11 @@
develop a compelling script outline with character descriptions and key plot points.
Your tasks consist of:
1. Write a script outline with 3-5 main characters and key plot points
1. Write a script outline with 3-5 main characters and key plot points.
2. Outline the three-act structure and suggest 2-3 twists.
3. Ensure the script aligns with the specified genre and target audience
"""))
3. Ensure the script aligns with the specified genre and target audience.
"""
))

casting_director_agent = BedrockLLMAgent(BedrockLLMAgentOptions(
model_id='anthropic.claude-3-haiku-20240307-v1:0',
Expand All @@ -51,24 +73,23 @@
Your tasks consist of:
1. Suggest 1-2 actors for each main role.
2. Check actors' current status using search_web tool
2. Check actors' current status using the search_web tool.
3. Provide a brief explanation for each casting suggestion.
4. Consider diversity and representation in your casting choices.
5. Provide a final response with all the actors you suggest for the main roles
5. Provide a final response with all the actors you suggest for the main roles.
""",

tool_config={
'tool': [search_web_tool.to_bedrock_format()],
'toolMaxRecursions': 20,
'useToolHandler': tool_handler
tool_config={
'tool': [search_web_tool.to_bedrock_format()],
'toolMaxRecursions': 20,
'useToolHandler': tool_handler
},
save_chat=False
))

movie_producer_supervisor = BedrockLLMAgent(BedrockLLMAgentOptions(
model_id='us.anthropic.claude-3-5-sonnet-20241022-v2:0',
name='MovieProducerAgent',
description="""
description="""\
Experienced movie producer overseeing script and casting.
Your tasks consist of:
Expand All @@ -77,7 +98,7 @@
3. Summarize the script outline and casting suggestions.
4. Provide a concise movie concept overview.
5. Make sure to respond with a markdown format without mentioning it.
""",
"""
))

supervisor = SupervisorAgent(SupervisorAgentOptions(
Expand All @@ -86,25 +107,23 @@
trace=True
))

# Define async function for handling requests
async def handle_request(_orchestrator: MultiAgentOrchestrator, _user_input: str, _user_id: str, _session_id: str):
classifier_result = ClassifierResult(selected_agent=supervisor, confidence=1.0)


async def handle_request(_orchestrator: MultiAgentOrchestrator, _user_input:str, _user_id:str, _session_id:str):
classifier_result=ClassifierResult(selected_agent=supervisor, confidence=1.0)

response:AgentResponse = await _orchestrator.agent_process_request(_user_input, _user_id, _session_id, classifier_result)
response: AgentResponse = await _orchestrator.agent_process_request(_user_input, _user_id, _session_id, classifier_result)

# Print metadata
print("\nMetadata:")
print(f"Selected Agent: {response.metadata.agent_name}")
if isinstance(response, AgentResponse) and response.streaming is False:
# Handle regular response
if isinstance(response.output, str):
return (response.output)
return response.output
elif isinstance(response.output, ConversationMessage):
return (response.output.content[0].get('text'))

return response.output.content[0].get('text')

# Initialize the orchestrator with some options
# Initialize the orchestrator
orchestrator = MultiAgentOrchestrator(options=OrchestratorConfig(
LOG_AGENT_CHAT=True,
LOG_CLASSIFIER_CHAT=True,
Expand All @@ -119,12 +138,10 @@ async def handle_request(_orchestrator: MultiAgentOrchestrator, _user_input:str,
USER_ID = str(uuid.uuid4())
SESSION_ID = str(uuid.uuid4())

# Input field for the report query
# Input fields for the movie concept
movie_idea = st.text_area("Describe your movie idea in a few sentences:")
genre = st.selectbox("Select the movie genre:",
["Action", "Comedy", "Drama", "Sci-Fi", "Horror", "Romance", "Thriller"])
target_audience = st.selectbox("Select the target audience:",
["General", "Children", "Teenagers", "Adults", "Mature"])
genre = st.selectbox("Select the movie genre:", ["Action", "Comedy", "Drama", "Sci-Fi", "Horror", "Romance", "Thriller"])
target_audience = st.selectbox("Select the target audience:", ["General", "Children", "Teenagers", "Adults", "Mature"])
estimated_runtime = st.slider("Estimated runtime (in minutes):", 30, 180, 120)

# Process the movie concept
Expand All @@ -134,6 +151,7 @@ async def handle_request(_orchestrator: MultiAgentOrchestrator, _user_input:str,
f"Movie idea: {movie_idea}, Genre: {genre}, "
f"Target audience: {target_audience}, Estimated runtime: {estimated_runtime} minutes"
)
# Get the response from the assistant
response = asyncio.run(handle_request(orchestrator, input_text, USER_ID, SESSION_ID))
st.write(response)
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
response = loop.run_until_complete(handle_request(orchestrator, input_text, USER_ID, SESSION_ID))
st.write(response)
Original file line number Diff line number Diff line change
@@ -1,38 +1,21 @@
## 🎬 AI Movie Production Agent
This Streamlit app is an AI-powered movie production assistant that helps bring your movie ideas to life using Claude 3 on Amazon BedrocK. It automates the process of script writing and casting, allowing you to create compelling movie concepts with ease.
### streamlit app
Here is a screenshot of the streamlit app. You can describe your movie, select a movie genre, audience and duration and hit `Develop Movie Concept`
This Streamlit app is an AI-powered movie production assistant that helps bring your movie ideas to life using Claude 3 on Amazon Bedrock. It automates the process of script writing and casting, allowing you to create compelling movie concepts with ease.

### Streamlit App
Here is a screenshot of the streamlit app. You can describe your movie, select a movie genre, audience and duration and hit `Develop Movie Concept`
![image](./movie-production.png)

After a few seconds you should have a your movie ready! 🍿 🎬

After a few seconds you should have your movie ready! 🍿 🎬
![image](./movie-production-result.png)

### Features
- Generates script outlines based on your movie idea, genre, and target audience
- Suggests suitable actors for main roles, considering their past performances and current availability
- Provides a concise movie concept overview

### How to get Started?

1. Clone the GitHub repository

```bash
git clone https://github.com/awslabs/multi-agent-orchestrator.git
```
2. Install the required dependencies:

```bash
cd examples/movie-production
pip install -r requirements.txt
```
3. Get your AWS Credentials
### How to Get Started?

4. Run the Streamlit App
```bash
streamlit run movie-production-demo.py
```
Check out the [demos README](../README.md) for installation and setup instructions.

### How it Works?

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 30 additions & 0 deletions examples/python/pages/home.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import streamlit as st

st.title("AWS Multi-Agent Orchestrator Demos")

st.markdown("""
Welcome to our comprehensive demo application showcasing real-world applications of the AWS Multi-Agent Orchestrator framework.
This app demonstrates how multiple specialized AI agents can collaborate to solve complex tasks using Amazon Bedrock and Anthropic's Claude.
Each demo highlights different aspects of multi-agent collaboration, from creative tasks to practical planning,
showing how the framework can be applied to various business scenarios. 🤖✨
## 🎮 Featured Demos
### 🎬 AI Movie Production Studio
**Requirements**: AWS Account with Amazon Bedrock access (Claude models enabled)
Transform your movie ideas into detailed scripts and cast lists! Our AI agents collaborate:
- **ScriptWriter** ([BedrockLLMAgent](https://awslabs.github.io/multi-agent-orchestrator/agents/built-in/bedrock-llm-agent) with Claude 3 Sonnet): Creates compelling story outlines
- **CastingDirector** ([BedrockLLMAgent](https://awslabs.github.io/multi-agent-orchestrator/agents/built-in/bedrock-llm-agent) with Claude 3 Haiku): Researches and suggests perfect casting choices
- **MovieProducer** ([BedrockLLMAgent](https://awslabs.github.io/multi-agent-orchestrator/agents/built-in/bedrock-llm-agent) with Claude 3.5 Sonnet): Coordinates the entire creative process
- All coordinated by a [**BedrockFlowsAgent**](https://awslabs.github.io/multi-agent-orchestrator/agents/built-in/bedrock-flows-agent) supervisor
### ✈️ AI Travel Planner
**Requirements**: Anthropic API Key
Your personal travel assistant powered by AI! Experience collaboration between:
- **ResearcherAgent** ([AnthropicAgent](https://awslabs.github.io/multi-agent-orchestrator/agents/built-in/anthropic-agent) with Claude 3 Haiku): Performs real-time destination research
- **PlannerAgent** ([AnthropicAgent](https://awslabs.github.io/multi-agent-orchestrator/agents/built-in/anthropic-agent) with Claude 3 Sonnet): Creates personalized day-by-day itineraries
- Coordinated by a [**SupervisorMode**](https://awslabs.github.io/multi-agent-orchestrator/agents/built-in/supervisor-agent) using the Planner as supervisor
""")
79 changes: 79 additions & 0 deletions examples/python/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# AWS Multi-Agent Orchestrator Demos

This Streamlit application showcases various demos powered by the AWS Multi-Agent Orchestrator framework, demonstrating how multiple AI agents can collaborate to solve complex tasks using Amazon Bedrock.

## 🎯 Current Demos

### 🎬 [AI Movie Production](../movie-production/README.md)
**Requirements**: AWS Account with Amazon Bedrock access (Claude models enabled)

Transform your movie ideas into detailed concepts with this AI-powered production assistant. Simply describe your movie idea, choose a genre and target audience, and the system will generate a complete script outline and suggest suitable actors for main roles based on real-time casting research. Powered by a team of specialized AI agents using Claude 3 on Amazon Bedrock.

### ✈️ [AI Travel Planner](../travel-planner/README.md)
**Requirements**: Anthropic API Key

Create personalized travel itineraries with this AI-powered travel assistant. Input your destination and duration, and the system will research attractions, accommodations, and activities in real-time, crafting a detailed day-by-day itinerary tailored to your preferences. Built using specialized research and planning agents powered by Amazon Bedrock.

## 🚀 Getting Started

### Prerequisites
- Python 3.8 or higher
- For Movie Production Demo:
- AWS account with access to Amazon Bedrock
- AWS credentials configured ([How to configure AWS credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html))
- Claude models enabled in Amazon Bedrock ([Enable Bedrock model access](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html))
- For Travel Planner Demo:
- Anthropic API Key ([Get your API key](https://console.anthropic.com/account/keys))

### Installation

1. Clone the repository:
```bash
git clone https://github.com/awslabs/multi-agent-orchestrator.git
```

2. Navigate to the demos directory:
```bash
cd examples/python
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
```

3. Install the required dependencies:
```bash
# For running all demos through main app
python -m venv venv_main
source venv/bin/activate # On Windows use `venv_main\Scripts\activate`
pip install -r requirements.txt
```

4. Configure AWS credentials:
- Follow the [AWS documentation](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) to set up your credentials using your preferred method (AWS CLI, environment variables, or credentials file)

5. Run the Streamlit app:
```bash
streamlit run main-app.py
```

## 💡 How It Works

The application uses the Multi-Agent Orchestrator framework to coordinate multiple specialized AI agents powered by Amazon Bedrock. Each demo showcases different aspects of agent collaboration:
- **Movie Production**: Demonstrates creative collaboration between script writing and casting agents
- **Travel Planning**: Shows how research and planning agents can work together to create personalized travel experiences

Each agent is powered by Claude 3 on Amazon Bedrock and can communicate with other agents through a supervisor agent that orchestrates the entire process.

## 🛠️ Technologies Used
- AWS Multi-Agent Orchestrator
- Amazon Bedrock
- Claude 3 (Anthropic)
- Streamlit
- Python

## 📚 Documentation

For more information about the Multi-Agent Orchestrator framework and its capabilities, visit our [documentation](https://awslabs.github.io/multi-agent-orchestrator/).

## 🤝 Contributing

We welcome contributions! Please feel free to submit a Pull Request.
7 changes: 7 additions & 0 deletions examples/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Core dependencies for the main demo app
streamlit
duckduckgo-search
multi-agent-orchestrator[aws]
multi-agent-orchestrator[anthropic]
python-dotenv
boto3
File renamed without changes.
27 changes: 27 additions & 0 deletions examples/python/travel-planner/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## ✈️ AI Travel Planner
This Streamlit app is an AI-powered travel planning assistant that helps plan personalized travel itineraries using Claude 3 on Amazon Bedrock. It automates destination research and itinerary planning, creating detailed travel plans tailored to your needs.

### Streamlit App
Here's how the app works:
1. Enter your desired destination
2. Specify the number of days you want to travel
3. Click `Generate Itinerary`
4. Get a detailed, day-by-day travel plan with researched attractions and activities

### Features
- Researches destinations and attractions in real-time using web search
- Generates personalized day-by-day itineraries based on your travel duration
- Provides practical travel suggestions and tips based on current information
- Creates comprehensive travel plans that consider local attractions, activities, and logistics

### How to Get Started?

Check out the [demos README](../README.md) for installation and setup instructions.

### How it Works?

The AI Travel Planner utilizes two main components:
- **ResearcherAgent**: Searches and analyzes real-time information about destinations, attractions, and activities using web search capabilities
- **PlannerAgent**: Takes the researched information and creates a coherent, day-by-day travel itinerary, considering logistics and time management

The agents work together through a supervisor to create a comprehensive travel plan that combines up-to-date destination research with practical itinerary planning.
Loading

0 comments on commit 455a897

Please sign in to comment.