How arming-afk/hybrid-token-router works
1. Overall shape
- This is a Python batch inference service for the Fireworks AI judging/proxy environment.
- The core path is: read tasks from an input JSON file, route each task to a category, choose a model tier, build a prompt, call Fireworks concurrently, then write results.json.
2. Process boundary and I/O
- src/main.py is the runtime entrypoint.
- It reads /input/tasks.json (or a path from env/tests) and must always emit a valid /output/results.json, even on partial failure.
- This makes the app a file-in/file-out worker rather than a server.
3. Task routing subsystem
- src/router.py classifies each task into one of 8 categories using regex-based local heuristics.
- Only ambiguous inputs fall back to a small LLM-based classification, which is intentionally minimized to reduce token spend.
- The router is a key architectural boundary because it decides the downstream prompt/model path before any expensive API call.
4. Model tiering subsystem
- src/models.py takes ALLOWED_MODELS from the environment and organizes them into SMALL / MEDIUM / LARGE tiers.
- It parses model parameter counts and sorts available models by size.
- This module separates “what models are allowed by the runtime” from “which model tier a task category should use.”
5. Prompt construction subsystem
- src/prompts.py maps each category to a tier, a compact instruction, and a max_tokens budget.
- This is the primary tuning surface for token efficiency and answer quality.
- The interface is shared and stable: category in, messages plus token cap and tier out.
6. External inference boundary
- src/client.py encapsulates all Fireworks API calls and routes them through FIREWORKS_BASE_URL.
- The repository treats the proxy as mandatory; bypassing it would break scoring assumptions.
- The client is the only place where network interaction with the LLM provider should occur.
7. Execution flow inside the main worker
- src/main.py orchestrates the full pipeline: load tasks, route each task, render prompts, select a model, send calls concurrently, and aggregate outputs.
- The concurrency is important because the harness enforces a deadline; the code is designed to finish well before the 10-minute kill limit.
- The output format is kept valid regardless of errors so the harness can still consume the file.
8. Supporting scripts and local simulation
- scripts/run_local.sh is the Docker-based harness simulation.
- scripts/eval_matrix.py and scripts/token_report.py support offline evaluation and token accounting.
- These scripts are operational tooling around the same main pipeline, not separate application logic.
9. Test and evaluation structure
- tests/ contains focused unit tests for client, main, models, prompts, and router.
- tests/router_cases.json and the tests/eval/*.json files encode domain-specific evaluation sets for the 8 task categories.
- docs/eval-results.md appears to track benchmark or tuning outcomes, which suggests an iteration loop centered on routing accuracy and token usage.
10. Packaging and release
- Dockerfile packages the worker for the competition harness.
- .github/workflows/release.yml indicates a CI/CD path for building or publishing submission artifacts.
- The repo is designed to run identically in local Docker and in the external scoring environment.
11. Architectural dependencies that matter
- Runtime is Python with dependencies from requirements.txt.
- External service dependency is Fireworks AI, accessed via environment variables for key/base URL/model list.
- The architecture is optimized around two constraints: accuracy under an LLM judge and token minimization at the proxy.
12. What to draw in a diagram
- A single batch worker node at the center.
- Input JSON file on the left, output JSON file on the right.
- Inside the worker, show a routing stage, a tier-selection stage, a prompt-rendering stage, and an API client boundary to Fireworks AI.
- Around it, show test/eval assets and Docker/CI as supporting build-and-validation layers.
Main entry points: main.py Worker · scripts Ops scripts · tests Tests · router.py Router
Components 19
Runtime worker
Batch inference path that loads tasks, routes them, calls Fireworks, and writes results.
- Input tasks · Batch tasks read from /input/tasks.json or a test override path.
tests/sample_tasks.json - Worker · Entry point that loads tasks, routes each item, builds prompts, runs concurrent inference, and always writes results.
src/main.py - Router · Regex-first task classifier that assigns one of the 8 categories with minimal LLM fallback.
src/router.py - Model tiers · Parses allowed models and organizes them into SMALL, MEDIUM, and LARGE tiers.
src/models.py - Prompt map · Maps category to tier, instruction, and token budget; returns messages plus max_tokens.
src/prompts.py - Fireworks client · Encapsulates all network calls to Fireworks through the proxy base URL.
src/client.py - Output results · Valid results file emitted even when some tasks fail.
tests/sample_tasks.json - Fireworks AI · External inference provider reached only through the client boundary.
Supporting tools
Local simulation, token analysis, and offline evaluation helpers.
- Ops scripts · Local harness simulation and offline evaluation/token reporting utilities.
scripts - Local run · Docker-based simulation of the competition runtime.
scripts/run_local.sh - Eval matrix · Runs evaluation sweeps across task sets and model choices.
scripts/eval_matrix.py - Token report · Reports token usage and helps tune prompt budgets.
scripts/token_report.py
Tests and eval
Unit tests and category-specific evaluation sets used to verify routing and prompt behavior.
- Tests · Focused tests for the router, models, prompts, client, and main worker.
tests - Router cases · Domain-specific cases for validating category routing behavior.
tests/router_cases.json - Eval sets · Category-focused evaluation JSON files for codegen, factuality, logic, math, NER, sentiment, summarization, and debug.
tests/eval - Eval notes · Tracks benchmark outcomes and tuning iterations.
docs/eval-results.md
Build and release
Container and CI assets for running the worker in the competition harness.
- Dockerfile · Packages the worker for the external scoring harness.
Dockerfile - Release CI · GitHub Actions workflow for building or publishing submission artifacts.
.github/workflows/release.yml - Deps · Pinned runtime dependencies for the worker.
requirements.txt
Connections 18
- Input tasks → Worker: load · The worker reads batch tasks from the input JSON file.
- Worker → Router: classify · Each task is routed before any expensive model call.
- Router → Model tiers: tier hint · The selected category determines which model tier should be used.
- Router → Prompt map: category · Prompt templates are chosen by category.
- Model tiers → Prompt map: available tiers · Prompt construction consumes the tier mapping and max token guidance.
- Worker → Fireworks client: invoke · The orchestrator sends prepared requests to the Fireworks client.
- Prompt map → Fireworks client: messages · Rendered messages and token budgets feed the API call.
- Fireworks client → Fireworks AI: request · All LLM traffic goes through the Fireworks proxy boundary.
- Worker → Output results: write · The worker always emits a valid results file, even on partial failure.
- Ops scripts → Local run: simulate · Local Docker harness for reproducing the runtime.
- Ops scripts → Eval matrix: evaluate · Offline evaluation sweeps over task sets and models.
- Ops scripts → Token report: measure · Token accounting and prompt-efficiency analysis.
- Tests → Router cases: validate · Router-specific domain cases.
- Tests → Eval sets: benchmark · Evaluation corpora for the 8 task categories.
- Tests → Eval notes: record · Benchmark outcomes and tuning notes.
- Dockerfile → Worker: package · Container image packages the batch worker entrypoint.
- Release CI → Dockerfile: build · CI builds or publishes the containerized submission artifact.
- Deps → Worker: deps · Runtime dependency set used by the worker.