Repository navigation
LLM benchmark: Bedrock + AgentCore Web Search, prompt caching, reliability fixes, history analysis - #25
Merged
Conversation
- LLM_PROVIDER=openrouter|bedrock selects the AI SDK provider; Bedrock uses @ai-sdk/amazon-bedrock (Converse API) with the default AWS credential chain - searchWeb is now backed by a pluggable search backend (SEARCH_PROVIDER=tavily|agentcore|none, auto-detected from env) - AgentCore backend: minimal MCP client for AgentCore Gateway (SigV4 or JWT inbound auth), auto-discovers the `<target>___WebSearch` tool name and normalizes results to the same shape as Tavily - Prompt, tools and on-chain flow are unchanged, so existing OpenRouter deployments behave the same - README: env vars, gateway setup, fairness note Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Every prediction run (incl. DRY_RUN) writes predictions, per-market reasoning, full tool trace (search queries + results) and token usage to state/reasoning/<slug>-round-<id>-<ts>[-dryrun].json - DRY_RUN also prints tool calls and per-market reasoning to the console - gitignore agents/*/state/ (reveal queues contain salts) - README: correct the reasoning-storage section — the relayer only receives the per-market reasoning strings, not the trace Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Prompt now states the current UTC date/time. A Bedrock dry run on round 167 showed the model searching for "October 2024" because it assumed its training-era date. Applies to all models/providers. - AgentCore web search preflight (tools/list) at startup in predict/all mode and DRY_RUN. DRY_RUN fails hard; live runs log an error and predict without search so reveals in the same run are never blocked. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…results - Drive the tool loop one step at a time so cache points can be placed on the prompt and the two newest tool-result messages (Bedrock max 4). A dry run on round 167 used 205k prompt tokens across 8 steps, mostly re-sent search snippets. Enabled automatically for Claude/Nova (BEDROCK_PROMPT_CACHE). - Stop right after submitPredictions instead of paying for a closing summary. - Report cache read/write tokens per step and in the usage log line. - SEARCH_EXCLUDE_DOMAINS (default polymarket.com) drops results hosted exactly on excluded domains for every search backend; subdomains such as xtracker.polymarket.com (a resolution source) are kept. Over-fetches 3 results so the model still gets 5. - ai >= 4.3 (message-level providerOptions). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- export-history.mjs: scored rounds from the subgraph with market metadata (relayer /polymarket proxy), outcomes, per-agent predictions, per-market Brier/alpha (verified against on-chain scores) and posted reasoning - analyze-history.mjs: alpha by period/category/price/deviation, shrinkage toward the market, LLM ensemble, calibration, confident "already decided" calls, split-half check of post-processing rules, largest losses - gitignore tools/out/ Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
final = market + k·(model − market), using the YES price the model saw. Default k=1 (off). Auto-resolved markets are never shrunk; if the market price is unknown the forecast is left unchanged. Rounds 2–95 analysis: the benchmark LLMs lose to the market on moderate and opinion deviations; k=0.5 turned all four agents' alpha positive, in both halves of the data (-0.0044 → +0.0029 per market pooled). The reasoning log records modelPredictions, marketPrices and the factor; per-market reasoning keeps probabilityBps (committed) and modelProbabilityBps (raw). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Nova 2 Lite failed round 168 with "Malformed input request: #/messages/2/content/6: extraneous key [cachePoint] is not permitted". - Cache policy by family: Claude = prompt + newest tool results, Nova = prompt only, others = none - If Bedrock rejects a cache point anyway, retry the step uncached and keep caching off for the rest of the run, so a caching problem can't cost a round Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… deadline
Round 169: a Fable call started at 04:56 was still running when the 04:58
cron fired, so a second process predicted the same round (double LLM cost).
The first committed 28s before the deadline; the second's commit reverted in
simulation ("Already committed").
- state/run-<address>.lock: one run at a time per wallet; skips while the
holder is alive, takes over a lock from a dead process, removed on exit
- getPredictions(deadline): checked before each step and enforced mid-call
with an abort signal; the agent reserves 45s before the commit deadline
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Fable 5.1 on OpenRouter re-sent the whole conversation each step: 255k prompt tokens over 8 steps in round 169, ~$3.14/round. With caching, a replay of that trace comes to ~$1.17 (reads $0.25/M vs $10/M input). - fetch wrapper (the 0.0.6 SDK has no caching support) adds top-level cache_control for anthropic/* models and records usage.prompt_tokens_details (cached_tokens / cache_write_tokens) per step - other models' requests are unchanged; OPENROUTER_PROMPT_CACHE=on|off - cache rejections are detected in message or responseBody and the step is retried uncached Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…rapped Round 172 (Fable): the deadline guard fired at 17:59:15, exactly 45s before the 18:00 deadline, while OpenRouter's response body was being read. The abort surfaced as an undici "terminated" error, which the SDK wraps as "Failed to process successful response", so it was logged as an opaque failure. Check our own abort signal instead of the error type. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Round 176 (Nova 2 Lite): after 5 steps the model wrote its predictions as
text ("Prediction: 8450 bps ...") and stopped without calling
submitPredictions, so the round was lost.
If a step ends without a tool call and no predictions were submitted, append
a short user message asking for the submitPredictions call, up to 2 times,
within the same deadline guard. Forcing tool_choice is not an option (newer
Claude models reject it) and parsing free text would be fragile.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds Amazon Bedrock models and Web Search on Amazon Bedrock AgentCore to the LLM benchmark agent, plus fixes for the reliability and cost problems found while running Claude Fable 5.1 and Nova 2 Lite live (rounds 167–176), and tooling for a historical post-mortem of rounds 2–95.
The provider is a config switch alongside OpenRouter, not a separate module: prompt, tools and the on-chain flow stay shared, so models remain comparable. Existing OpenRouter agents keep their current behavior apart from the changes listed under Behavior changes for existing agents.
Providers and search
LLM_PROVIDER=openrouter|bedrock. The Bedrock path uses@ai-sdk/amazon-bedrock(Converse API) with the default AWS credential chain.SEARCH_PROVIDER=tavily|agentcore|none, auto-detected.lib/agentcore.mjsis a minimal MCP client for AgentCore Gateway (SigV4 or JWT) that auto-discovers the<target>___WebSearchtool. Results are normalized to the same shape as Tavily.DRY_RUNfails hard; live runs continue without search so reveals are never blocked.SEARCH_EXCLUDE_DOMAINS(defaultpolymarket.com) applies to every backend. It drops only the exact host andwww., soxtracker.polymarket.com(a resolution source) is kept.Cost
anthropic/*models through a top-levelcache_control, injected by a fetch wrapper because the 0.0.6 SDK has no caching support. Live Fable 5.1 run: 308k of 375k prompt tokens read from cache, ~$1.22 vs ~$4.06 without caching.submitPredictionsinstead of paying for a closing summary.Reliability
state/run-<address>.lock). In round 169 a slow Fable call outlasted the 2-minute cron and a second process predicted the same round.Out of timeeven when the SDK wraps the abort as "Failed to process successful response" (round 172).submitPredictions(Nova, round 176), the agent asks it to submit, up to 2 times.Analysis and post-processing
tools/export-history.mjs: scored rounds with market metadata, outcomes, per-market Brier/alpha (verified against on-chain scores) and the posted reasoning.tools/analyze-history.mjs: alpha by period, category, price and deviation; shrinkage; ensemble; calibration; confident calls; split-half checks.SHRINK_TO_MARKET=kpost-processing (default1= off).k=0.5turned every agent's alpha positive in both halves of the data.DRY_RUN) saves predictions, per-market reasoning, the full tool trace, token and cache usage, and raw vs committed forecasts tostate/reasoning/.Behavior changes for existing agents
polymarket.comsearch results are excluded by default. SetSEARCH_EXCLUDE_DOMAINS=(empty) to restore the old behavior.OPENROUTER_PROMPT_CACHE=off.ainow requires^4.3.0. Runnpm installafter pulling.agents/*/state/andtools/out/are now gitignored.Testing
cache_controland usage capture, deadline aborts (including mid-body), the run lock, the submit reminder and the shrink function. Each live failure (Nova cache rejection, wrapped abort, text answer) was reproduced in a test before fixing.Not in this PR
🤖 Generated with Claude Code