Cutting the Cost of AI Agents with OpenClaw
I've recently started using OpenClaw to build a collection of AI agents. Some help me with IT tasks, others monitor my investments, and a few are just there to experiment with different AI models.
I loved how flexible it was, but there was one problem: after a few days of enthusiastic testing, I received a much larger bill than I was expecting.
Reducing AI Costs
The first thing I did was review which models each agent was using.
Originally, many of my agents were running more expensive models. I changed most of them to use GPT-4.1 Mini and Gemini 2.5 Flash, keeping only two agents on Claude Sonnet for the tasks where I felt the extra reasoning ability was worth paying for.
That change alone reduced my running costs considerably while still giving me good responses for most day-to-day tasks.
Replacing AI with Automation
The second saving came from asking a simple question:
"Does this task actually need AI?"
One of my agents was checking the Kainos share price and sending me alerts when it crossed certain thresholds.
There's really no need to ask an LLM to do that every 15 minutes. A simple Python script and a cron job can do exactly the same thing for free.
Ironically, I own shares in Kainos—a company that never offered me a job or even an interview after I applied there. At least now they're helping me learn more about automation!
The Python Script
# kainos_alert.py
import requests
import json
import os
TICKER = "KNOS.L"
LOW_ALERT = 750
MID_ALERT = 1150
HIGH_ALERT = 1250
BOT_TOKEN = "YOUR_BOT_TOKEN"
CHAT_ID = "YOUR_CHAT_ID"
STATE_FILE = "/root/kainos_state.json"
def send_telegram(msg):
requests.post(
f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage",
json={"chat_id": CHAT_ID, "text": msg},
timeout=15
)
def get_price():
url = f"https://query1.finance.yahoo.com/v8/finance/chart/{TICKER}"
data = requests.get(
url,
headers={"User-Agent": "Mozilla/5.0"},
timeout=15
).json()
return float(data["chart"]["result"][0]["meta"]["regularMarketPrice"])
def load_state():
if os.path.exists(STATE_FILE):
with open(STATE_FILE) as f:
return json.load(f)
return {"below750": False, "above1150": False, "above1250": False}
def save_state(state):
with open(STATE_FILE, "w") as f:
json.dump(state, f)
price = get_price()
state = load_state()
if price < LOW_ALERT and not state["below750"]:
send_telegram(f"π΄ Kainos alert: {price}p below 750p")
state["below750"] = True
elif price >= LOW_ALERT:
state["below750"] = False
if price > MID_ALERT and not state["above1150"]:
send_telegram(f"π‘ Kainos alert: {price}p above 1150p")
state["above1150"] = True
elif price <= MID_ALERT:
state["above1150"] = False
if price > HIGH_ALERT and not state["above1250"]:
send_telegram(f"π’ Kainos alert: {price}p above 1250p")
state["above1250"] = True
elif price <= HIGH_ALERT:
state["above1250"] = False
save_state(state)
PY
```
The script checks the latest Kainos share price using Yahoo Finance and sends a Telegram message if it falls below or rises above your chosen thresholds.
Creating the Cron Job
Open your crontab:
crontab -e
Add the following line to run the script every 15 minutes:
*/15 * * * * /usr/bin/python3 /root/kainos_alert.py >> /root/kainos_alert.log 2>&1
For testing, you can temporarily run it every minute:
* * * * * /usr/bin/python3 /root/kainos_alert.py >> /root/kainos_alert.log 2>&1
Testing the Script
First, run it manually:
python3 /root/kainos_alert.py
Then check that your Telegram bot can send messages correctly.
Verify your cron job has been installed:
crontab -l
You should see your Kainos monitoring command listed.
Finally, check that cron is executing the script:
grep CRON /var/log/syslog | tail -20
You should see entries showing the script running every 15 minutes.
Future Plans
The Kainos share alert is just the beginning. My next step is to extend the script so it monitors all of my stock market investments from a single watchlist rather than maintaining separate scripts for each company. Each share will have its own alert thresholds and Telegram notifications.
I'm also planning to add cryptocurrency monitoring. The same approach can be used to track Bitcoin, Ethereum, Solana, and other digital assets, sending alerts whenever they move above or below prices that matter to me.
Rather than paying an AI model to check prices every few minutes, a lightweight Python script running as a cron job is faster, more reliable, and essentially free to run. It also allows my AI agents to focus on tasks that genuinely benefit from natural language understanding and reasoning, while repetitive monitoring is handled by simple automation.
Over time I hope to expand this into a personal investment dashboard, combining share prices, cryptocurrency holdings, market news, and AI-powered analysis into a single automated system.