
Hybrid Token-Efficient Routing Agent is an AI orchestration system designed to maximize response accuracy while minimizing Fireworks AI token usage. Rather than sending every request directly to a remote model, the system intelligently analyzes each task and chooses the most cost-effective execution path. The workflow starts with feature extraction, task classification, complexity analysis, and constraint parsing. A prompt optimizer reduces unnecessary tokens, while a budget engine estimates the required response size. An Adaptive Router then decides whether the task can be solved locally or should be routed to Fireworks AI. A bundled **Qwen2.5-3B-Instruct (GGUF)** model handles suitable tasks locally, including factual knowledge, sentiment analysis, named entity recognition, short summarization, basic mathematics, and medium-complexity coding. Since local inference uses zero Fireworks tokens, these tasks incur no remote token cost while maintaining high accuracy. When a task exceeds the local model's capability, the router automatically selects the cheapest suitable Fireworks model from the models available through the `ALLOWED_MODELS` environment variable. This decision is based on task category, complexity, estimated token usage, and model capability. The system also includes confidence scoring, response validation, retry handling, routing memory, structured logging, and execution metrics to ensure reliable results and continuous routing improvements. The application is fully containerized with Docker, reads tasks from `/input/tasks.json`, writes results to `/output/results.json`, and routes all remote inference through `FIREWORKS_BASE_URL`. By combining intelligent preprocessing, hybrid routing, local inference, and adaptive model selection, the project delivers a scalable AI agent that reduces Fireworks token consumption without compromising accuracy.
13 Jul 2026