What will the agent do, and what may it touch?
I build autonomous AI agents and systems, and I’ve built and introduced AI systems that can run businesses. In my experience, the model is rarely the hard part. The hard part is deciding, in writing, what the agent is for and what it may touch.
So I start with the business outcome and the real workflow, then plan a narrow first version. Before any code, write down:
- The job, in one sentence.
- Every action the agent could take, each marked as read-only, draft, or a change that needs approval.
- What the agent must never do, whatever anyone tells it.
- Who approves, and what they need to see to approve with confidence.
- What done looks like, so the agent can be tested against it.
Wakeel is a good example of the right size: one process, Dubai rent renewal. A job that narrow is what makes a fixed rules engine, an approval step and a complete audit trail practical to build.
What does a safe AI agent architecture look like?
A safe agent is mostly ordinary software with a language model in one well-fenced place. Follow a request through it and you meet six parts:
- The modelReads the request, chooses a tool and writes the reply. It explains and drafts. It never holds the final numbers or the final say.
- ToolsNarrow, typed functions the model may call, such as looking up a product or requesting a calculation. Each one is validated on the server like a public endpoint.
- Rules and real dataPlain code that calculates figures, and live records from the system of record. The same input always gives the same output.
- An approval stepAnything that changes the world waits as a pending action until a person approves it.
- An audit trailA record of every step: the request, each tool call and its result, the proposal, the approver and the outcome.
- Evaluations and a budgetA test suite that runs on every change, and a cap on what the agent may spend on AI.
Keep the agent’s working state in your database, not only in the conversation. A task that spans several steps should survive a page refresh, a retry or a handoff, and the audit trail needs something solid to point at.
Wakeel shows the core of this shape. The agent calls a fixed rules engine through tools, waits for a person’s approval before acting, and signs every step into a hash-chained audit trail.
Why should rules, not the model, calculate the numbers?
Language models are good with language and unreliable with guarantees. Ask one to total a week of sales and it will often get it right, which is not the same as always. A business can’t run on often.
So in Posific, fixed rules calculate every figure, and the AI only explains and drafts. Its job is to put a number into plain words, never to produce one. The same split runs through Wakeel: rent renewal involves rules and money, so the agent asks a fixed rules engine for answers through tools rather than working them out itself.
There is a second benefit. When the numbers come from rules, you can test them with ordinary unit tests, the way you test any other code. Most correctness problems become normal software problems, which teams already know how to solve.
Prices, taxes, totals, dates, eligibility and anything a customer could dispute. If a person would check it with a calculator or a rulebook, it belongs in code.
How should you design AI agent tools?
Tools are the agent’s hands, so most of the safety work happens here. Design them like an API for a stranger, because the model will call them in ways you didn’t plan for.
- Keep each tool narrow. “Look up this product” is safer than “run any query.”
- Separate reading from writing. Read tools can run freely; write tools should create a pending action rather than change anything directly.
- Validate every input on the server: types, ranges, permissions, and whether this user may touch this record.
- Make writes safe to repeat. Models retry and networks fail, and a repeated call shouldn’t create a second order.
- Return plain facts, not prose, so the model has less room to misread them.
Write each tool’s description as carefully as documentation for a new colleague: what it does, when to use it and when not to. The model picks tools by reading those descriptions, so vague ones lead to wrong calls.
The mustashar.ae store shows why the server must stay in charge. Its checkout is priced on the server, with duplicate-order protection and retries. The official prices and stock live in the Posific POS, which the store syncs with through signed webhooks, a change feed and scheduled jobs. The AI shop assistant looks up live product data, so whatever is said in a chat, the figures come from the system of record.
How do you build approvals and an audit trail?
An approval step is easy to describe and easy to get wrong. The agent should prepare a complete, specific proposal: what will happen, to which record, with which numbers, and why. The person approves that exact proposal. If anything changes afterward, it needs approving again.
The audit trail is the other half. Wakeel signs each step into a hash-chained audit trail. Each entry carries a fingerprint of the one before it, so editing or deleting any past entry breaks the chain from that point on. Wakeel also has a tamper test. The idea is simple: alter a record on purpose and confirm that verification catches it.
Each audit entry should hold:
- The request, and who made it.
- Every tool call, with its inputs and outputs.
- The proposal shown to the approver.
- Who approved or rejected it, and when.
- The final result.
How do you test an AI agent and cap its costs?
An agent isn’t ready because it handled the demo. It’s ready when it passes a written set of scenarios, including people trying to misuse it. Three examples from my own work:
- Every update to Posific goes through an evaluation suite, so anything that breaks agreed behavior shows up as a failing test, not a complaint.
- Wakeel passed all 11 of its live evaluation scenarios.
- The mustashar.ae assistant went through 240 normal scenarios and 40 attack attempts before it went live.
Then cap the spend. Posific gives each business a daily AI budget, and the mustashar.ae assistant has a spending cap. A loop that misbehaves, or a user who floods the chat, should hit a ceiling, not your invoice. I go deeper on testing in my article on how to evaluate an LLM app.
Do you need an AI agent framework or a multi-agent system?
An AI agent framework can save time on the loop itself: calling the model, routing tool calls, keeping conversation state. That part is useful but generic. A framework won’t decide what your agent may touch, how your numbers are calculated or who approves what. Whether you adopt one or write the loop yourself, those decisions stay with you.
Multi-agent systems split work across several agents, often with one coordinating the rest. They can help when a job genuinely divides into separate skills. They also add hand-offs, more places for errors to compound and more paths for untrusted text to travel. They are harder to test, and harder to explain to the person approving the result.
My advice is to start with one agent, one job and a rules engine behind its tools, which is the shape Wakeel has. Split the work across agents only when your evaluations show that one agent can’t do the job well.
A checklist before your AI agent touches real data
- The job and the forbidden actions are written down.
- Every number comes from rules or real data, never from the model.
- Tools are narrow, validated on the server and safe to repeat.
- Every write waits for approval, and the approver sees the exact proposal.
- Every step lands in an audit trail that can’t be quietly edited.
- Normal scenarios and attack attempts pass, and they run again on every change.
- A budget caps AI spend, and there’s a clear route to a person.
Frequently asked questions
What programming language should I use to build an AI agent?
Use the language your product already runs on, because the agent needs close access to your data, rules and permissions. Much of my work runs on Next.js and PostgreSQL, with native Kotlin apps on Android. The language matters far less than the structure around the model: narrow tools, rules for numbers, approvals, an audit trail and tests.
Can an AI agent connect to my existing systems?
Yes, through tools that call your existing APIs or database. Keep the existing system as the source of truth. On mustashar.ae, the official prices and stock live in the Posific POS, and the store syncs with it through signed webhooks, a change feed and scheduled jobs. An agent should read from systems like these rather than keep its own copy of the truth.
How do you stop an AI agent from making up numbers?
Don’t ask it for numbers. Calculate them with fixed rules or read them from real data, hand them to the model, and let it explain them. That’s how Posific works: rules calculate every figure and the AI only explains and drafts. Then check it: your evaluation scenarios should confirm that any figure in a reply matches the one the rules produced.
What’s a common mistake when building an AI agent?
Giving it broad tools and trusting the prompt to keep it in line. An instruction to a model is a request, not enforcement. Enforcement lives in code: narrow tools, server-side checks, approvals and budgets. Build it so that if the model does the wrong thing, the system around it still refuses, and the audit trail shows exactly what was attempted.











