Skip to content

Commit

Permalink
Merge pull request #177 from awslabs/refacto-examples-issues-171
Browse files Browse the repository at this point in the history
cleanup streamlit examples
  • Loading branch information
cornelcroi authored Dec 26, 2024
2 parents d386853 + 2826fcd commit 0ad010a
Show file tree
Hide file tree
Showing 25 changed files with 268 additions and 114 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ Get hands-on experience with the Multi-Agent Orchestrator through our diverse se

- **Ready-to-run Scripts**: Start locally with our collection of standalone scripts in both Python and TypeScript.
- **Demo Applications**:
- [Streamlit Global Demo](https://github.com/awslabs/multi-agent-orchestrator/tree/main/examples/python): A single Streamlit application showcasing multiple demos, including:
- AI Movie Production Studio
- AI Travel Planner
- [Chat Demo App](https://awslabs.github.io/multi-agent-orchestrator/cookbook/examples/chat-demo-app/):
- Explore multiple specialized agents handling various domains like travel, weather, math, and health
- [E-commerce Support Simulator](https://awslabs.github.io/multi-agent-orchestrator/cookbook/examples/ecommerce-support-simulator/): Experience AI-powered customer support with:
Expand Down
Binary file added examples/python/img/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,47 @@
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.
To learn more about the agents used in this demo visit [this link](https://github.com/awslabs/multi-agent-orchestrator/tree/main/examples/python/movie-production).
search_web_tool = Tool(name='search_web',
description='Search Web for information',
properties={
'query': {
'type': 'string',
'description': 'The search query'
}
},
required=['query'])
""")

st.caption("")

# 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'])

# Define the agents
script_writer_agent = BedrockLLMAgent(BedrockLLMAgentOptions(
model_id='us.anthropic.claude-3-sonnet-20240229-v1:0',
name="ScriptWriterAgent",
Expand All @@ -37,10 +65,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 +80,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 +105,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 +114,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 +145,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 +158,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.
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
""")
85 changes: 85 additions & 0 deletions examples/python/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# AWS Multi-Agent Orchestrator Demos

This Streamlit application demonstrates the capabilities of the AWS Multi-Agent Orchestrator framework by showcasing how specialized AI agents can collaborate to solve complex tasks using Amazon Bedrock and Anthropic's Claude models.

![Demo app](./img/screenshot.png)

## 🎯 Current Demos

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

Bring your movie ideas to life with this AI-powered production assistant. Describe your movie concept, select a genre and target audience, and let the system create a comprehensive script outline and recommend actors for the main roles based on real-time research.

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

Enter your destination and travel duration, and the system will research attractions, accommodations, and activities in real-time to create a personalized, day-by-day itinerary based on your preferences.



## 🚀 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
cd examples/python
python -m venv venv
source venv/bin/activate # On Windows use `venv\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
```

## 🎮 Featured Demos

### 🎬 AI Movie Production Studio
**Prerequisite**: 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 [**Custom Agent**](https://awslabs.github.io/multi-agent-orchestrator/agents/custom-agents) as Supervisor Agent

### ✈️ AI Travel Planner
**Prerequisite**: 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 [**Custom Agent**](https://awslabs.github.io/multi-agent-orchestrator/agents/custom-agents) as Supervisor Agent

## 🛠️ Technologies Used
- Streamlit for UI
- AWS Multi-Agent Orchestrator for multi-agent collaboration
- Amazon Bedrock for deploying Claude models
- Anthropic's Claude models for AI reasoning
- Python for backend scripting

## 📚 Documentation


Learn more about the AWS Multi-Agent Orchestrator framework, including its features and technical details, by visiting the official [documentation](https://awslabs.github.io/multi-agent-orchestrator/).


## 🤝 Contributing

If you want to create a new demo to be included in this global Streamlit demo application, contributions are welcome! Please fork the repository, create a new branch with your changes, and submit a Pull Request for review
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.
Loading

0 comments on commit 0ad010a

Please sign in to comment.