Wing Tips: Best Practices for Working with AI Agents in Wing Pro 12
This is the closing Wing Tip in the series on AI agents in Wing Pro 12. It collects the habits that produce reliable results.
Basic Principles
The fact that AI agents work as well as they do is remarkable, given that the LLMs that underlie them are (famously) prone to hallucinating and making other mistakes. The reason they work is that they build in self-checking feedback loops for every level of the software development process.
Your methodology in using them should embrace and build on this basic philosophy of cross-checking everything. There are two parts to this:
- Work in an environment where mistakes are contained and correctable.
- Recheck and review all work before accepting or shipping it.
AI Safety
The better AI agents have good safety controls out of the box. But like people, they can make mistakes, and when they do, they make them very quickly.
In order for an agent's work to be contained and correctable, you need to set up a reasonably protected environment in a VM, on a dedicated host, or at least in a dedicated account. Don't run an agent in an environment where it has access to the keys to your server infrastructure or sensitive data like customer records.
- Make sure your environment is backed up automatically, ideally continuously through something like Dropbox or iCloud.
- Use revision control with a remote repository that the agent cannot access. Ideally, set up a VCS-only SSH key and do all push or other operations that affect the remote repository manually.
Exactly how you approach this depends on your needs and risk tolerance, and the sensitivity of your work. In fact asking the agent for solutions is a great way to find relatively easy ways to set up an environment you are comfortable with. See also AI Agent Safety in Wing's documentation.
Treat the Agent Like a Capable Employee
The agent is fast, patient, and capable, but still needs clear instructions and supervision. For the most part, you will no longer be writing code; instead, it's your job to frame tasks, review outcomes, and steer iteration.
Your goal should be to set up a working environment that keeps it honest. That starts with clear instructions, which may be a one-line bug fix or a high-level specification that the agent researches and breaks into smaller tasks. It includes unit testing. It may include independent AI agent validation of work for correctness, performance, security, and other metrics.
Write down your development policies too, from coding style to workflow rules, in AGENTS.md (outside the block Wing maintains there). Agents read it at the start of every session.
Cross-Check from Different Angles
A single review pass can miss things on larger changes. That's true whether it's a human working independently, or an AI agent writing the code. Instead, where appropriate, try to run work through a few different lenses:
- Behavioral -- does this code really do everything in the spec?
- End Cases -- does this code fail to handle end cases that could occur?
- Security -- are there security flaws likely to be exploited here?
- Performance -- is this code going to be fast enough in production?
Since you can make the AI agent do the assessments, it becomes possible to review code in far more ways and far more deeply than was possible before the advent of AI agents. You can ask the agent to do things that no human employee would put up with:
"Re-read the change you just made and propose the three most likely sources of bugs. Don't fix anything; just list them."
Wing packages several of these lenses as one-click AI actions in the editor's Code Actions menu -- Review for Security Risks, Review for Code Quality, and Optimize Code -- each of which frames the request for you.
When agents work autonomously with the Tasks Manager, make some of these review passes a regular part of your workflow, as tasks of their own at key points. Each can turn up problems that become new tasks.
Review at the Behavior Level
Wing presents agent edits as diffs, which makes it tempting to review line by line. For small changes that's fine. For larger ones:
- Read the task's report -- its summary and judgement calls -- and the test results first.
- Skim the diff for surprises -- new dependencies, new files, scope creep, suspicious patterns.
- Spot-check a few hunks to confirm the agent's style.
- Trust the rest, contingent on tests and other cross-checks passing.
If you don't trust the test suite enough to do this, strengthen the suite first. The good news is, you just ask the agent to do that.
How much you read at the code level is up to you, and your answer will likely change over time. Once you trust your tests and cross-checks, you may find yourself reading reports and committing without reading every diff, and turning on the Tasks Manager so agents can carry out a series of tasks on their own. See the Wing Tip on autonomous development.
When the Agent Gets Stuck
Most of the time you don't need to watch the details of what the agent is doing. But occasionally, especially on a hard bug, an agent will start spinning its wheels -- trying one speculative fix after another, fixating on an approach that isn't working, or even brushing off your reports that something is still broken.
When you notice this, step in once or twice with more specific guidance, or point it at the debugger. When you hit an exception yourself, the FIX action in the Exceptions tool hands it to the agent with the full debug context. If that doesn't turn things around, don't keep iterating. It is usually better to start fresh than to try to course-correct an agent that has gone off the rails.
Before you do, look for any unwanted or half-finished code the agent left behind, and either ask it to remove that or revert to your last known-good commit. Then use Clear Conversation in the AI Agent tool's Options menu to start a new session, or start a new task from the Tasks tool. A fresh session has no memory of the origin or correctness of uncommitted code, so if you leave a broken attempt in place it may assume that code is intentional and fixate on the same wrong solution. Retrying the fix in Plan mode can help too, since it makes the agent reason through a new approach before changing anything.
Understanding Context and Token Costs
An agent uses both its already-learned knowledge about the software development process, from its original training, and also facts it has learned about your development environment and project. When you set up an agent with Set Up for AI Agent, Wing writes development guides into the .wing directory, describing how to use Wing's tools and your project's testing regimen and commit policy, and points AGENTS.md at them. Wing also offers to run the agent's own project analysis, if it has one, so the agent starts with its own notes about your code as well.
All of this is combined with input seen in the current session into a working context that is essentially a short-term memory. Every time you start a new session, the agent forgets everything, and then reloads some of its memories from those files.
This is a simplification, but enough to be able to manage what really matters here -- token use. The more the agent has in its memory, and the more it has to read through while doing tasks, the more tokens it uses up out of your allowance. Keeping that under control is an important part of using AI agents.
Wing helps with that. We've designed the Tasks tool and the MCP servers that agents use to keep token consumption lower. In our initial benchmarks, run with Claude Code, this often meaningfully reduced the API cost and time to finish a task, though how much depends on the work -- the tools help most when the bottleneck is locating code or runtime state. See the benchmark write-up for the details.
The decision you will have to make is when to clear the conversation in an agent session, or when to use the Q menu in the Tasks tool to change the session reuse and run modes (as discussed in an earlier Wing Tip) to use context when relevant and discard it when not. When the Tasks Manager is enabled, it makes these choices for you, running closely related tasks in the same session so later ones keep the context of earlier ones. Setting goals aside with the clock icon in their headers on the Plan tab keeps both your plan and the Manager focused on current work.
Further Reading
Wing's AI agent integration has a lot of features, but you don't need to understand all of them to get started. When in doubt, ask the agent!
See also Autonomous Development with AI Agents, AI Agent-Assisted Development, and Using AI Agents Effectively in Wing's documentation.
That's it for the AI agent series! We'll be back soon with more Wing Tips for using Wing in everyday Python development.
As always, please don't hesitate to email support@wingware.com if you run into problems or have any questions.