Skip to content

Commit

Permalink
Merge pull request #28 from awslabs/chain-agent
Browse files Browse the repository at this point in the history
Chain agent
  • Loading branch information
cornelcroi authored Aug 28, 2024
2 parents d8a9e90 + c41e3d6 commit 6200acb
Show file tree
Hide file tree
Showing 21 changed files with 1,904 additions and 35 deletions.
5 changes: 4 additions & 1 deletion docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ export default defineConfig({
{ label: 'Amazon Bedrock Agent', link: '/agents/built-in/amazon-bedrock-agent' },
{ label: 'Amazon Lex Bot Agent', link: '/agents/built-in/lex-bot-agent' },
{ label: 'AWS Lambda Agent', link: '/agents/built-in/lambda-agent' },
{ label: 'OpenAI Agent', link: '/agents/built-in/openai-agent' }
{ label: 'OpenAI Agent', link: '/agents/built-in/openai-agent' },
{ label: 'Chain Agent', link: '/agents/built-in/chain-agent' },
{ label: 'Comprehend Filter Agent', link: '/agents/built-in/comprehend-filter-agent' },
{ label: 'Amazon Bedrock Translator Agent', link: '/agents/built-in/bedrock-translator-agent' }
]
},
{ label: 'Custom Agents', link: '/agents/custom-agents' },
Expand Down
15 changes: 8 additions & 7 deletions docs/src/content/docs/agents/built-in/bedrock-llm-agent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Documentation for the BedrockLLMAgent in the Multi-Agent Orchestrat
---
## Overview

The `BedrockLLMAgent` is a powerful and flexible agent class in the Multi-Agent Orchestrator System. It leverages [Amazon Bedrock's Converse API](https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference.html) to interact with various LLMs supported by Amazon Bedrock.
The **Bedrock LLM Agent** is a powerful and flexible agent class in the Multi-Agent Orchestrator System. It leverages [Amazon Bedrock's Converse API](https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference.html) to interact with various LLMs supported by Amazon Bedrock.

This agent can handle a wide range of processing tasks, making it suitable for diverse applications such as conversational AI, question-answering systems, and more.

Expand All @@ -20,11 +20,11 @@ This agent can handle a wide range of processing tasks, making it suitable for d

## Creating a BedrockLLMAgent

By default, the Bedrock LLM Agent uses the `anthropic.claude-3-haiku-20240307-v1:0` model.
By default, the **Bedrock LLM Agent** uses the `anthropic.claude-3-haiku-20240307-v1:0` model.

### Basic Example

To create a new `BedrockLLMAgent` with only the required parameters, use the following code:
To create a new **Bedrock LLM Agent** with only the required parameters, use the following code:

import { Tabs, TabItem } from '@astrojs/starlight/components';

Expand Down Expand Up @@ -55,7 +55,7 @@ In this basic example, only the `name` and `description` are provided, which are

### Advanced Example

For more complex use cases, you can create a BedrockLLMAgent with all available options. All parameters except `name` and `description` are optional:
For more complex use cases, you can create a **Bedrock LLM Agent** with all available options. All parameters except `name` and `description` are optional:

<Tabs syncKey="runtime">
<TabItem label="TypeScript" icon="seti:typescript" color="blue">
Expand Down Expand Up @@ -177,7 +177,6 @@ For more complex use cases, you can create a BedrockLLMAgent with all available

## Setting a New Prompt

You can update the agent's system prompt at any time using the `set_system_prompt` method:

<Tabs syncKey="runtime">
<TabItem label="TypeScript" icon="seti:typescript" color="blue">
Expand Down Expand Up @@ -214,7 +213,7 @@ This method allows you to dynamically change the agent's behavior and focus with

## Adding the Agent to the Orchestrator

To integrate the BedrockLLMAgent into your Multi-Agent Orchestrator, follow these steps:
To integrate the **Bedrock LLM Agent** into your orchestrator, follow these steps:

1. First, ensure you have created an instance of the orchestrator:

Expand Down Expand Up @@ -273,4 +272,6 @@ To integrate the BedrockLLMAgent into your Multi-Agent Orchestrator, follow thes
</TabItem>
</Tabs>

By leveraging the `BedrockLLMAgent`, you can create sophisticated, context-aware AI agents capable of handling a wide range of tasks and interactions, all powered by the latest LLM models available through Amazon Bedrock.
---

By leveraging the **Bedrock LLM Agent**, you can create sophisticated, context-aware AI agents capable of handling a wide range of tasks and interactions, all powered by the latest LLM models available through Amazon Bedrock.
276 changes: 276 additions & 0 deletions docs/src/content/docs/agents/built-in/bedrock-translator-agent.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
---
title: Bedrock Translator Agent
description: Documentation for the Bedrock Translator Agent in the Multi-Agent Orchestrator System
---

The `BedrockTranslatorAgent` uses Amazon Bedrock's language models to translate text between different languages.

## Key Features

- Utilizes Amazon Bedrock's language models
- Supports translation between multiple languages
- Allows dynamic setting of source and target languages
- Can be used standalone or as part of a [ChainAgent](/multi-agent-orchestrator/agents/built-in/chain-agent)
- Configurable inference parameters for fine-tuned control

## Creating a Bedrock Translator Agent

### Basic Example

To create a new `BedrockTranslatorAgent` with minimal configuration:

import { Tabs, TabItem } from '@astrojs/starlight/components';

<Tabs syncKey="runtime">
<TabItem label="TypeScript" icon="seti:typescript" color="blue">
```typescript
import { BedrockTranslatorAgent, BedrockTranslatorAgentOptions } from 'multi-agent-orchestrator';

const agent = new BedrockTranslatorAgent({
name: 'BasicTranslator',
description: 'Translates text to English',
targetLanguage: 'English'
});
```
</TabItem>
<TabItem label="Python" icon="seti:python">
```python
from multi_agent_orchestrator.agents import BedrockTranslatorAgent, BedrockTranslatorAgentOptions
agent = BedrockTranslatorAgent(BedrockTranslatorAgentOptions(
name='BasicTranslator',
description='Translates text to English',
target_language='English'
))
```
</TabItem>
</Tabs>

### Advanced Example

For more complex use cases, you can create a BedrockTranslatorAgent with custom settings:

<Tabs syncKey="runtime">
<TabItem label="TypeScript" icon="seti:typescript" color="blue">
```typescript
import { BedrockTranslatorAgent, BedrockTranslatorAgentOptions, BEDROCK_MODEL_ID_CLAUDE_3_SONNET } from 'multi-agent-orchestrator';
const options: BedrockTranslatorAgentOptions = {
name: 'AdvancedTranslator',
description: 'Advanced translator with custom settings',
sourceLanguage: 'French',
targetLanguage: 'German',
modelId: BEDROCK_MODEL_ID_CLAUDE_3_SONNET,
region: 'us-west-2',
inferenceConfig: {
maxTokens: 2000,
temperature: 0.1,
topP: 0.95,
stopSequences: ['###']
}
};
const agent = new BedrockTranslatorAgent(options);
```
</TabItem>
<TabItem label="Python" icon="seti:python">
```python
from multi_agent_orchestrator.agents import BedrockTranslatorAgent, BedrockTranslatorAgentOptions
from multi_agent_orchestrator.types import BEDROCK_MODEL_ID_CLAUDE_3_SONNET
options = BedrockTranslatorAgentOptions(
name='AdvancedTranslator',
description='Advanced translator with custom settings',
source_language='French',
target_language='German',
model_id=BEDROCK_MODEL_ID_CLAUDE_3_SONNET,
region='us-west-2',
inference_config={
'maxTokens': 2000,
'temperature': 0.1,
'topP': 0.95,
'stopSequences': ['###']
}
)
agent = BedrockTranslatorAgent(options)
```
</TabItem>
</Tabs>

## Dynamic Language Setting

To set the language during the invocation:

<Tabs syncKey="runtime">
<TabItem label="TypeScript" icon="seti:typescript" color="blue">
```typescript
import { MultiAgentOrchestrator, BedrockTranslatorAgent } from 'multi-agent-orchestrator';
const translator = new BedrockTranslatorAgent({
name: 'DynamicTranslator',
description: 'Translator with dynamically set languages'
});
const orchestrator = new MultiAgentOrchestrator();
orchestrator.addAgent(translator);
async function translateWithDynamicLanguages(text: string, fromLang: string, toLang: string) {
translator.setSourceLanguage(fromLang);
translator.setTargetLanguage(toLang);
const response = await orchestrator.routeRequest(
text,
'user123',
'session456'
);
console.log(`Translated from ${fromLang} to ${toLang}:`, response);
}
// Usage
translateWithDynamicLanguages("Hello, world!", "English", "French");
translateWithDynamicLanguages("Bonjour le monde!", "French", "Spanish");
```
</TabItem>
<TabItem label="Python" icon="seti:python">
```python
from multi_agent_orchestrator.orchestrator import MultiAgentOrchestrator
from multi_agent_orchestrator.agents import BedrockTranslatorAgent, BedrockTranslatorAgentOptions
translator = BedrockTranslatorAgent(BedrockTranslatorAgentOptions(
name='DynamicTranslator',
description='Translator with dynamically set languages'
))
orchestrator = MultiAgentOrchestrator()
orchestrator.add_agent(translator)
async def translate_with_dynamic_languages(text: str, from_lang: str, to_lang: str):
translator.set_source_language(from_lang)
translator.set_target_language(to_lang)
response = await orchestrator.route_request(
text,
'user123',
'session456'
)
print(f"Translated from {from_lang} to {to_lang}:", response)
# Usage
import asyncio
asyncio.run(translate_with_dynamic_languages("Hello, world!", "English", "French"))
asyncio.run(translate_with_dynamic_languages("Bonjour le monde!", "French", "Spanish"))
```
</TabItem>
</Tabs>

## Usage with ChainAgent

The `BedrockTranslatorAgent` can be effectively used within a `ChainAgent` for complex multilingual processing workflows. Here's an example that demonstrates translating user input and processing it:

<Tabs syncKey="runtime">
<TabItem label="TypeScript" icon="seti:typescript" color="blue">
```typescript
import { MultiAgentOrchestrator, ChainAgent, BedrockTranslatorAgent, BedrockLLMAgent } from 'multi-agent-orchestrator';
// Create translator agents
const translatorToEnglish = new BedrockTranslatorAgent({
name: 'TranslatorToEnglish',
description: 'Translates input to English',
targetLanguage: 'English'
});
// Create a processing agent (e.g., a BedrockLLMAgent)
const processor = new BedrockLLMAgent({
name: 'EnglishProcessor',
description: 'Processes text in English'
});
// Create a ChainAgent
const chainAgent = new ChainAgent({
name: 'TranslateProcessTranslate',
description: 'Translates, processes, and translates back',
agents: [translatorToEnglish, processor]
});
const orchestrator = new MultiAgentOrchestrator();
orchestrator.addAgent(chainAgent);
// Function to handle user input
async function handleMultilingualInput(input: string, sourceLanguage: string) {
translatorToEnglish.setSourceLanguage(sourceLanguage);
const response = await orchestrator.routeRequest(
input,
'user123',
'session456'
);
console.log('Response:', response);
}
// Usage
handleMultilingualInput("Hola, ¿cómo estás?", "Spanish");
```
</TabItem>
<TabItem label="Python" icon="seti:python">
```python
from multi_agent_orchestrator.orchestrator import MultiAgentOrchestrator
from multi_agent_orchestrator.agents import ChainAgent, BedrockTranslatorAgent, BedrockLLMAgent
from multi_agent_orchestrator.agents import ChainAgentOptions, BedrockTranslatorAgentOptions, BedrockLLMAgentOptions
# Create translator agents
translator_to_english = BedrockTranslatorAgent(BedrockTranslatorAgentOptions(
name='TranslatorToEnglish',
description='Translates input to English',
target_language='English'
))
# Create a processing agent (e.g., a BedrockLLMAgent)
processor = BedrockLLMAgent(BedrockLLMAgentOptions(
name='EnglishProcessor',
description='Processes text in English'
))
# Create a ChainAgent
chain_agent = ChainAgent(ChainAgentOptions(
name='TranslateProcessTranslate',
description='Translates, processes, and translates back',
agents=[translator_to_english, processor]
))
orchestrator = MultiAgentOrchestrator()
orchestrator.add_agent(chain_agent)
# Function to handle user input
async def handle_multilingual_input(input_text: str, source_language: str):
translator_to_english.set_source_language(source_language)
response = await orchestrator.route_request(
input_text,
'user123',
'session456'
)
print('Response:', response)
# Usage
import asyncio
asyncio.run(handle_multilingual_input("Hola, ¿cómo estás?", "Spanish"))
```
</TabItem>
</Tabs>

In this example:
1. The first translator agent converts the input to English.
2. The processor agent (e.g., a `BedrockLLMAgent`) processes the English text.

This setup allows for seamless multilingual processing, where the core logic can be implemented in English while supporting input and output in various languages.

---

By leveraging the `BedrockTranslatorAgent`, you can create sophisticated multilingual applications and workflows, enabling seamless communication and processing across language barriers in your Multi-Agent Orchestrator system.
Loading

0 comments on commit 6200acb

Please sign in to comment.