Skip to content

Bedrock Translator Agent

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

  • 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
  • Configurable inference parameters for fine-tuned control

If you haven’t already installed the AWS-related dependencies, make sure to install them:

Terminal window
pip install "agent-squad[aws]"

To create a new BedrockTranslatorAgent with minimal configuration:

import { BedrockTranslatorAgent, BedrockTranslatorAgentOptions } from 'agent-squad';
const agent = new BedrockTranslatorAgent({
name: 'BasicTranslator',
description: 'Translates text to English',
targetLanguage: 'English'
});

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

import { BedrockTranslatorAgent, BedrockTranslatorAgentOptions, BEDROCK_MODEL_ID_CLAUDE_3_SONNET } from 'agent-squad';
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);

To set the language during the invocation:

import { AgentSquad, BedrockTranslatorAgent } from 'agent-squad';
const translator = new BedrockTranslatorAgent({
name: 'DynamicTranslator',
description: 'Translator with dynamically set languages'
});
const orchestrator = new AgentSquad();
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");

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:

import { AgentSquad, ChainAgent, BedrockTranslatorAgent, BedrockLLMAgent } from 'agent-squad';
// 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 AgentSquad();
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");

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 Agent Squad system.