ax-refine

ax-refine is a skill for Claude Code, Codex from ax-llm/ax. It costs 38 tokens per session (773 once invoked), scanned A, original, Apache-2.0.

A guide to using best-of-N selection and refinement in the @ax-llm/ax library. These methods create or retry several AI answers, score them, and either choose the best one or use feedback to improve later attempts.

In plain words
What is it for?
Scoring candidate outputs, setting acceptance thresholds, retrying with generated feedback, and diagnosing generation attempts.
Why use it?
It helps raise output quality when a single generated answer may be incomplete or incorrect.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Scoring candidate outputs, setting acceptance thresholds, retrying with generated feedback, and diagnosing generation attempts.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/ax-llm/ax/ax-refine
About the project

Ax is a TypeScript-first programming framework for building applications with large language models through typed generation, agents, workflows, and optimization tools. It is intended for developers who want one model for LLM programs across TypeScript, Python, Java, C++, Go, Rust, and other runtimes.

ax-llm/ax · 2,893 stars · on GitHub · axllm.dev

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add ax-llm/ax --skill ax-refine
Clone the repo
git clone --depth 1 https://github.com/ax-llm/ax

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for ax-refine

README.md
[![agentmods](https://agentmods.dev/badge/skills/ax-llm/ax/ax-refine.svg)](https://agentmods.dev/skills/ax-llm/ax/ax-refine)
Your own site
<a href="https://agentmods.dev/skills/ax-llm/ax/ax-refine"><img src="https://agentmods.dev/badge/skills/ax-llm/ax/ax-refine.svg" alt="Measured on agentmods" height="20"></a>
Per session 38 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 773 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00038 $0.00773
Opus 5 $0.00019 $0.00387
Sonnet 5 $0.00008 $0.00155
Haiku 4.5 $0.00004 $0.00077

Measured today against content hash 0ee7f053c19e, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

ax-refine scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured today.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

Copies of this mod

1 near-identical copy found in the catalogue:

  • ax-refine — 91% identical, 0 lines differ
website/static/typescript/.well-known/agent-skills/ax-refine/SKILL.md · 82 lines

How it starts

The opening of the file, as written. The whole thing — 82 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Ax Refine And BestOfN

Use bestOfN(...) when you can score complete outputs independently. Use refine(...) when failed rounds should produce feedback that changes the next attempt.

Validation And Assertions

Keep reward scoring, whole-output assertions, and streaming assertions separate:

  • Use schema validation for shape, types, and field-level constraints.
  • Use addAssert(...) for whole-output hard invariants. Failed assertions feed correction text into the normal retry loop.
  • Use addStreamingAssert(...) for partial streaming hard invariants. It aborts the current stream attempt as soon as the partial field fails, then feeds correction text into the normal retry loop.
  • Use bestOfN(...) for complete-candidate selection.
  • Use refine(...) for reward-scored retry rounds with generated feedback.

APIs

import { bestOfN, refine } from '@ax-llm/ax';

const selected = bestOfN(program, {
  n: 4,
  threshold: 0.8,
  rewardFn: ({ input, prediction, traces, chatLog }) => score(prediction),
});

const improved = refine(program, {
  rounds: 3,
  samplesPerRound: 2,
  threshold: 0.85,
  rewardDescription: 'Prefer complete, grounded, concise answers.',
  rewardFn: ({ prediction }) => score(prediction),
});

Rules:

  • forward(...) returns the selected prediction.
  • streamingForward(...) is unsupported; score complete outputs instead.
  • getUsage() aggregates usage across attempts.
  • getTraces() and getChatLog() return the selected attempt's diagnostics.
  • getAttempts() returns all attempt metadata, including reward, errors, and advice application.

Reward Functions

Reward functions return a number. Higher is better. A threshold marks a good-enough candidate and can stop serial attempts early.

const rewardFn = ({ prediction }) => {
  const exact = prediction.answer === 'Paris' ? 1 : 0;
  const concise = prediction.answer.length < 80 ? 0.2 : 0;
  return exact + concise;
};

Use serial strategy when the reward needs traces, chat logs, tools, or full flow behavior.

Read the full file on GitHub · 82 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. today Changed 0ee7f053c19e
  2. 4d ago First seen · 82 lines · 38 tokens per session scan A ecb16e65743b

Subscribe to this mod's changes

ax-refine is a skill published in the GitHub repository ax-llm/ax (2,893 stars, last pushed today), licensed Apache-2.0. It adds 38 tokens to every session and 773 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

Other skills, from other repositories

output-dev-prompt-file

Create .prompt files for LLM operations in Output SDK workflows. Use when designing prompts, configuring LLM providers, or using Liquid.js templating.

growthxai/output · 36 tokens

output-dev-eval-testing

Create offline evaluation tests for Output SDK workflows using @outputai/evals. Use when implementing test evaluators with verify(), creating dataset YAML files, building eval workflows, or running workflow tests via CLI.

growthxai/output · 46 tokens

output-dev-step-function

Create step functions in steps.ts for Output SDK workflows. Use when implementing I/O operations, error handling, HTTP requests, or LLM calls.

growthxai/output · 34 tokens

output-meta-project-context

Comprehensive guide to Output.ai Framework for building durable, LLM-powered workflows orchestrated by Temporal. Covers project structure, workflow patterns, steps, LLM integration, HTTP clients, CLI commands, and the full inventory of available agents and skills.

growthxai/output · 54 tokens

update-provider-models

Add new or remove obsolete model IDs for existing AI SDK providers. Use when adding a model to a provider, removing an obsolete model, or processing a list of model changes from an issue. Triggers on "add model", "remove model", "new model ID", "obsolete model", "update model IDs".

vercel/ai · 68 tokens

output-eval-dataset-design

Design diverse eval datasets using dimension-based variation. Use when bootstrapping eval datasets, when real traces are sparse, or when existing datasets miss edge cases.

growthxai/output · 38 tokens