Why Polyglot Task Apps?
- Use your preferred language - No need to rewrite existing code in Python
- Better performance - Compiled languages can be faster for CPU-intensive tasks
- Smaller deployments - Single binaries with no runtime dependencies
- Existing codebases - Integrate directly with your current infrastructure
- No Python required - Start optimization jobs via API calls
How It Works
/rollout endpoint with candidate prompts, and you return a reward indicating how well each prompt performed. That’s it.
The Contract
All Task Apps implement the same OpenAPI contract, regardless of language: Required Endpoints:GET /health- Health check (unauthenticated OK)POST /rollout- Evaluate a prompt (authenticated)
GET /task_info- Dataset metadata (authenticated)
env.seed- Dataset indexpolicy.config.inference_url- LLM endpoint (see notes below)policy.config.prompt_template- The prompt to evaluate
metrics.mean_return- Reward (0.0-1.0) that drives optimizationtrajectories[].steps[].reward- Per-step reward
Accessing the OpenAPI Contract
The Task App contract is available through multiple methods, so you can access it without installing Python or any dependencies:1. Via CLI (Recommended for Developers)
If you have the Synth CLI installed:2. Direct Download (No Installation Required)
Download the contract directly from GitHub:3. Via Python SDK
If you’re working in Python:4. View in Browser
- GitHub: task_app.yaml
- Raw URL: https://raw.githubusercontent.com/synth-laboratories/synth-ai/main/synth_ai/contracts/task_app.yaml
Using the Contract with Code Generators
Once you have the contract, you can generate types for your language: For Rust:Contract Contents
The OpenAPI specification includes:- Complete type definitions for all request/response schemas
- Detailed field descriptions explaining what each field means
- Behavioral documentation describing how to implement
/rollout - Authentication requirements for each endpoint
- Example payloads for common scenarios
- Error response schemas for proper error handling
Authentication
Task Apps involve two separate authentication flows:1. Task App Authentication (X-API-Key)
Requests to your task app from the optimizer include an X-API-Key header. This authenticates the optimizer to your task app.
X-API-Key matches ENVIRONMENT_API_KEY on /rollout and /task_info endpoints.
2. LLM API Authentication (Authorization: Bearer)
When your task app makes requests to OpenAI/Groq/etc, you need to add a Bearer token:
X-API-Key header from the optimizer is for task app auth only - do NOT forward it to the LLM API.
Banking77 Examples
All examples below implement the same Banking77 intent classification task. They share a common dataset file and produce identical results.Rust
Features:- Fast, type-safe implementation using Axum
- Async/await with Tokio runtime
- Strong compile-time guarantees
- Tested end-to-end with MIPRO - achieves 100% accuracy
inference_url from the optimizer includes query params for tracing:
Go
Features:- Zero external dependencies (uses only Go standard library)
- Single static binary
- Built-in cross-compilation
- Excellent concurrency with goroutines
- Tested end-to-end with MIPRO - achieves 100% accuracy
TypeScript
Features:- Uses Hono - fast, lightweight web framework
- Works with Node.js, Deno, Bun, and Cloudflare Workers
- Type-safe with full TypeScript support
- Easy deployment to edge platforms
- Install Wrangler:
npm install -g wrangler - Create
wrangler.toml: - Modify for Workers (replace the serve() call with
export default app;) - Deploy:
wrangler deploy
Zig
Features:- Zero external dependencies (uses only Zig standard library)
- Single static binary (~1-5MB optimized)
- Trivial cross-compilation to any target
- No garbage collection (predictable latency)
- Requires Zig 0.15+ (uses new HTTP client and I/O APIs)
Running Optimization (No Python Required!)
You can start optimization jobs directly via API calls, without installing the Python SDK:Shared Dataset
All examples load from the same dataset file for consistency:Project Structure
Customizing for Your Task
To adapt these examples for your own task:- Replace the dataset - Load your own data in the appropriate format
- Update the tool schema - Modify the
classifytool to match your output format - Adjust reward computation - Change how you compare predictions to ground truth
- Update task metadata - Modify the
/task_inforesponse to reflect your task
- Parse the rollout request
- Extract the seed and load your data
- Render the prompt template with your data
- Call the LLM via
inference_url/chat/completions - Parse the response and compute reward
- Return the rollout response
Performance Characteristics
| Language | Binary Size | Dependencies | Startup Time | Cross-Compile |
|---|---|---|---|---|
| Rust | ~5-10MB | Some | Fast (~50ms) | Yes (via rustup) |
| Go | ~8-12MB | None | Very Fast (~10ms) | Yes (built-in) |
| TypeScript | N/A (Node) | Many | Medium (~200ms) | N/A |
| Zig | ~1-5MB | None | Very Fast (~10ms) | Yes (trivial) |
Language Recommendations
Choose Rust if:- You want strong type safety and compile-time guarantees
- You need async/await for concurrent processing
- You’re comfortable with Rust’s ownership model
- You want zero dependencies and simple deployment
- You need excellent concurrency with goroutines
- You prefer a simpler learning curve
- You’re already in the Node.js ecosystem
- You want to deploy to edge platforms (Cloudflare Workers)
- You prefer JavaScript’s familiar syntax
- You want the smallest possible binaries
- You need trivial cross-compilation
- You want no garbage collection for predictable latency
- You’re comfortable with a newer language
Debugging Tips
Testing Locally
Test your task app with curl before connecting to the optimizer:Common Issues
- 404 errors from LLM endpoint: Check that you’re constructing the URL correctly with query parameters BEFORE
/chat/completions - Authentication failures: Verify that
X-API-KeymatchesENVIRONMENT_API_KEY - Missing rewards: Ensure
rewardfield is present in each step’s response - Tool call parsing: Make sure you’re extracting predictions from
tool_callsorcontentcorrectly
Examples Repository
All polyglot examples are available in the synth-ai repository:Next Steps
- Try running one of the examples locally
- Customize the dataset for your use case
- Deploy to production using Cloudflare Tunnel
- Start optimization via the API
- Check out the Deployed Task App Walkthrough for a step-by-step guide