Skip to content

Commit 01849c5

Browse files
authored
Merge pull request #125 from mikaelsitruk/mikaels/language-agents-fixes
Mikaels/language agents fixes
2 parents 51cec73 + cedce84 commit 01849c5

File tree

5 files changed

+60
-28
lines changed

5 files changed

+60
-28
lines changed
Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
# Text Translation Agent
22

3-
This code sample helps create agents that handle multilingual text processing, including dynamic language detection and bidirectional translation using Azure AI Translator service.
3+
This code sample helps create agents that handle multilingual text processing, including dynamic language detection and bidirectional translation using Azure AI Translator service.
44

55
**IMPORTANT NOTE:** Starter templates, instructions, code samples and resources in this msft-agent-samples file (“samples”) are designed to assist in accelerating development of agents for specific scenarios. It is important that you review all provided resources and carefully test Agent behavior in the context of your use case: ([Learn More](https://learn.microsoft.com/en-us/legal/cognitive-services/agents/transparency-note?context=%2Fazure%2Fai-services%2Fagents%2Fcontext%2Fcontext)).
66

77
Certain Agent offerings may be subject to legal and regulatory requirements, may require licenses, or may not be suitable for all industries, scenarios, or use cases. By using any sample, you are acknowledging that Agents or other output created using that sample are solely your responsibility, and that you will comply with all applicable laws, regulations, and relevant safety standards, terms of service, and codes of conduct.
88

99
## Use Cases
10+
1011
1. **Text Translation**: Translate text between multiple languages for seamless communication.
1112
2. **Business Communication**: Enable businesses to localize content for global audiences.
1213
3. **Educational Content**: Translate learning materials to make them accessible to non-native speakers.
1314

1415
## Architecture Overview
16+
1517
The system consists of:
18+
1619
- An AI Agent created with Azure AI Agent Service using `gpt-4o` as the base model.
17-
- Azure AI Translator integrated for language detection and translation.
20+
- Azure AI Services resource for accessing language translation feature.
1821
- A Bicep template to automate provisioning of Azure resources.
1922

2023
```text
24+
2125
+----------------+
2226
| User Query |
2327
| (Any Language) |
@@ -39,6 +43,7 @@ The system consists of:
3943
## Setup Instructions
4044

4145
### Prerequisites
46+
4247
- Python 3.8+
4348
- Azure CLI
4449
- Azure subscription
@@ -55,55 +60,67 @@ The system consists of:
5560
- For more info about Azure AI Translator service, see [Text translation Overview](https://learn.microsoft.com/en-us/azure/ai-services/translator/text-translation/overview)
5661

5762
### Steps
58-
1. **Clone the Repository**
5963

60-
2. **Set Config Variables**
64+
1. Clone the Repository in the folder of your choice
6165

62-
4. **Run the Agent Script**
6366
```bash
64-
python template.py
67+
git clone https://github.com/azure-ai-foundry/foundry-samples
6568
```
6669

67-
## ⚙️ Configuration Guide
70+
2. Populate the config variables in config.yaml
71+
6872
| Parameter Name | Description |
6973
|----------------------------------------|-----------------------------------------------------------------------------------|
7074
| `project_endpoint` | Endpoint for the project this agent is using |
7175
| `model_name` | Name of the model deployment to be used for the Agent |
7276
| `translator_resource_connection_name` | Name of the translator resource connection added in the agent project |
7377
| `connection_id` | Connection ID for the translator resource connection added in the agent project |
7478

79+
3. Install the requirements
80+
81+
It is recommended to use a virtual environment (via venv or similar) to isolate installation requirements of this sample from other samples.
82+
83+
```bash
84+
pip install -r requirements.txt
85+
```
86+
87+
4. Run the template script
88+
89+
```bash
90+
python template.py
91+
```
92+
7593
## Sample Data Instructions
94+
7695
You can try the sample user messages and test the interaction by invoking the agent with prompts as listed in the next section.
7796

7897
## Example Agent Interaction
79-
### User:
80-
Translate this Chinese poem to English: 白日依山尽,黄河入海流
8198

82-
### Agent:
83-
At the end of the day, the Yellow River flows into the sea.
99+
```text
100+
>User: Translate this Chinese poem to English: 白日依山尽,黄河入海流
101+
102+
>Agent: At the end of the day, the Yellow River flows into the sea.
84103
85-
### User:
86-
translate this text to Chinese, Spanish, and Korean: Translator Agent handles multilingual text processing, including dynamic language detection and bidirectional translation using Translator service. The translator agent is triggered when the user message has the “translation intent”.
104+
>User: translate this text to Chinese, Spanish, and Korean: Translator Agent handles multilingual text processing, including dynamic language detection and bidirectional translation using Translator service. The translator agent is triggered when the user message has the “translation intent”.
87105
88-
### Agent:
89-
Here are the translations:
106+
> Agent: Here are the translations:
90107
91-
Chinese: Translator Agent 处理多语言文本,包括使用 Translator服务的动态语言检测和双向翻译。当用户消息具有 “translation intent” 时,将触发翻译代理。
92-
Spanish: Translator Agent se encarga del procesamiento de texto multilingüe, incluida la detección dinámica de idiomas y la traducción bidireccional mediante el servicio Translator. El agente traductor se activa cuando el mensaje del usuario tiene la "intención de traducción".
93-
Korean: Translator Agent는 Translator 서비스를 사용하여 동적 언어 감지 및 양방향 번역을 포함한 다국어 텍스트 처리를 처리합니다. 변환기 에이전트는 사용자 메시지에 "번역 의도"가 있을 때 트리거됩니다.
108+
Chinese: Translator Agent 处理多语言文本,包括使用 Translator服务的动态语言检测和双向翻译。当用户消息具有 “translation intent” 时,将触发翻译代理。
109+
Spanish: Translator Agent se encarga del procesamiento de texto multilingüe, incluida la detección dinámica de idiomas y la traducción bidireccional mediante el servicio Translator. El agente traductor se activa cuando el mensaje del usuario tiene la "intención de traducción".
110+
Korean: Translator Agent는 Translator 서비스를 사용하여 동적 언어 감지 및 양방향 번역을 포함한 다국어 텍스트 처리를 처리합니다. 변환기 에이전트는 사용자 메시지에 "번역 의도"가 있을 때 트리거됩니다.
94111
95-
### User:
96-
localize this text to Japanese and Germany: The agent can detect the source language for the input text unless the source language is defined in the user message.
112+
> User: localize this text to Japanese and Germany: The agent can detect the source language for the input text unless the source language is defined in the user message.
97113
98-
### Agent:
99-
Here are the localized texts:
114+
> Agent: Here are the localized texts:
100115
101-
Japanese: エージェントは、入力テキストのソース言語を検出できます。ただし、ソース言語がユーザー・メッセージで定義されていない場合に限ります。
102-
German: Der Agent kann die Ausgangssprache für den Eingabetext erkennen, es sei denn, die Ausgangssprache ist in der Benutzermeldung definiert.
116+
Japanese: エージェントは、入力テキストのソース言語を検出できます。ただし、ソース言語がユーザー・メッセージで定義されていない場合に限ります。
117+
German: Der Agent kann die Ausgangssprache für den Eingabetext erkennen, es sei denn, die Ausgangssprache ist in der Benutzermeldung definiert.
103118
104119
## Customization Tips
120+
105121
- Modify the system instructions in `template.py` to your specif needs (e.g., special handling on some terminologies).
106122
- Extend the agent with other useful tools or APIs (using OpenAPI spec).
107123
108124
## License
125+
109126
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.

samples/agent-catalog/msft-agent-samples/foundry-agent-service-sdk/text-translation-agent/config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ model_name:
77
# The connection name of the above resource when added in the Azure AI Foundry portal to your project
88
translator_resource_connection_name:
99

10+
# the region when the translator resource/AI service resource was created.
11+
translator_resource_region:
12+
1013
# Go to the page of above connection in the Azure AI Foundry portal, then construct the connection ID by append "/connections/<language_resource_connection_name>" to the wsid parameter value in the page URL.
1114
# For example, if the connection page URL contains "wsid=/subscriptions/<subscription_id>/resourceGroups/<resource_group_name>/providers/Microsoft.CognitiveServices/accounts/<account_name>/projects/<project_name>",
1215
# Then the connection ID is /subscriptions/<subscription_id>/resourceGroups/<resource_group_name>/providers/Microsoft.CognitiveServices/accounts/<account_name>/projects/<project_name>/connections/<language_resource_connection_name>

samples/agent-catalog/msft-agent-samples/foundry-agent-service-sdk/text-translation-agent/requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
artifacts-keyring==0.4.0
2-
azure-ai-agents==1.0.0a20250506003
2+
#azure-ai-agents==1.0.0a20250506003
3+
azure-ai-agents==1.0.0
34
azure-core==1.34.0
45
azure-identity==1.22.0
56
azure-storage-blob==12.26.0b1
@@ -24,3 +25,4 @@ requests==2.32.3
2425
six==1.17.0
2526
typing_extensions==4.13.2
2627
urllib3==2.4.0
28+
PyYAML==6.0.2

samples/agent-catalog/msft-agent-samples/foundry-agent-service-sdk/text-translation-agent/template.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
# Create the agent
4040
agent = agents_client.create_agent(
4141
model=model_name,
42-
name="My_Translator_Agent",
43-
instructions="You are a translation agent. The user can use any language to interface with you and please answer in the same language as the customer. " +
42+
name="ms-translator",
43+
instructions="You are a translation agent. The user can use any language to interface with you and please answer in the same language as the user used. " +
4444
"Any translation asks must be performed via a call to the translator_api. In case of failure to call the translator_api indicate what was the failure",
4545
tools=translator_api_tool.definitions
4646
)
@@ -73,6 +73,6 @@
7373
last_text = msg.text_messages[-1]
7474
print(f"{msg.role}: {last_text.text.value}")
7575

76-
# Delete the Agent when done
76+
# Delete the Agent when done
7777
agents_client.delete_agent(agent.id)
7878
print("Deleted agent")

samples/agent-catalog/msft-agent-samples/foundry-agent-service-sdk/text-translation-agent/translator.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424
"description": "Translates text into one or more languages.",
2525
"operationId": "Translator_Translate",
2626
"parameters": [
27+
{
28+
"name": "ocp-apim-subscription-region",
29+
"in": "header",
30+
"description": "the local region of the endpoint",
31+
"required": true,
32+
"schema": {
33+
"type": "string",
34+
"default": "${translator_resource_region}"
35+
}
36+
},
2737
{
2838
"name": "api-version",
2939
"in": "query",

0 commit comments

Comments
 (0)