CSE Roadmap

Common tier · about 4 hours · 6 parts

Part 5 of 6 · 3 min read

Exercises

Easy

Easy 1: Run it and read the table (30 minutes)

In code/mini-cache, run pytest -q, python run_all.py.

Done when: you report the relative cost and read share of cache_keep_all, cache_volatile_header and cache_compact_batch, and say in a sentence why the volatile header is worse than no cache.

Hint

agent.table() returns the rows used in the notes.

Easy 2: Find the miss (30 minutes)

Write a request of four segments, send it, then send a copy with the second segment changed. Print read, written and uncached for both sends.

Done when: you show that everything after the change is written again, and say what happens if only the last segment changes.

Hint

cache.PrefixCache(Pricing(min_cacheable=100)).send(request, step).

Easy 3: Price your own provider (30 minutes)

Look up your provider's current cached-read price, write premium, TTL and minimum size. Put them in Pricing and re-run the table.

Done when: you report the three relative costs and say whether compacting every step still loses to append-only at your prices.

Hint

Pricing(read=..., write=..., ttl=..., min_cacheable=...).

Medium

Medium 1: Find the threshold (2 hours)

Sweep the compaction budget (8,000 to 30,000 tokens) for batch compaction at read prices 0.1 and 0.5.

Done when: you report the cost curve for each, say where it is lowest, and explain why the best budget differs between the two prices.

Hint

change agent.BUDGET; batch compaction targets half of it.

Medium 2: Stable state block (2 hours)

Add a state block between the tools and the history that is rewritten every N steps. Sweep N from 1 to 20.

Done when: you plot cost against N and say how often the state block should change, and what you would do if the state must be current on every step.

Hint

add a segment ("state@k", n) whose id changes when step % N == 0.

Medium 3: Parallel sub-agents (3 hours)

Run three sub-agents that share the same system prompt and tool definitions but have different histories. Model them with one cache.

Done when: you report the read share with and without a shared stable prefix and say what happens if one sub-agent reorders the tools.

Hint

one PrefixCache instance, three histories; send each sub-agent's request in turn.

Hard

Hard 1: A real API (4 hours)

Run 40 steps against a provider that reports cached tokens, once append-only and once compacting every step. (I did not run this, so your numbers are the ground truth.)

Done when: you report cached and uncached input tokens per step for both, the provider, the date, and say how close the simulation's shape was.

Hint

the usage field of the response gives cached and uncached counts; log them per step.

Hard 2: Cost and accuracy together (5 hours)

Combine this module's cost model with module 3's accuracy results: for each compaction schedule report accuracy at a given cost. (I did not run this.)

Done when: you draw the cost-accuracy frontier and say which schedule you would ship at which price.

Hint

take module 3's accuracy for each strategy and put cost on the other axis.

Hard 3: Warm-up traffic (4 hours)

For an agent with one request every ten minutes and a five-minute TTL, compute the cost of keeping the cache warm with a cheap ping every four minutes. (I did not run this.)

Done when: you report the break-even request rate and say what changes if the TTL refreshes on use.

Hint

a ping costs one cached read plus a few uncached tokens; compare with one write per miss.