Skip to content

Commit

Permalink
Merge pull request #108 from brnaba-aws/main
Browse files Browse the repository at this point in the history
Split MAO python package dependency into feature (anthropic and openai) and removed Bedrock dependency in Classifier and Orchestrator
  • Loading branch information
brnaba-aws authored Nov 26, 2024
2 parents 0c20056 + 223f71a commit a6c0855
Show file tree
Hide file tree
Showing 18 changed files with 289 additions and 85 deletions.
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ To quickly get a feel for the Multi-Agent Orchestrator, check out our [Demo App]
Get hands-on experience with the Multi-Agent Orchestrator through our diverse set of examples:

- **Ready-to-run Scripts**: Start locally with our collection of standalone scripts in both Python and TypeScript.
- **Demo Applications**:
- [Chat Demo App](https://awslabs.github.io/multi-agent-orchestrator/cookbook/examples/chat-demo-app/):
- **Demo Applications**:
- [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:
- Automated response generation for common queries
Expand All @@ -83,8 +83,8 @@ Get hands-on experience with the Multi-Agent Orchestrator through our diverse se
- [`chat-chainlit-app`](https://github.com/awslabs/multi-agent-orchestrator/tree/main/examples/chat-chainlit-app): Chat application built with Chainlit
- [`fast-api-streaming`](https://github.com/awslabs/multi-agent-orchestrator/tree/main/examples/fast-api-streaming): FastAPI implementation with streaming support
- [`text-2-structured-output`](https://github.com/awslabs/multi-agent-orchestrator/tree/main/examples/text-2-structured-output): Natural Language to Structured Data


All examples are available in both Python and TypeScript implementations. Check out our [documentation](https://awslabs.github.io/multi-agent-orchestrator/) for comprehensive guides on setting up and using the Multi-Agent Orchestrator!


Expand Down Expand Up @@ -192,7 +192,7 @@ if (response.streaming == true) {

### Python Version

#### Installation
#### Core Installation

```bash
# Optional: Set up a virtual environment
Expand All @@ -201,7 +201,7 @@ source venv/bin/activate # On Windows use `venv\Scripts\activate`
pip install multi-agent-orchestrator
```

#### Usage
#### Default Usage

Here's an equivalent Python example demonstrating the use of the Multi-Agent Orchestrator with a Bedrock LLM Agent and a Lex Bot Agent:

Expand Down Expand Up @@ -289,6 +289,19 @@ These examples showcase:
3. The orchestrator's ability to route requests to the most appropriate agent based on the input.
4. Handling of both streaming and non-streaming responses from different types of agents.

### Working with Anthropic or OpenAI
If you want to use Anthropic or OpenAI for classifier and/or agents, make sure to install the multi-agent-orchestrator with the relevant extra feature.
```bash
pip install multi-agent-orchestrator[anthropic]
pip install multi-agent-orchestrator[openai]
```

### Full package installation
For a complete installation (including Anthropic and OpenAi):
```bash
pip install multi-agent-orchestrator[all]
```


## 🤝 Contributing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ The Anthropic Classifier extends the abstract `Classifier` class and uses the An

### Basic Usage

⚠️ To use Anthropic Classifier, make sure you have installed the multi-agent-orchestrator with anthropic feature (see [python installation](/multi-agent-orchestrator/general/quickstart#-get-started))
```bash
pip install multi-agent-orchestrator[anthropic]
```

To use the AnthropicClassifier, you need to create an instance with your Anthropic API key and pass it to the Multi-Agent Orchestrator:

import { Tabs, TabItem } from '@astrojs/starlight/components';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ The OpenAI Classifier extends the abstract `Classifier` class and uses the OpenA

## Basic Usage

⚠️ To use OpenAI Classifier, make sure you have installed the multi-agent-orchestrator with openai feature (see [python installation](/multi-agent-orchestrator/general/quickstart#-get-started))

```bash
pip install multi-agent-orchestrator[openai]
```

To use the OpenAIClassifier, you need to create an instance with your OpenAI API key and pass it to the Multi-Agent Orchestrator:

import { Tabs, TabItem } from '@astrojs/starlight/components';
Expand Down
13 changes: 8 additions & 5 deletions docs/src/content/docs/classifiers/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ The Classifier is a crucial component of the Multi-Agent Orchestrator, responsib

- **[Anthropic Classifier](/multi-agent-orchestrator/classifiers/built-in/anthropic-classifier)** uses Anthropic's AI models for intent classification. It provides an alternative option for users who prefer or have access to Anthropic's services.

- **[OpenAI Classifier](/multi-agent-orchestrator/classifiers/built-in/openai-classifier)** uses OpenAI's AI models for intent classification. It provides an alternative option for users who prefer or have access to OpenAI's services.


### Process Flow

Regardless of the classifier used, the general process remains the same:
Expand All @@ -23,11 +26,11 @@ Regardless of the classifier used, the general process remains the same:

By default, if no agent is selected the orchestrator can be configured to:

A. Use a default agent (a **[BedrockLLMAgent](/multi-agent-orchestrator/agents/built-in/bedrock-llm-agent)**)
A. Use a default agent (a **[BedrockLLMAgent for example](/multi-agent-orchestrator/agents/built-in/bedrock-llm-agent)**)

B. Return a message prompting the user for more information.

This behavior can be customized using the `USE_DEFAULT_AGENT_IF_NONE_IDENTIFIED` and `NO_SELECTED_AGENT_MESSAGE` configuration options in the orchestrator.
This behavior can be customized using the `USE_DEFAULT_AGENT_IF_NONE_IDENTIFIED` and `NO_SELECTED_AGENT_MESSAGE` configuration options in the orchestrator.

For a detailed explanation of these options and other orchestrator configurations, please refer to the [Orchestrator Overview](/multi-agent-orchestrator/orchestrator/overview#agent-selection-and-default-behavior) page.

Expand Down Expand Up @@ -105,13 +108,13 @@ You can test any Classifier directly using the `classify` method:
user_input = "What are the symptoms of the flu?"
user_id = "test_user"
session_id = "test_session"

# Fetch chat history (this might vary depending on your implementation)
chat_history = await orchestrator.storage.fetch_all_chats(user_id, session_id)

# Classify the input
response = await orchestrator.classifier.classify(user_input, chat_history)

print('\n** RESPONSE ** \n')
print(f" > Agent ID: {response.selected_agent.id if response.selected_agent else 'None'}")
print(f" > Agent Name: {response.selected_agent.name if response.selected_agent else 'None'}")
Expand Down
15 changes: 9 additions & 6 deletions docs/src/content/docs/general/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ To help you kickstart with the Multi-Agent Orchestrator framework, we'll walk yo

2. Authenticate with your AWS account

This quickstart demonstrates the use of Amazon Bedrock for both classification and agent responses.
This quickstart demonstrates the use of Amazon Bedrock for both classification and agent responses.

To authenticate with your AWS account, follow these steps:

Expand All @@ -61,8 +61,8 @@ By default, the framework is configured as follows:
<br/>

> **Important**
>
> These are merely default settings and can be easily changed to suit your needs or preferences.
>
> These are merely default settings and can be easily changed to suit your needs or preferences.
<br/>

Expand Down Expand Up @@ -91,7 +91,10 @@ Ensure you have [requested access](https://docs.aws.amazon.com/bedrock/latest/us
</TabItem>
<TabItem label="Python" icon="seti:python">
```bash
pip install multi-agent-orchestrator
pip install multi-agent-orchestrator # for core dependencies
pip install multi-agent-orchestrator[anthropic] # for Anthropic classifier and agent
pip install multi-agent-orchestrator[openai] # for OpenAI classifier and agent
pip install multi-agent-orchestrator[all] # for all packages including Anthropic and OpenAI
```
</TabItem>
</Tabs>
Expand Down Expand Up @@ -165,7 +168,7 @@ Ensure you have [requested access](https://docs.aws.amazon.com/bedrock/latest/us
streaming: true
})
);

orchestrator.addAgent(
new BedrockLLMAgent({
name: "Health Agent",
Expand Down Expand Up @@ -227,7 +230,7 @@ Ensure you have [requested access](https://docs.aws.amazon.com/bedrock/latest/us
console.error("Received unexpected chunk type:", typeof chunk);
}
}
console.log();
console.log();
} catch (error) {
console.error("An error occurred:", error);
// Here you could also add more specific error handling if needed
Expand Down
8 changes: 7 additions & 1 deletion docs/src/content/docs/orchestrator/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ The Orchestrator accepts an `OrchestratorConfig` object during initialization. A
- `GENERAL_ROUTING_ERROR_MSG_MESSAGE`: Custom message for general routing errors.
3. `logger`: Custom logger instance. If not provided, a default logger will be used.
4. `classifier`: Custom classifier instance. If not provided, a `BedrockClassifier` will be used.
5. `default_agent`: A default agent when the classifier could not determine the most suitable agent.

### Example with all options

Expand Down Expand Up @@ -107,7 +108,12 @@ Here's an example that demonstrates how to initialize the Orchestrator with all
),
storage=DynamoDBChatStorage(),
classifier=CustomClassifier(),
logger=CustomLogger()
logger=CustomLogger(),
default_agent=BedrockLLMAgent(BedrockLLMAgentOptions(
name="Default Agent",
streaming=False,
description="This is the default agent that handles general queries and tasks.",
))
)
```
</TabItem>
Expand Down
17 changes: 15 additions & 2 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Check out our [documentation](https://awslabs.github.io/multi-agent-orchestrator



### Installation
### Core Installation

```bash
# Optional: Set up a virtual environment
Expand All @@ -81,7 +81,7 @@ source venv/bin/activate # On Windows use `venv\Scripts\activate`
pip install multi-agent-orchestrator
```

### Usage
#### Default Usage

Here's an equivalent Python example demonstrating the use of the Multi-Agent Orchestrator with a Bedrock LLM Agent and a Lex Bot Agent:

Expand Down Expand Up @@ -176,6 +176,19 @@ This example showcases:
4. Handling of both streaming and non-streaming responses from different types of agents.


### Working with Anthropic or OpenAI
If you want to use Anthropic or OpenAI for classifier and/or agents, make sure to install the multi-agent-orchestrator with the relevant extra feature.
```bash
pip install multi-agent-orchestrator[anthropic]
pip install multi-agent-orchestrator[openai]
```

### Full package installation
For a complete installation (including Anthropic and OpenAi):
```bash
pip install multi-agent-orchestrator[all]
```

## 🤝 Contributing

We welcome contributions! Please see our [Contributing Guide](https://raw.githubusercontent.com/awslabs/multi-agent-orchestrator/main/CONTRIBUTING.md) for more details.
Expand Down
7 changes: 7 additions & 0 deletions python/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ packages = find:
python_requires = >=3.11
install_requires =
boto3==1.34.151

[options.extras_require]
anthropic =
anthropic==0.32.0
openai =
openai==1.55.0
all =
anthropic==0.32.0
openai==1.55.0

Expand Down
18 changes: 14 additions & 4 deletions python/src/multi_agent_orchestrator/agents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
from .comprehend_filter_agent import ComprehendFilterAgent, ComprehendFilterAgentOptions
from .chain_agent import ChainAgent, ChainAgentOptions
from .bedrock_translator_agent import BedrockTranslatorAgent, BedrockTranslatorAgentOptions
from .anthropic_agent import AnthropicAgent, AnthropicAgentOptions

try:
from .anthropic_agent import AnthropicAgent, AnthropicAgentOptions
_ANTHROPIC_AVAILABLE = True
except ImportError:
_ANTHROPIC_AVAILABLE = False


__all__ = [
'Agent',
Expand All @@ -24,13 +30,17 @@
'LexBotAgent',
'LexBotAgentOptions',
'AmazonBedrockAgent',
'AmazonBedrockAgentOptions'
'AmazonBedrockAgentOptions',
'ComprehendFilterAgent',
'ComprehendFilterAgentOptions',
'BedrockTranslatorAgent',
'BedrockTranslatorAgentOptions',
'ChainAgent',
'ChainAgentOptions',
'AnthropicAgent',
'AnthropicAgentOptions'
]

if _ANTHROPIC_AVAILABLE:
__all__.extend([
'AnthropicAgent',
'AnthropicAgentOptions'
])
38 changes: 28 additions & 10 deletions python/src/multi_agent_orchestrator/classifiers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
"""
Code for Classifier.
"""


from .classifier import Classifier, ClassifierResult
from .anthropic_classifier import AnthropicClassifier, AnthropicClassifierOptions
from .bedrock_classifier import BedrockClassifier, BedrockClassifierOptions
from .openai_classifier import OpenAIClassifier, OpenAIClassifierOptions

try:
from .anthropic_classifier import AnthropicClassifier, AnthropicClassifierOptions
_ANTHROPIC_AVAILABLE = True
except Exception as e:
_ANTHROPIC_AVAILABLE = False

try:
from .openai_classifier import OpenAIClassifier, OpenAIClassifierOptions
_OPENAI_AVAILABLE = True
except Exception as e:
_OPENAI_AVAILABLE = False



__all__ = [
"AnthropicClassifier",
"AnthropicClassifierOptions",
"BedrockClassifier",
"BedrockClassifierOptions",
"Classifier",
"ClassifierResult",
"OpenAIClassifier",
"OpenAIClassifierOptions",
"BedrockClassifier",
"BedrockClassifierOptions"
]

if _ANTHROPIC_AVAILABLE:
__all__.extend([
"AnthropicClassifier",
"AnthropicClassifierOptions"
])

if _OPENAI_AVAILABLE:
__all__.extend([
"OpenAIClassifier",
"OpenAIClassifierOptions"
])
10 changes: 1 addition & 9 deletions python/src/multi_agent_orchestrator/classifiers/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Dict, List, Optional
from dataclasses import dataclass
from multi_agent_orchestrator.types import ConversationMessage, AgentTypes, TemplateVariables
from multi_agent_orchestrator.agents import Agent, BedrockLLMAgent, BedrockLLMAgentOptions
from multi_agent_orchestrator.agents import Agent


@dataclass
Expand All @@ -13,14 +13,6 @@ class ClassifierResult:

class Classifier(ABC):
def __init__(self):
self.default_agent = BedrockLLMAgent(
options=BedrockLLMAgentOptions(
name=AgentTypes.DEFAULT.value,
streaming=True,
description="A knowledgeable generalist capable of addressing a wide range of topics.\
This agent should be selected if no other specialized agent is a better fit."
))

self.agent_descriptions = ""
self.history = ""
self.custom_variables: TemplateVariables = {}
Expand Down
Loading

0 comments on commit a6c0855

Please sign in to comment.