Skip to content

🍳 Cookbook: Agentic Translation Engine

Build an intelligent translation service that goes beyond simple textβ€”handling PDFs, images (via OCR), and multi-language documents with AI-powered quality checking.

🎯 What You'll Build

A service that: 1. Translates text between 20+ languages 2. Processes files (PDF, images, Markdown) 3. Uses AI to validate translation quality


πŸ—οΈ Phase 1: Clone & Setup

1. Get the Code

git clone https://github.com/traylinx/agentic-translation-engines.git
cd agentic-translation-engines

2. Install Dependencies

pip install -r requirements.txt

3. Configure Environment

cp .env.sample .env
nano .env

Key Variables:

# LLM Configuration
LLM_MODEL=gpt-4o
LLM_API_KEY=your-api-key
LLM_BASE_URL=https://switchai.traylinx.com/v1

# File Engine (Required for PDF/OCR)
FILE_ENGINE_BASE_URL=https://api.traylinx.com/file-engine


πŸš€ Phase 2: Run the Service

uvicorn api:app --reload
# Server running at http://localhost:8000

πŸ§ͺ Phase 3: Basic Text Translation

Simple Translation Request

curl -X POST http://localhost:8000/v1/translate \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Hello, how are you today?",
    "source_language": "en",
    "target_language": "es"
  }'

Response:

{
  "translated_text": "Hola, ΒΏcΓ³mo estΓ‘s hoy?",
  "source_language": "en",
  "target_language": "es",
  "quality_score": 0.95
}


πŸ“„ Phase 4: Document Translation

Translate a PDF

curl -X POST http://localhost:8000/v1/translate/document \
  -H "Authorization: Bearer your-token" \
  -F "file=@contract.pdf" \
  -F "target_language=de"

What Happens: 1. File Engine extracts text (uses OCR if needed) 2. Translator Agent translates content 3. Quality Checker validates accuracy 4. Returns translated document


πŸ”„ Phase 5: The Agentic Workflow

The translation engine uses a multi-agent orchestration pattern:

          Document
             β”‚
             β–Ό
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚ File Engine   β”‚ ← Extract text, handle OCR
     β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚
             β–Ό
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚  Translator   β”‚ ← LLM-powered translation
     β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚
             β–Ό
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚Quality Checkerβ”‚ ← Validates accuracy, suggests fixes
     β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”
     β”‚  Pass?        β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
        No   β”‚   Yes
             β–Ό
       [Retry Loop] β†’ Final Output

The Orchestrator manages retries if the Quality Checker finds issues.


🌍 Supported Languages

Language Code Language Code
English en Spanish es
French fr German de
Italian it Portuguese pt
Japanese ja Korean ko
Chinese (Simplified) zh Arabic ar
Russian ru Hindi hi

And many more!


πŸ” Phase 6: Enable A2A Authentication

Let other agents use your translation service.

Add to .env

TRAYLINX_CLIENT_ID=ag-xxx
TRAYLINX_CLIENT_SECRET=ts-xxx

Call as an Agent

curl -X POST http://localhost:8000/v1/translate \
  -H "X-Agent-Secret-Token: your-token" \
  -H "X-Agent-User-Id: your-agent-id" \
  -H "Content-Type: application/json" \
  -d '{"text": "Bonjour", "target_language": "en"}'

πŸ“š Next Steps

  • Integrate batch translation for large document sets
  • Add custom glossaries for domain-specific terms
  • Deploy to Kubernetes for production scale