how to reduce token cost in agent workflows?

To cut token costs in agent workflows, especially while building **Liminality** (the question-decomposition and routing MCP server), you need to shrink the data moving to and from the LLM and tighten the decomposition process.

Here is how:

1. **Optimize Question Decomposition (Liminality’s Core Function):** * **Minimize Sub-questions:** Split questions only when you have to. Over-decomposition just creates more LLM calls. * **Reuse Routes:** Your assets mention "reusable routes." Cache successful decomposition patterns for similar queries so you stop re-computing logic. * **Ground Early:** Use your MCP server to ground sub-questions to real tools *before* sending them to the LLM. This lets the LLM send concise, tool-specific prompts instead of verbose natural language.

2. **Context Management:** * **Prune Context:** Only keep relevant tool outputs and conversation history. Delete redundant or outdated info from the context window. * **Summarize History:** For long chats, summarize previous turns. Do not pass raw text. * **Use System Prompts Efficiently:** Keep system instructions short and focused on the current task.

3. **Model Selection and Routing:** * **Route by Complexity:** Use a smaller, cheaper model for simple, well-defined sub-questions like data retrieval or formatting. Save larger, expensive models for complex reasoning or creative work. * **Use Liminality for Routing:** Use your MCP server to route questions to the right tool or model based on the decomposed sub-questions.

4. **Tool Output Optimization:** * **Filter Tool Outputs:** When tools return data, filter and format it. Include only what is needed for the next step. Do not pass large JSON blobs or raw HTML if you only need specific fields. * **Use Structured Outputs:** Enforce structured output formats like JSON. This reduces the need for the LLM to parse or correct its own responses, saving tokens in subsequent iterations.

5. **Caching:** * **Cache Tool Responses:** If tools return deterministic results, cache them. This avoids redundant API calls and LLM processing. * **Cache Decomposition Results:** Cache the decomposition of common question patterns.

Implementing these strategies significantly reduces token consumption. It makes **Liminality** more cost-effective and scalable for both human and AI users.

This answer was worked out by Liminality — Physea's engine that decomposes a request, grounds each part to a real tool, and returns a reusable, checkable route.

Connect it over MCP: https://mcp.physea.ai/mcp · physea.ai