Designing Tools for Intelligent AI Use
I have been putting AI agents to work in a few unrelated areas: binary analysis, development in a legacy language, script deobfuscation, and legal research over a large document set. The subjects have nothing in common, but the same approach kept working in all of them. This post writes it down in general terms. Earlier write-ups with the details are linked at the end.
An agent is a model running in a loop: it takes an action, sees the result, and decides what to do next. The intelligence is in the model. The agency comes from the loop. Everything else is plumbing, and the plumbing is what this post is about.
The short version: put the specialized knowledge and the exacting mechanics into tools, give the agent a clean way to drive those tools, and let the agent do the reasoning. The tool does what must be right every time. The agent does what needs judgment. Most of the work is deciding where that line goes.
1. Expose what you already have
You usually don't need to build an "AI interface". If your program already has an internal data model, expose that, through whatever scripting or IPC mechanism your platform has: COM, a local socket, an embedded script engine, a REST endpoint, or just an export to SQLite. The agent then drives the same structures your own code uses, and it can do anything the program can do.
This changes what you build. Where you once would have written a feature with its own UI, you can now export the data and let the agent do the work. One example: I wanted binary diffing for a disassembler. Instead of a diff engine and a viewer, the tool exports its parsed model to a database, two binaries go into one file, and the agent does the diff with SQL and judgment. The tool side is deliberately dumb and the agent side is smart. Likewise, thousands of legal PDFs became useful to an agent once they were in tables with full-text search. The work was in the database, not in an app on top of it.
A few things make an exposed model much easier for an agent to use:
- Generate the schema; don't hand-write it. Give the agent a description of your object model, generated from the source code and regenerated when the code changes, so it stays current. A short hand-written briefing covers the rules; the generated schema covers the shape. Nothing about your specific classes needs to go in the prompt, because the agent can look it up.
- Let the agent look up the schema a piece at a time. For a large object model, the whole
schema is too much to hand over at once. One file per class, or a
describe(obj)call that returns the shape of whatever object the agent is looking at, lets it pull in only the parts it needs. - Summaries first, details on request. Raw output can easily flood the agent's context and crowd out its reasoning. Have calls return counts, summaries or a page of results first, and let the agent drill down into the parts that matter. A search that returns the first 20 hits and a total count is more useful than one that returns 40,000 lines.
- Offer machine-readable output. If the tool produces text formatted for people, also offer structured output (JSON, rows, typed fields). Don't make the agent scrape a display format.
- Let it check what it is talking to. A call that reports the tool's version and build, and a state flag for "is something loaded, and has it changed", prevent a whole class of confused sessions.
- Design out anything that waits for a human. Modal dialogs, confirmation popups and
"press any key" prompts hang an automated session. Add an automation mode that records those
messages somewhere readable instead, and a
Busyflag for anything asynchronous, so the agent can wait for real completion. - Keep it running. If loading or parsing is expensive, let the tool act as a persistent local data server. Parse once and let many agent sessions query it. As a bonus, the data set stays on your machine (only what the agent actually reads goes to the model), and you can use whichever model you like.
More: Scripting the disassembler walks through publishing a live object model to an agent, and Agentic Coding Against Live Object Models covers generating the schema files and building the agent loop.
2. Draw the line between the tool and the agent
The rule I use: if it must be exactly right, repeatable, or is something the model would get quietly wrong, it goes in the tool. If it needs context, interpretation, or a decision about what to do next, it stays with the agent.
Written out for a bytecode decompiler, the split looks like this:
| Who | Provides |
|---|---|
| the disassembler | structure: the instruction listing, decoded operands, variable and type layouts |
| an opcode database | semantics: what each instruction does to the stack and interpreter state |
| the agent | simulation: walk the listing, apply the semantics, write readable statements |
A PowerShell deobfuscator I built (an internal tool) works the same way. It runs as a pure single-layer transform: it parses, canonicalizes and folds constants, and that is all. It does not decide whether there is another layer underneath, does not make assumptions about the host, and does not recurse. Those decisions belong to the agent, whose instructions start with "You are the intelligence layer above the tool."
Neither half is complete alone, and that is the point. The tool is reliable because it does not guess. The agent is effective because it does not have to rediscover the mechanics.
3. Measure a heuristic before you build it in
The previous section says to keep judgment out of the tool. This is where that gets tested, because adding a clever heuristic to a tool feels like progress. Before you automate a judgment call, measure whether it actually helps.
The deobfuscator had an identifier renamer that replaced random names like
$PtdJ0cKe4t9aa with $v1. Obviously helpful. Then I ran it against 200 real
samples (199 completed; one 11 MB file timed out). About half of the identifiers in real malware were already meaningful, things like
$var_code and func_get_proc_address, because a lot of it is repackaged
offensive tooling whose obfuscator never touched the names.
| before | after | |
|---|---|---|
| identifiers renamed | 83% | 42% |
| renames destroying a meaningful name | 48% | <1% |
| files helped / hurt / unchanged | 60 / 94 / 45 | 54 / 24 / 121 |
The renamer now defaults to keeping names. Working out what a variable actually holds is left to the model, which is good at it. Inferring intent is a job for a model, not a heuristic.
When you do want automated classification, run the cheap, deterministic methods first and give the model only what is left. For the legal database, case outcomes were classified with regular expressions against the order text, then a pass to repair failed PDF extractions, then a regex fix for a phrasing variant in older decisions. Only the remaining low-confidence cases went to a model. Unknowns went from 48.8% to 2.7%, and the model spent its time on the cases that actually needed it. That number is coverage, not accuracy: it says how many cases got a label, not how many labels are right. Which is exactly why the next section matters.
4. Make the tool honest about its limits
An agent can only reason well about a tool's output if the tool says where its knowledge ends. A tool that reports "I couldn't handle this part" gives the agent something to act on. A tool that quietly does its best leaves the agent building on something it can't check.
Some forms this takes:
- Refusal notes. The deobfuscator writes a notes file listing what it declined to fold and why. That file is the agent's map to the next layer.
- Confidence grades. Each output is graded
Clean,DegradedorUntrusted. In the 200-sample run, every output it graded as trustworthy reparsed (174 of 174), and the outputs that failed were all in files it had already flagged. Reparsing shows the output is valid syntax, not that it means the same thing; that is what the differential tests in the next section are for. - Completeness flags. The disassembler's database export marks each binary complete or not, so a partial export from a crash doesn't get compared as if it were whole.
- Provenance. The legal database records which method classified each case, keeps the model's reasoning for the cases a model classified, and lists known gaps and unverified fields in its notes.
- Verbatim errors. When something the agent sent fails, return the exact error together with the exact input that caused it. Not a summary. The model is good at spotting its own mistake, but only if it sees exactly what it sent. Adding "do not repeat the same input" stops it from resubmitting the same broken call.
- Known bad errors, translated. If a tool produces a uselessly vague error for a known cause, say so in the briefing: "an empty error on line 1 almost always means X". That one line replaces several rounds of guessing.
5. Use the real implementation as the oracle
Documentation describes what something is supposed to do. The real compiler, runtime or engine is what actually does it. Wherever possible, check against the real thing.
- The deobfuscator's test harness runs the original expression and the transformed one through the real PowerShell engine and compares values and types. "Semantics preserved" is measured, not claimed. Several findings contradicted reasonable-sounding assumptions from the docs.
- The opcode database was checked against the runtime's actual handler code, not just written from documentation.
- When rewriting a component, build the old and the new version, run both on the same real data, and compare the output. That differential test caught a regression hand testing missed. Let the differential decide.
- Every language trap in the briefing (next section) is backed by a small program that compiles and runs it, so each claim is a checked fact.
This matters twice over with an agent: it tends to take what you tell it at face value, and it can reason its way to a confident wrong answer from a wrong premise. It doesn't always need to know the right answer if it has a reliable way to test its answer.
The agent's own work needs testing too. Deterministic parts of the system can have ordinary tests. Judgment can't, so keep a set of representative tasks, save the traces, and check the outcomes whenever you change the briefing or the tools. Keep the briefing under version control so you can tell which change made things better or worse.
For work where there is no oracle at all, such as a design document or a write-up like this one, the nearest substitute is independent review. Different models were trained differently and miss different things, so running a draft past two or three of them surfaces more than any one alone. This post went through that process, and the reviewers caught real problems: one noticed that a table's rows summed to 199, not 200; another pointed out that raw tool output can flood an agent's context. Treat what reviewers say as leads to check, not as findings. Verify each claim before acting on it, and ignore the praise and the scores.
6. Write down where the model's instincts are wrong
A model's training is an average of what is common. In a mainstream language or a well-known API, that is a good guide. In a niche, legacy or in-house environment, it is a confident and wrong one. The model doesn't fail because it knows nothing. It fails because it "knows" the common case and applies it where it doesn't hold.
Some examples of the kind of thing that cost hours until they were written down:
- a compiler that rejects files with Unix line endings, with an error that doesn't mention line endings
- a build tool that reports errors in a modal dialog unless given a log-file switch, so an automated build simply hangs
- a language where
AndandOrdon't short-circuit, and an inline conditional evaluates both branches - two ways of getting the same object from a scripting host, one of which returns a dead stub with empty properties
So the briefing you give the agent is mostly not a tutorial. It is a list of places where its instincts are wrong, plus working templates so it doesn't have to rediscover how to build and test. The warnings are the most valuable lines in it. Keep the prompt about the rules of the environment, not about your data; the data it can discover.
There is a practical reason all of this has to be written down: you can't count on the agent carrying the details from one session to the next. These documents are its memory. Every time a session hits a new snag, it should end with a line added to the briefing. I now write two documents for a project like this: a package written for the AI, and a paper written for people.
More: AI Assisted VB6 Development is a full worked example of this kind of package, gotchas, templates and all.
7. Give the agent a clean feedback loop
Agents work in a loop: change something, run it, look at the result, fix it. If the environment was designed for a person clicking through a GUI, most of your effort goes into making that loop possible: command-line builds with a log file, test harnesses that write results somewhere readable, error locations mapped back to the real source line, and a way to drive a running program and time it from inside.
The loop also has to give a clean signal. Two lessons:
- Make each step stand alone. In one agent loop, a script engine kept variables from one step to the next. The agent got the right answer, but only because a leftover variable from an earlier step happened to hold the right value. That is accidental correctness, and it hides bugs. Resetting the engine between steps means each step works or fails on its own. This doesn't conflict with keeping a tool running as a data server (section 1): the loaded data can persist, while the agent's scratch state should start fresh each step.
- Log everything, verbatim. The full prompt, each action the agent took, each result, each error, with timestamps. When something goes wrong you can read exactly what the agent saw and did. The log is also the best thing to hand back to an AI when debugging; it will find things in it you wouldn't have thought to mention. Every choice the model makes should be auditable.
If the agent can see and check the results of what it did, it can correct itself. If it can't, it guesses.
8. Put safety in the tool, not just the prompt
There are two kinds of safety here, and they suit different work.
For ordinary development, containing the environment usually does the job: run the agent in a throwaway VM and let it work freely. That is how I handle the legacy development work.
When the input itself is hostile, the tool has to enforce it. The deobfuscator handles live
malware, so it can't rely on the agent remembering a rule. The one component that executes code
(for the differential tests) has two independent guards: it won't start without an explicit
--unsafe flag, and the execution function itself throws unless it has been armed. It
also refuses to run if its test directory contains hash-named files, which catches the realistic
accident of real samples getting copied into the wrong place.
The safe, parse-only tool has no gate at all, on purpose. Putting friction on the safe tool would push people toward the unsafe one. That applies to agents too: make the safe path the easy path, and make the dangerous path hard. Prompt rules still help (never execute any part of a sample; decode a layer by extracting its data and applying the transform yourself), but they are the second layer, not the first.
Hostile input isn't only code that might run. A document, a source comment or a tool's output can contain text addressed to the agent ("ignore your instructions and..."). Whatever the agent reads through a tool is data to analyze, never instructions to follow. Say so in the briefing, and don't give the agent capabilities on hostile input that it doesn't need.
9. Make mistakes cheap to undo
The agent will sometimes take the wrong action: misread the state, repeat a step, or head down the wrong approach entirely. Plan for it. A tool that makes mistakes easy to detect and reverse gives the agent room to explore.
- Never modify the original. The deobfuscator always keeps the original input untouched, and its lossy renaming step always writes an original-to-new mapping, so nothing is unrecoverable.
- Work on copies. When verifying a shared component against every program that uses it, copy each one to a scratch folder, build it unmodified as a baseline, then swap in the new component. The real source tree is never touched.
- Make long jobs resumable. The disassembler's database export marks a crashed export as incomplete and can resume it, rather than leaving a half-written file that looks finished.
- Look before changing. Where possible offer read-only inspection, dry runs, and operations that are safe to repeat, so the agent can check what it is about to do and confirm what it did.
10. User wishes go to the agent; agent friction goes to the tool
Once a tool is scriptable by an agent, most feature requests turn into "ask the agent". You no longer need to build every report or analysis someone might want. Features that were never worth building and maintaining for a handful of users become one-off agent tasks. Operations that get repeated often are still worth turning into real code, for speed and repeatability, but the bar for doing so is much higher than it used to be.
What does still need building is whatever the agent keeps tripping over. If it repeatedly misreads an output, needs a value it can't get, or burns time on a step that should be mechanical, that is the next tool feature. The agent is a very thorough user, and its friction is a good feature list. The tool and the agent get better together.
That gives a simple test for where a new capability belongs. If it varies from one user or one question to the next, it belongs above the tool, with the agent. If the agent keeps needing it, it belongs in the tool.
Checklist
- Expose your program's real data model, with a generated schema the agent can look up piece by piece, and machine-readable output that starts with summaries.
- Remove anything that waits for a human; add state and busy flags.
- Decide what must be exact (tool) and what needs judgment (agent), and keep them separate.
- Don't build heuristics that guess at meaning. Measure before you trust one. Run cheap methods first and give the model the rest.
- Have tools report what they refused, how confident they are, what is incomplete, and the exact error with the exact input.
- Check against the real implementation, not the docs. Test the agent's work with representative tasks, and use independent model reviews where there is no oracle.
- Write a briefing that lists where the model's instincts are wrong, and prove each claim.
- Build a loop the agent can run on its own, with isolated steps and a verbatim log.
- Contain the environment, and put hard guards in the tool when the input is hostile. Treat anything the agent reads through a tool as data, not instructions.
- Never modify originals; make long jobs resumable and mistakes reversible.
- Send user wishes to the agent and agent friction to your feature list.
Taken together, the point is not to make the model reliable. It is to build around the model so that its mistakes are visible, testable, contained and easy to undo.
The agent doesn't need to be an expert in the domain. It needs tools that are, and room to think.
Further reading
- Scripting the disassembler (Talos): publishing a disassembler's live object model to a local agent.
- Agentic Coding Against Live Object Models: building an agent loop over a running program's objects, generated schema files, error handling and logging.
- AI Assisted VB6 Development: a complete AI-facing package for a hostile build environment, with live GUI driving and differential testing.
- NYS Tax Research Database: the legal document set, with its classification method and data quality notes.