Implementation:2akouwu Reverify ReconstructionAgent
| Knowledge Sources | |
|---|---|
| Domains | Reverse_Engineering, LLM_Agents, Iterative_Refinement |
| Last Updated | 2026-10-24 12:00 GMT |
Overview
Concrete tool for running the closed propose-verify-revise loop until grounded or capped, provided by the Reverify library.
Description
The ReconstructionAgent class implements the closed verification loop. It takes binary bytes, a proposer callable (from openai_proposer or demo_proposer), and configuration (max rounds, samples, min information, ledger, prompt budget). The run(goal) method executes the loop: build prompt from fact sheet + ledger, call proposer, parse claims, verify all, apply anti-gaming (echo/known detection), record to ledger, generate feedback, and repeat until grounded or max_rounds.
The agent also provides binary_facts(data) (build the fact sheet), compact_facts(facts, budget, ...) (shrink the view to fit the prompt budget), build_prompt(...) (assemble the prompt), parse_claims(raw) (tolerantly extract JSON claims from model response), openai_proposer(...) (OpenAI-compatible API proposer), and demo_proposer(data) (offline proposer for testing).
Usage
Import this class when you need to:
- Run the full propose-verify-revise reconstruction loop on a binary.
- Use a real LLM (via
openai_proposer) or offline demo (demo_proposer) as the proposer. - Resume a reconstruction from an existing ledger after a context reset.
- Run the
reverify reconstructCLI subcommand or themodel_loopbenchmark.
Code Reference
Source Location
- Repository: Reverify
- File: reverify/agent.py
- Lines:
ReconstructionAgentat L377-542;__init__at L388-419;runat L421-542;binary_factsat L142-169;compact_factsat L347-374;build_promptat L172-218;parse_claimsat L221-239;openai_proposerat L545-582;demo_proposerat L585-607
Signature
class ReconstructionAgent:
def __init__(
self,
data: bytes,
propose: Proposer,
max_rounds: int = 4,
samples: int = 1,
min_information: float = 1.0,
max_facts: int = 40,
ledger: Any = None, # Ledger, dir path, or None (in-memory)
resume: bool = True,
prompt_budget: int = 60000,
session: Optional[str] = None,
file_path: Optional[str] = None,
):
...
def run(self, goal: str) -> Dict[str, Any]:
"""Run the loop until grounded or max_rounds. Returns result dict."""
Import
from reverify.agent import ReconstructionAgent, openai_proposer, demo_proposer
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| data | bytes | Yes | Binary bytes to reconstruct |
| propose | Callable[[str], str] | Yes | Proposer function (prompt -> response text) |
| max_rounds | int | No | Round cap (default 4) |
| samples | int | No | Proposals per round (default 1) |
| min_information | float | No | Grounding weight threshold (default 1.0) |
| max_facts | int | No | Bounded view size (default 40) |
| ledger | Ledger/str/None | No | Ledger instance, directory path, or None (in-memory) |
| resume | bool | No | Continue from existing ledger (default True) |
| prompt_budget | int | No | Max prompt chars (default 60000) |
| session | str | No | Session label for the ledger |
| file_path | str | No | Binary file path (for ledger keying) |
| goal | str | Yes | Plain-language reconstruction goal (for run)
|
Outputs
| Name | Type | Description |
|---|---|---|
| return | Dict | Result: goal, grounded, rounds_used, information, verified_claims, observed, established, resumed_facts, compactions, over_budget, session, ledger summary, ledger_path, history (per-round reports), final_report |
Usage Examples
With a Real LLM
from reverify.agent import ReconstructionAgent, openai_proposer
with open("target.dll", "rb") as f:
data = f.read()
propose = openai_proposer(model="gpt-4o") # uses OPENAI_API_KEY env var
agent = ReconstructionAgent(
data, propose,
max_rounds=4,
min_information=1.0,
ledger="./ledgers", # persist to disk
resume=True,
)
result = agent.run("Reconstruct the entry-point function and its prologue")
print(f"Grounded: {result['grounded']}, Rounds: {result['rounds_used']}")
print(f"Information: {result['information']}")
Offline Demo
from reverify.agent import ReconstructionAgent, demo_proposer
# No API key needed; demo_proposer makes informative claims about the bytes
propose = demo_proposer(data)
agent = ReconstructionAgent(data, propose, max_rounds=3, ledger=None)
result = agent.run("demo reconstruction")
CLI Usage
# Live reconstruction with OpenAI
reverify reconstruct target.dll --goal "Reconstruct entry point"
# Offline mock
reverify reconstruct target.dll --goal "demo" --mock