---
title: "Your AI Agent Is Wasting $0.04 Every Time It Reasons About Optimization. Here's the $0.01 Alternative."
published: true
tags: machinelearning, ai, typescript, api
canonical_url: https://web-olive-one-89.vercel.app/demo
series: "AI Agent Optimization"
---

Last week I watched GPT-4 spend 2,000 tokens, 3 seconds, and $0.04 to pick the wrong A/B test variant. Then I replaced it with a single API call that took 0.01ms, cost $0.01, and gave the mathematically correct answer.

This isn't a hot take. It's arithmetic.

## The Prompt That Costs $0.04 and Gets It Wrong

Here's what most agent builders do when they need to select the best variant from an A/B test:

```
System: You are a data-driven optimizer. Analyze the following A/B test
results and select the variant to show next.

User: I have three email subject lines being tested:
- Variant A: 500 sends, 175 opens (35% rate)
- Variant B: 300 sends, 126 opens (42% rate)
- Variant C: 12 sends, 8 opens (66.7% rate)

Which variant should I send to the next batch? Explain your reasoning.
```

GPT-4's response (actual output, shortened):

> *"Based on the data, Variant C has the highest open rate at 66.7%. However, the sample size is very small... I'd recommend Variant B as a balanced choice with a strong 42% open rate and reasonable sample size..."*

**Token count:** ~2,100 tokens (prompt + response)
**Latency:** 3.2 seconds
**Cost:** $0.04
**Answer:** Wrong.

Here's why it's wrong: This is a multi-armed bandit problem. The correct algorithm (UCB1) accounts for both the observed reward *and* the uncertainty from under-sampling. Variant C, with only 12 pulls, has massive confidence width. A proper bandit selects it precisely *because* it's under-explored -- not despite it. The LLM tried to reason about statistics and landed on a heuristic that ignores the exploration-exploitation tradeoff entirely.

## The 0.01ms Alternative

```bash
curl -X POST https://oraclaw-api.onrender.com/api/v1/optimize/bandit \
  -H 'Content-Type: application/json' \
  -d '{
    "arms": [
      {"id": "A", "name": "Variant A", "pulls": 500, "totalReward": 175},
      {"id": "B", "name": "Variant B", "pulls": 300, "totalReward": 126},
      {"id": "C", "name": "Variant C", "pulls": 12, "totalReward": 8}
    ],
    "algorithm": "ucb1"
  }'
```

Response:

```json
{
  "selected": { "id": "C", "name": "Variant C" },
  "score": 1.543,
  "algorithm": "ucb1",
  "exploitation": 0.667,
  "exploration": 0.876,
  "regret": 0.053
}
```

**Token count:** 0
**Latency:** 0.01ms
**Cost:** $0.01 (or free on the free tier)
**Answer:** Correct. Mathematically provable.

The UCB1 score is `reward_rate + sqrt(2 * ln(total_pulls) / arm_pulls)`. No opinion. No hedging. No hallucination. Just the formula that Auer, Cesa-Bianchi, and Fischer proved optimal in 2002.

## LLMs Can't Do Math. Stop Asking Them To.

This isn't a one-off failure. LLMs systematically hallucinate when you ask them to perform optimization. Here are three categories where I've seen this blow up in production:

### 1. Bandit Selection (as above)

LLMs consistently over-index on observed conversion rates and ignore confidence intervals. They'll pick the "safe" option with more data instead of the mathematically optimal exploration target. In a 500-variant feature flag system, this compounding error means you converge on a suboptimal variant and never discover the actual winner.

### 2. Constraint Optimization

Prompt: *"I have 3 workers, 8 tasks, each task takes different time, workers have different hourly costs. Minimize total cost while finishing by 5pm."*

GPT-4 will give you a plausible-sounding assignment. It will not give you the *optimal* one. This is a Mixed Integer Programming problem. The solution space is combinatorial. An LLM exploring it through chain-of-thought is like solving a Sudoku by describing what numbers might go where -- sometimes it works, usually it doesn't, and you never know which.

```bash
curl -X POST https://oraclaw-api.onrender.com/api/v1/solve/constraints \
  -H 'Content-Type: application/json' \
  -d '{
    "objective": "minimize",
    "variables": [
      {"name": "w1_t1", "type": "binary"},
      {"name": "w1_t2", "type": "binary"},
      {"name": "w2_t1", "type": "binary"},
      {"name": "w2_t2", "type": "binary"}
    ],
    "objectiveCoefficients": [15, 20, 25, 10],
    "constraints": [
      {"coefficients": [1, 0, 1, 0], "type": "eq", "rhs": 1},
      {"coefficients": [0, 1, 0, 1], "type": "eq", "rhs": 1}
    ]
  }'
```

This uses HiGHS -- the same solver used in commercial operations research. Provably optimal. 2ms.

### 3. Risk Assessment

Ask GPT-4: *"What's the Value-at-Risk on this portfolio at 95% confidence?"*

It'll give you a number. It won't give you a *correct* number, because VaR requires Monte Carlo simulation over the joint distribution of returns. It needs to sample thousands of scenarios, compute the portfolio value under each, and find the 5th percentile. An LLM doesn't simulate -- it pattern-matches from training data.

```bash
curl -X POST https://oraclaw-api.onrender.com/api/v1/analyze/risk \
  -H 'Content-Type: application/json' \
  -d '{
    "assets": [
      {"name": "AAPL", "weight": 0.4, "expectedReturn": 0.12, "volatility": 0.25},
      {"name": "BONDS", "weight": 0.4, "expectedReturn": 0.04, "volatility": 0.05},
      {"name": "BTC", "weight": 0.2, "expectedReturn": 0.30, "volatility": 0.70}
    ],
    "confidenceLevel": 0.95,
    "timeHorizon": 30,
    "simulations": 5000
  }'
```

You get VaR, CVaR (Expected Shortfall), confidence intervals, and worst-case scenarios. In 5ms. With math you can audit.

## The Performance Gap Is Not Close

| Task | GPT-4 | OraClaw |
|------|-------|---------|
| **A/B test selection** | ~2,000 tokens, 3s, $0.04, sometimes wrong | 0.01ms, $0.01, always correct |
| **Schedule optimization** | ~5,000 tokens, 8s, $0.10, approximate | 2ms, $0.01, provably optimal (HiGHS) |
| **Risk assessment** | ~3,000 tokens, 5s, $0.06, no confidence intervals | 5ms, $0.02, VaR + CVaR + CI |
| **Anomaly detection** | ~1,500 tokens, 2s, $0.03, threshold guessing | 0.01ms, $0.01, Z-score + IQR |
| **Time series forecast** | ~4,000 tokens, 6s, $0.08, no model | 0.08ms, $0.01, ARIMA + Holt-Winters |

If your agent makes 1,000 optimization decisions a day (not unusual for a production system), that's:

- **GPT-4:** $40-100/day, 50-80 seconds of latency, probabilistic correctness
- **OraClaw:** $10/day (or $0 on free tier), 10-50ms total latency, deterministic correctness

Over a month, you're saving $900-$2,700 and getting answers that are actually right.

## 19 Algorithms, Zero LLM Tokens

OraClaw ships 19 deterministic algorithms across 8 categories:

**Optimize** -- Multi-Armed Bandit (UCB1/Thompson/Epsilon-Greedy), Contextual Bandit (LinUCB), Genetic Algorithm, CMA-ES

**Simulate** -- Monte Carlo (6 distributions), Scenario Planning

**Solve** -- Constraint Optimizer (LP/MIP via HiGHS), Schedule Optimizer

**Analyze** -- Decision Graph (PageRank, Louvain), Portfolio Risk (VaR/CVaR)

**Predict** -- Bayesian Inference, Ensemble Model, Time Series Forecast (ARIMA + Holt-Winters)

**Detect** -- Anomaly Detection (Z-score + IQR)

**Score** -- Convergence Scoring, Calibration Scoring

**Plan** -- A* Pathfinding (K-shortest paths, Yen's algorithm)

14 of 17 endpoints respond in under 1ms. All under 25ms. Every result is deterministic and auditable.

## Three Ways to Integrate

### 1. REST API (zero install, works right now)

```bash
# Bayesian inference -- update beliefs with new evidence
curl -X POST https://oraclaw-api.onrender.com/api/v1/predict/bayesian \
  -H 'Content-Type: application/json' \
  -d '{
    "prior": 0.3,
    "evidence": [
      {"factor": "positive_signal", "weight": 0.85, "value": 0.1}
    ]
  }'

# Anomaly detection -- find outliers in time series
curl -X POST https://oraclaw-api.onrender.com/api/v1/detect/anomaly \
  -H 'Content-Type: application/json' \
  -d '{
    "data": [10, 12, 11, 13, 50, 12, 11, 10],
    "method": "zscore",
    "threshold": 2.0
  }'
```

### 2. MCP Server (for Claude, ChatGPT, and any AI agent)

Add to your `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "oraclaw": {
      "command": "npx",
      "args": ["tsx", "node_modules/@oraclaw/mcp-server/src/index.ts"]
    }
  }
}
```

Now your AI agent can call `optimize_bandit`, `solve_constraints`, `analyze_portfolio_risk`, and 9 more tools natively. The agent decides *when* to use math. OraClaw does the math correctly.

### 3. npm SDK (14 packages)

```bash
npm install @oraclaw/bandit @oraclaw/solver @oraclaw/risk
```

```typescript
import { OraBandit } from '@oraclaw/bandit';
import { OraSolver } from '@oraclaw/solver';

const bandit = new OraBandit({ baseUrl: 'https://oraclaw-api.onrender.com' });
const solver = new OraSolver({ baseUrl: 'https://oraclaw-api.onrender.com' });

// Let the bandit pick the best option
const pick = await bandit.optimize({
  arms: variants,
  algorithm: 'thompson'
});

// Solve a scheduling problem optimally
const schedule = await solver.constraints({
  objective: 'minimize',
  variables: tasks,
  constraints: deadlines
});
```

14 SDK packages: `@oraclaw/bandit`, `@oraclaw/solver`, `@oraclaw/simulate`, `@oraclaw/risk`, `@oraclaw/forecast`, `@oraclaw/anomaly`, `@oraclaw/graph`, `@oraclaw/bayesian`, `@oraclaw/ensemble`, `@oraclaw/calibrate`, `@oraclaw/evolve`, `@oraclaw/pathfind`, `@oraclaw/cmaes`, `@oraclaw/decide`

## Try It Now -- No Signup Required

The free tier gives you 25 calls/day with no API key and no signup. Every curl example in this post hits the live API. Copy one, run it, and look at the response.

**[Try the Interactive Demo](https://web-olive-one-89.vercel.app/demo)** -- run algorithms in your browser, no signup.

- **Live API:** [oraclaw-api.onrender.com](https://oraclaw-api.onrender.com)
- **Interactive Demo:** [web-olive-one-89.vercel.app/demo](https://web-olive-one-89.vercel.app/demo)
- **GitHub:** [github.com/Whatsonyourmind/oracle](https://github.com/Whatsonyourmind/oracle)
- **npm:** [@oraclaw](https://www.npmjs.com/org/oraclaw)

Paid tiers start at $9/mo for 10K calls. For AI agents that pay autonomously, there's USDC-based pay-per-call on Base (x402 protocol) -- $0.01 to $0.15 per call, no subscription, no human in the loop.

## The Takeaway

LLMs are extraordinary at understanding intent, generating code, and handling ambiguity. They are terrible at math. Every time you ask an LLM to "reason" about an optimization problem, you're paying for a slow, expensive, probabilistic approximation of something that a deterministic algorithm solves exactly in microseconds.

Stop making your AI agents think about optimization. Give them a calculator.

---

*OraClaw is open-source (MIT). Built with Fastify 5, TypeScript, HiGHS (WASM), and graphology. 1,072 tests passing. Star us on [GitHub](https://github.com/Whatsonyourmind/oracle) if this saved you some tokens.*
