Slash AI Agent Costs: Reformat Config Files to YAML
Job to be done: Reduce LLM context size and costs by reformatting config files to YAML
🇳🇬 Ways to use this in Nigeria
Ideas to get you started, adapt to your situation.
- Entrepreneur
Developing an AI customer support chatbot for your e-commerce startup, reformat its extensive FAQ and response rules from Markdown to YAML to cut down on monthly LLM API expenses.
- 9-5 employee
As an IT support staff, optimize the configuration files for your department's internal AI assistant that answers common employee queries, reducing its operational costs and improving response times.
- Student
Building a simple AI study assistant for JAMB prep or a WhatsApp bot for a campus side hustle, convert its internal rules from verbose text to compact YAML to reduce API costs.
What you’ll get
You will learn how to convert verbose configuration files (like those written in Markdown) into a more compact YAML format. This reduces the amount of text (called ‘tokens’) your AI agent needs to process in each interaction, leading to significant cost savings and potentially faster responses, especially if your agent loads many config files or long prompts.
Tools you need
- Any Text Editor (free): A program on your computer or phone to type and edit text, like Notepad on Windows, TextEdit on Mac, or a simple notes app.
- Online YAML Converter (freemium): A website tool (for example, Code Beautify’s YAML converter) that helps you convert text to YAML and check if it’s correctly formatted.
- Any LLM Chat App (freemium): A free AI chat tool (like ChatGPT, Claude, or Gemini) that can help you understand concepts or assist with reformatting text into YAML.
Steps
-
Understand why this works: AI models process text in small pieces called ‘tokens’. The more tokens an AI agent has to read (its ‘context’), the more it costs and the longer it takes to respond. By making your configuration files shorter and more direct, you use fewer tokens.
-
Identify verbose configuration files: Look for files that your AI agent loads repeatedly, especially those written in a human-friendly but wordy format like Markdown. These often contain rules, personality prompts, or tool descriptions.
-
Review a verbose example (Markdown): Consider this typical, human-oriented Markdown configuration from the author. Notice how it uses headings and full sentences:
## Backup Rules You should always create a backup before making any changes to the system. Use the cp command with a date suffix to ensure you can track versions. If you are modifying directories, use tar with compression to save space. ## Response Rules If the user's message does not contain a question, do not reply at all. If it is a rhetorical question that implies an action, execute silently without responding.This example uses 420 characters, which translates to about 105 tokens for an AI model.
-
Review the compact example (YAML): Now, see the same information reformatted into YAML. It uses key-value pairs, which are much more machine-dense and less verbose:
backup: rule: always cmd: "cp f f.bak-$(date +%Y%m%d)" dir: "tar -czf backup.tar.gz" response: no_question: no_reply rhetorical_with_action: execute_silentThis YAML version uses only 140 characters, which is about 35 tokens. This is a 66% reduction in tokens for the same information.
-
Convert your own text to YAML: Open your chosen text editor or an online YAML converter. Take a small section of your verbose configuration text and manually reformat it into key-value pairs, similar to the example above. If you need help, you can ask an AI chat app. The author doesn’t share their exact prompt; a starting point:
Convert the following text into a compact YAML format. Use clear key-value pairs and avoid unnecessary words. [Paste your verbose text here]You should get a more compact, structured YAML output that contains all the original information in fewer words.
-
Validate your YAML (optional but recommended): If you used a text editor or an AI chat app for conversion, paste your new YAML content into an online YAML converter or validator. This tool will check for correct formatting, such as proper indentation and syntax.
You should see a message confirming that your YAML is valid, or it will point out any errors you need to fix.
-
Replace the original file: Once you have a validated, compact YAML version, save it. If this file is used by an AI agent, replace the old verbose version with your new YAML file. Remember to keep a backup of the original file.
Your configuration file is now significantly smaller, reducing the token count for your AI agent.
Original source
This workflow was shared by Reddit user /u/No_Substance6819 on the platform Reddit. They demonstrated how reformatting configuration files from Markdown to YAML can drastically cut down on the number of tokens an AI agent processes, leading to substantial cost savings.
Notes & variations
- Free-tier alternatives: For basic text editing, you can use any free text editor on your device. Many online text editors and notes apps on phones can also work. For YAML validation, there are numerous free online tools available.
- Common mistake: YAML is very sensitive to indentation. Make sure to use consistent spacing (usually two or four spaces, not tabs) for nested items. Incorrect indentation will cause errors.
- Tip for better results: Start by converting small, simple sections of your configuration. Once you get comfortable, move on to larger or more complex parts. Using an AI chat app can be a great way to quickly get a first draft of the YAML, which you can then refine and validate.