"""The agentic cost curve with the prefix cache ON + FIXED_CHUNKS (audit 258). Baseline from audit 250.3 (cache off): 15.5, 29.0, 44.5, 54.0, 72.0, 85.3 s as the prompt grew 2.7k -> 15.9k. """ import json, time, urllib.request URL="http://127.0.0.1:8300/v1/chat/completions" def ask(msgs, mt=8): body={"model":"glm-5.3-exl3","messages":msgs,"max_tokens":mt,"temperature":0} r=urllib.request.Request(URL,data=json.dumps(body).encode(),headers={"Content-Type":"application/json"}) t0=time.perf_counter(); d=json.loads(urllib.request.urlopen(r,timeout=3600).read()); dt=time.perf_counter()-t0 st=d.get("tensorfold",{}) or {} return dt, d.get("usage",{}).get("prompt_tokens"), st.get("cached"), d["choices"][0]["message"].get("content") or "" unit=("Log entry: the service handled a request, validated the payload, wrote two rows, and returned 201. ") blk=unit*120 msgs=[{"role":"system","content":"You are an agent. Reply with just OK."}] print(f"{'turn':>4s} {'prompt':>8s} {'cached':>8s} {'wall s':>8s} (cache-off baseline)") base=[15.5,29.0,44.5,54.0,72.0,85.3] for t in range(1,7): msgs.append({"role":"user","content":f"{blk}\nStep {t}: acknowledge."}) dt,pt,ca,got=ask(msgs) msgs.append({"role":"assistant","content":got or "OK"}) b=base[t-1] if t<=len(base) else None sp=f"{b/dt:5.1f}x" if b else "" print(f"{t:4d} {pt:8} {str(ca):>8} {dt:8.2f} {b}s {sp}", flush=True) print("### GROWTH DONE")