harness¶
Base¶
- class milp_flare.harness.base.Harness(model, effort='medium')[source]¶
Base class for FLARE agent harness.
FLAREuses an agent harness to auto-formalize MILP formulations in Lean and do automated formal proof synthesis (AFPS) of reformulation certificates. This is the base class for aFLAREagent harness. It has methods to configure the agent working directory, run the agent in a Docker container, and return a configuration dictionary.- Parameters:
- Attributes:
- configure_wd(wd)[source]¶
Configure the agent working directory with necessary files for the harness.
The agent working directory needs the following:
An agent command script (
agent.sh) that is called by the Docker container entrypoint to launch the agent. The script typically calls an agent CLI in non-interactive mode.Any configuration files necessary to enable the lean-lsp-mcp MCP server.
Custom Agent Skills for auto-formalization of MILP formulations and automated formal proof synthesis for reformulation (see Agent Skills).
- Parameters:
- wd
pathlib.Path The agent working directory (on the host). Must already exist.
- wd
- Raises:
RuntimeErrorIf
wddoes not exist.
- run(wd)[source]¶
Run the agent in a Docker container.
Spawns a Docker container with the image specified by
IMAGEand bind-mountswdinto the container. The container entrypoint calls the agent command script which launches the agent. Agent output is written towd/agent_output.jsonl.The Docker image is expected to be built (see Installation).
- Parameters:
- wd
pathlib.Path The agent working directory to bind-mount at
/workspace/wdin the container.
- wd
- Returns:
- result
HarnessRunResult Duration, cost, token counts, and stop reason.
- result
- class milp_flare.harness.base.HarnessRunResult(duration_s, cost_usd, input_tokens, output_tokens, stop_reason)[source]¶
Result of a harness run returned by
Harness.run().- Attributes:
- duration_s
float Wall-clock duration of the agent run, in seconds.
- cost_usd
float, optional Estimated USD cost of the agent run, or
Noneif cost information is not available (e.g., model is missing fromCOST_PER_MTOK).- input_tokens
int Total input (prompt) tokens reported by the agent stream. Used by
COST_PER_MTOKto estimatecost_usdwhen not directly reported by the agent.- output_tokens
int Total output (completion) tokens reported by the agent stream. Used by
COST_PER_MTOKto estimatecost_usdwhen not directly reported by the agent.- stop_reason
str, optional Final stop reason reported by the agent (e.g.,
"end_turn","max_tokens").Noneif not reported.
- duration_s
- milp_flare.harness.base.IMAGE = 'flare-agent:latest'¶
The name of the Docker image containing the agent environment. This image is expected to be built prior to running FLARE. See Installation.
Agent Harnesses¶
- class milp_flare.harness.claude_code.ClaudeCodeHarness(model, effort='medium')[source]¶
Bases:
HarnessClaude Code agent harness for FLARE.
Use the Claude Code CLI as an agent harness. Authentication is provided by a long-lived OAuth token (
CLAUDE_CODE_OAUTH_TOKEN) generated viaclaude setup-tokenand is billed against a Claude subscription. See Claude Code for setup instructions.Warning
Starting June 15, 2026, Claude Agent SDK and claude -p usage no longer counts towards the Claude plan’s usage limits. It will instead charge a separate Agent SDK monthly credit. See this article.
- Parameters:
- model
str Claude model identifier. Only supports models that are supported by the Claude Code CLI (e.g.,
"claude-opus-4-7","claude-sonnet-4-6"). See Claude Code Docs for up-to-date model information.- effort
str, default"medium" Reasoning effort level (
"low","medium","high","xhigh","max"). See Claude Code Docs for supported effort levels for each model.
- model
- Attributes:
Examples
Configure Claude Code agent harness with Claude Opus 4.7 and high effort:
>>> from milp_flare import FLARE >>> from milp_flare.harness import ClaudeCodeHarness >>> harness = ClaudeCodeHarness(model="claude-opus-4-7", effort="high") >>> print(json.dumps(harness.get_config_dict(), indent=2)) { "harness": "claude_code", "image": "flare-agent:latest", "model": "claude-opus-4-7", "effort": "high" }
- class milp_flare.harness.codex.CodexHarness(model, effort='medium')[source]¶
Bases:
HarnessCodex agent harness for FLARE.
Use the Codex CLI as an agent harness. Authentication is provided by running
codex loginon the host to create a~/.codexdirectory with the necessary credentials; this directory is bind-mounted read-write into the Docker container. See Codex for setup instructions.- Parameters:
- model
str OpenAI model identifier. Only supports models that are supported by the Codex CLI (e.g.,
"gpt-5.4","gpt-5.5"). See Codex Docs for up-to-date model information.- effort
str, default"medium" Reasoning effort level (
"none","low","medium","high","xhigh"). See Codex Docs for supported effort levels.
- model
- Attributes:
Examples
Configure Codex agent harness with GPT-5.4 and high effort:
>>> from milp_flare import FLARE >>> from milp_flare.harness import CodexHarness >>> harness = CodexHarness(model="gpt-5.4", effort="high") >>> print(json.dumps(harness.get_config_dict(), indent=2)) { "harness": "codex", "image": "flare-agent:latest", "model": "gpt-5.4", "effort": "high" }
- class milp_flare.harness.opencode.OpenCodeHarness(model, effort='medium', provider=None)[source]¶
Bases:
HarnessOpenCode agent harness for FLARE.
Use the OpenCode CLI as an agent harness. Authentication is provided by API key. The following API keys are automatically forwarded from the host into the container if they are set:
ANTHROPIC_API_KEYfor Anthropic modelsOPENAI_API_KEYfor OpenAI modelsGOOGLE_API_KEYfor Google modelsDEEPSEEK_API_KEYfor DeepSeek models
See OpenCode for setup instructions.
- Parameters:
- model
str Model identifier passed to the underlying CLI. See OpenCode Docs for supported providers and models.
- effort
str, default"medium" Reasoning effort level (
"low","medium","high"). Supported reasoning effort levels vary by provider and model.- provider
str, optional The OpenCode model provider to use. By default, the provider is inferred from the model name. See OpenCode Docs for supported providers.
- model
- Attributes:
Examples
Configure OpenCode agent harness with DeepSeek V4 Pro and high effort:
>>> from milp_flare import FLARE >>> from milp_flare.harness import OpenCodeHarness >>> harness = OpenCodeHarness(model="deepseek-v4-pro", effort="high") >>> print(json.dumps(harness.get_config_dict(), indent=2)) { "harness": "opencode", "image": "flare-agent:latest", "model": "deepseek-v4-pro", "effort": "high", "provider": "deepseek" }
Pricing¶
- milp_flare.harness.cost.COST_PER_MTOK = {'claude-haiku-4-5': (1, 5.0), 'claude-opus-4-6': (5.0, 25.0), 'claude-opus-4-7': (5.0, 25.0), 'claude-sonnet-4-5': (3.0, 15.0), 'claude-sonnet-4-6': (3.0, 15.0), 'deepseek-v4-flash': (0.14, 0.28), 'deepseek-v4-pro': (1.74, 3.48), 'gpt-4.1': (2.0, 8.0), 'gpt-4o': (2.5, 10.0), 'gpt-4o-mini': (0.15, 0.6), 'gpt-5.4': (2.5, 15.0), 'gpt-5.4-mini': (0.75, 4.5), 'gpt-5.4-nano': (0.2, 1.25), 'gpt-5.5': (5.0, 30.0)}¶
Cost per million tokens (input, output). Used to compute cost_usd when the agent harness does not report cost directly. This is a fallback and is likely to become outdated quickly. See pricing documentation for the most up-to-date pricing information: