Think-Reason-Learn
Research · Think-Reason-Learn · 9 November 2026

Give your coding agent a judge: the generate, score, improve loop

Have your agent write a draft, score it with a model that gives reasons, fix what pulled it down and keep the best version, in Python or one API call.

Get an API key

Here's the loop: your agent writes a draft, a separate model scores it and says what pulled the score down, the agent rewrites only those parts, the model scores the rewrite, and you keep whichever version scored highest. Stop after two or three rounds, or when the score stops rising.

This is the evaluator-optimizer pattern. Below, a Think-Reason-Learn model is the judge, and the loop is built three ways: in about 25 lines of Python, through OpenRouter, and as one API call that runs it for you.

Why the judge should be a separate model

An agent grading its own work tends to like what it already wrote. Ask it "is this good?" and the answer leans yes. Ask it to improve the draft and it changes whatever it likes, because it has no fixed idea of what better means.

A judge trained on real outcomes gives the agent a target that doesn't move. Our Show HN Launch Predictor, for example, learned from 4,885 past posts which traits go with reaching 100 points. It also returns its reasons, so the agent knows what to change, not just that the score is low. How Think-Reason-Learn works explains where those reasons come from.

The loop in Python

The API is OpenAI-compatible, so the OpenAI SDK works as is. Send the post as JSON in the user message. The reply's content is a JSON string with the model's output fields at the top level, next to model, release and common.

import json, os
from openai import OpenAI

judge = OpenAI(base_url="https://api.thinkreasonlearn.com/v1", api_key=os.environ["TRL_API_KEY"])
JUDGE = "think-reason-learn/show-hn-launch-predictor"

def score(post: dict) -> dict:
    r = judge.chat.completions.create(
        model=JUDGE,
        messages=[{"role": "user", "content": json.dumps(post)}],
    )
    return json.loads(r.choices[0].message.content)

def improve(post: dict, write, rounds: int = 2) -> dict:
    best, best_out = post, score(post)
    for _ in range(rounds):
        fixes = [r.get("label") or r["check"] for r in best_out["pulled_down"][:5]]
        if not fixes:
            break
        draft = write(best, fixes)          # your agent or writer model
        out = score(draft)
        if out["hit_probability"] <= best_out["hit_probability"]:
            break                           # no better: keep what we had
        best, best_out = draft, out
    return {"post": best, "outlook": best_out["outlook"], "score": best_out["hit_probability"]}

write is whatever produces the rewrite. That can be your coding agent, or a call to any chat model with a prompt like "Rewrite this Show HN post to fix these problems. Keep every fact and the author's voice. Don't add claims or links." followed by the list in fixes.

Two details matter:

  • Compare on the probability, not the level. The level ("weak", "strong") moves in steps. hit_probability tells two close drafts apart. For quoting the odds to a person, use level_hit_rate next to base_rate.
  • Only keep a rewrite that scores higher. Without that check, the loop can wander and hand you something worse than what you started with.

The same loop through OpenRouter

If your agent already has an OpenRouter key, point the client there instead. The model id is the same.

judge = OpenAI(base_url="https://openrouter.ai/api/v1", api_key=os.environ["OPENROUTER_API_KEY"])

The Show HN Launch Predictor and the LinkedIn Viral Post Predictor are on OpenRouter. The GitHub PR and contributor models are only on our API for now. Under per-token pricing, a pasted diff would cost far more than the call does.

Or let us run it: /v1/improve

POST /v1/improve does the whole loop in one call. It scores your text, and a writer rewrites only what pulled the score down, keeping your facts and voice. Then it scores the rewrite and keeps the best version. It runs two rounds by default and up to three.

curl https://api.thinkreasonlearn.com/v1/improve \
  -H "Authorization: Bearer $TRL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "think-reason-learn/show-hn-launch-predictor",
    "input": {
      "title": "Show HN: Tabsy – a smart browser tab manager",
      "url": "https://tabsy.app",
      "text": "Tabsy is a powerful, intelligent tab manager that helps you stay organized and productive. It groups your tabs automatically, lets you search across them instantly, and saves sessions so you never lose your work. Built with Rust and WebAssembly for blazing-fast performance. Try it free today!"
    },
    "rounds": 2
  }'

The response has the final text, whether it improved, the score and full output before and after, a plain list of changes, and each round. This is a real run, with output left out:

{
  "object": "improvement",
  "field": "text",
  "text": "Tabsy is a powerful, intelligent tab manager that helps you stay organized and productive. It groups your tabs automatically, lets you search across them instantly, and saves sessions so you never lose your work. Built with Rust and WebAssembly for fast performance.",
  "improved": true,
  "before": { "score": 0.0070, "label": "weak" },
  "after": { "score": 0.0094, "label": "weak" },
  "changes": [
    "Removed 'blazing-fast' to reduce marketing copy tone.",
    "Removed 'Try it free today!' to reduce marketing copy tone."
  ],
  "rounds": [{ "round": 1, "score": 0.0094, "kept": true }],
  "usage": { "cost_usd": 0.04, "latency_ms": 6268 }
}

The writer cut two marketing phrases and the score went up by about a third. The post is still "weak", and that's the honest result. What holds it back is a link to a landing page and a product described in generic terms, and no rewording fixes those. The model's reasons tell you that too: link to the code or a demo, and say what's technically hard about it. Only you can supply that. The second round stopped early because the writer returned the text unchanged.

Each score is charged at the model's price and each rewrite at 5x our cost, between $0.01 and $0.05. Two rounds on a $0.01 model come to about $0.05 and take 10 to 20 seconds. By default it rewrites the post's text; pass "field": "title" to rewrite the title instead.

The trap: writing for the judge

Any loop that optimizes against a score can learn to please the score instead of the reader. This is Goodhart's law, and it's the main risk here. A Show HN post stuffed with phrases that look like "deep technical skill" isn't a better post.

What /v1/improve does about it:

  • The writer sees which checks pulled the score down and which pulled it up. It's told to change only what's needed to fix the first list and to keep the second.
  • It must keep every fact, number and name, and the author's voice. It can't add facts or links. A rewrite with a link the author didn't write is thrown away.
  • A rewrite that scores the same or lower is never returned as better. You get improved: false and your original text back.

We don't know yet whether posts rewritten this way do better on Hacker News than the originals would have. The model's numbers come from posts people wrote themselves, and we haven't yet tested rewrites against real outcomes. Until we have, read the rewrite before you post it.

Telling your coding agent about it

Coding agents read instructions from files like CLAUDE.md or AGENTS.md. A few lines are enough:

## Launch posts
Before suggesting a Show HN post, score it with think-reason-learn/show-hn-launch-predictor
(https://api.thinkreasonlearn.com/v1, key in TRL_API_KEY). Fix what's in pulled_down, score again,
and show me the best version with its outlook and level_hit_rate next to base_rate.

Agents can also find every model on their own. /llms.txt lists each one with what it returns and its price, /llms-full.txt adds the inputs, and GET /v1/models returns each model's input and output JSON Schema.

What it costs

WhatCost
Score one draft$0.01
Score 20 drafts$0.20
One /v1/improve call, 2 roundsabout $0.05

Create an API key to try it, or browse the model catalog to see what else can be a judge.