🌐 AzureAICommunity - Agent - Language Middleware
Automatic language detection, translation, and response back-translation middleware for AI agent applications built on the Agent Framework.
Your agent always reasons in its best language — your users always receive replies in theirs.
Overview
azureaicommunity-agent-language-middleware is a plug-and-play translation layer for AI agent pipelines built on agent-framework. It automatically detects the user's language, translates incoming messages to the agent's target language, and back-translates the response — using Azure Translator with an optional LLM agent as fallback.
✨ Features
| Feature | |
|---|---|
| 🔍 | Language detection — automatically detect the user's language with configurable confidence threshold |
| 🔄 | Round-trip translation — translate incoming messages and back-translate agent responses |
| ☁️ | Azure Translator — production-grade speed and accuracy with 100+ languages |
| 🤖 | LLM fallback — silently falls back to LLM translation when Azure is unavailable |
| 🔧 | Builder pattern — fluent create() API to compose and customize middleware |
| 🔌 | Framework integration — drops directly into agent-framework middleware pipelines |
📦 Installation
pip install azureaicommunity-agent-language-middleware
🚀 Quick Start
import asyncio
from agent_framework import Agent
from agent_framework.ollama import OllamaChatClient
from language_middleware import LanguageTranslationMiddleware
async def main():
client = OllamaChatClient(model="gemma3:4b")
agent = Agent(client)
middleware = LanguageTranslationMiddleware.create(
llm_agent=agent,
target_language="en",
)
try:
result = await agent.run("Wie heißt die Hauptstadt von Frankreich?", middleware=middleware)
print(result.text) # "Die Hauptstadt von Frankreich ist Paris."
finally:
await middleware.aclose()
asyncio.run(main())
⚙️ Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
target_language |
str |
"en" |
ISO 639-1 code of the language the agent should reason in |
min_confidence |
float |
0.8 |
Minimum detection confidence to skip translation |
azure_config |
AzureTranslatorConfig |
None |
Azure Translator credentials (optional) |
llm_agent |
Agent |
None |
LLM agent used as translation fallback or primary service |
🧑💻 Usage
Option 1 — Azure Translator + LLM Fallback (Recommended)
import asyncio
import os
from agent_framework import Agent
from agent_framework.ollama import OllamaChatClient
from language_middleware import LanguageTranslationMiddleware, AzureTranslatorConfig
azure_config = AzureTranslatorConfig(
key=os.environ.get("AZURE_TRANSLATOR_KEY", ""),
region=os.environ.get("AZURE_TRANSLATOR_REGION", ""),
endpoint=os.environ.get("AZURE_TRANSLATOR_ENDPOINT", ""),
)
async def main():
client = OllamaChatClient(model="gemma3:4b")
agent = Agent(client)
middleware = LanguageTranslationMiddleware.create(
azure_config=azure_config,
target_language="en",
min_confidence=0.8,
llm_agent=agent,
)
try:
tamil_query = "தஞ்சாவூரின் வரலாற்று சிறப்பு என்ன?"
tamil_result = await agent.run(tamil_query, middleware=middleware)
print("Tamil response:", tamil_result.text)
german_query = "Was ist die historische Bedeutung von Thanjavur?"
german_result = await agent.run(german_query, middleware=middleware)
print("German response:", german_result.text)
finally:
await middleware.aclose()
asyncio.run(main())
Option 2 — LLM-Only (No Azure Subscription Required)
import asyncio
from agent_framework import Agent
from agent_framework.ollama import OllamaChatClient
from language_middleware import LanguageTranslationMiddleware
async def main():
client = OllamaChatClient(model="gemma3:4b")
agent = Agent(client)
middleware = LanguageTranslationMiddleware.create(
llm_agent=agent,
target_language="en",
)
try:
result = await agent.run("Wie heißt die Hauptstadt von Frankreich?", middleware=middleware)
print(result.text) # "Die Hauptstadt von Frankreich ist Paris."
finally:
await middleware.aclose()
asyncio.run(main())
Option 3 — Azure Only (No LLM Fallback)
middleware = LanguageTranslationMiddleware.create(
azure_config=azure_config,
target_language="en",
)
⚙️ How It Works
1. Intercept → middleware captures the last user message
2. Detect → language is detected with a confidence score
3. Translate → message is translated to the target language (if needed)
4. Agent runs → the primary LLM processes the translated message
5. Back-translate → agent response is translated back to the user's original language
6. Return → user receives the response in their native language
Translation providers (with automatic fallback):
| Priority | Provider | Capability |
|---|---|---|
| 1st | Azure Translator | Detect language + translate (fast, accurate, 100+ languages) |
| 2nd | LLM Agent (fallback) | Detect language + translate when Azure is unavailable |
🤝 Contributing
Contributions are welcome! Please open an issue to discuss what you'd like to change before submitting a pull request.
- Fork the repository
- Create a feature branch (
git checkout -b feature/my-feature) - Commit your changes (
git commit -m 'Add my feature') - Push to the branch (
git push origin feature/my-feature) - Open a Pull Request
📄 License
MIT — see LICENSE for details.
Metadata
Release files for azureaicommunity-agent-language-middleware 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| azureaicommunity_agent_language_middleware-0.1.0.tar.gz | 8.8 kB | Without provenance | Details for azureaicommunity_agent_language_middleware-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| azureaicommunity_agent_language_middleware-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for azureaicommunity_agent_language_middleware-0.1.0-py3-none-any.whl |
Total release size: 19.5 kB
Release files / azureaicommunity_agent_language_middleware-0.1.0.tar.gz
| Download URL | azureaicommunity_agent_language_middleware-0.1.0.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
de60a6e3f3544a5a6d3e837d31eda664f553f3495c3244cfd2461c21c16cf1e0
|
|
BLAKE2b-256 checksum How to use checksums |
50cfd889acc137fbd26a9e6f2a50062f3151fb92047db6e3bbb9fa0f439107ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / azureaicommunity_agent_language_middleware-0.1.0-py3-none-any.whl
| Download URL | azureaicommunity_agent_language_middleware-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2a3698f751bdd08667024e88e393697c9dd5ba53e767e16692c7fdafb004ce3f
|
|
BLAKE2b-256 checksum How to use checksums |
6890038d18638371c0f1cedbc14a0f3f3c203f9d86e66aae946a55b5a7bc1271
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Security for azureaicommunity-agent-language-middleware 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.