| Author: Abdullah Ahmed | Category: Custom Web Application Development
A purchasing application already knows that an order above a defined threshold needs approval. It does not need an AI agent to rediscover that rule. The harder work happens when a supplier sends an unclear explanation, several records disagree, and an employee must decide which information to gather before preparing a response.
Rules and AI reasoning serve different purposes in custom business software. Rules express conditions the organisation wants enforced consistently. AI can assist with interpreting varied information and selecting a useful next step within a defined task. Combining them well requires a clear boundary between suggestions, evidence gathering, and authoritative decisions.
The phrase reasoning can also overstate what a system guarantees. An agent's generated plan is not proof that the plan is correct. This article treats agent reasoning as adaptive task behaviour that must be evaluated, constrained, and connected to confirmed application outcomes.
Keep explicit policy in explicit code
When a requirement can be stated precisely, implement it through ordinary application logic. Required approvals, allowed state transitions, account ownership, and valid monetary ranges should be enforceable without asking a model whether they seem appropriate.
Such rules are easier to inspect when they have a named owner and meaningful tests. A product manager can explain the policy, an engineer can locate its implementation, and an operator can see why a request was accepted or rejected.
Avoid moving established policy into a long prompt simply because the new feature includes AI. Prompt text may help the model understand the workflow, but the execution service should still reject an operation that violates the application's rules.
Rules can change over time. Store and deploy them through a controlled process, with version information where decisions must be explained later. Consistency does not require freezing policy permanently; it requires making changes deliberate and traceable.
Identify where the next step depends on interpretation
Some work cannot be described as a short fixed sequence without an unwieldy collection of branches. An employee may read a supplier explanation, decide whether to inspect an order or a delivery record, and ask for clarification when neither resolves the issue.
That adaptive information-gathering work is a more plausible place for an agent. Its role can be to choose among approved lookups and prepare a supported proposal. It need not receive authority to make every downstream change.
Look for a real uncertainty about the next useful step. If the workflow always reads the same three records and produces the same structured output, conventional orchestration with one model call may be simpler and more predictable.
Anthropic distinguishes predefined workflows from agents that direct their own process and tool use. That distinction helps teams discuss architecture in concrete terms: which steps are fixed, and which choices genuinely benefit from adaptive selection?
Use a spectrum of designs rather than a binary choice
At one end, ordinary software processes structured inputs through known rules. A step further, a model extracts or summarises information within a fixed workflow. Beyond that, an agent chooses among bounded tools to complete a task.
These designs can coexist in one application. A model might classify an incoming request, a deterministic router might select a workflow, and an agent might investigate only the exceptional cases that need additional evidence.
Choose the least complex design that meets the requirement. More autonomy adds questions about stopping, permissions, cost, recovery, and evaluation. Those costs may be justified, but they should follow a demonstrated need rather than a product label.
Write the design choice next to the task. “Extract fields with a fixed schema” and “investigate an unresolved delivery discrepancy” imply different architectures. Calling both features agents hides the decisions that determine implementation effort.
Draw the boundary between interpretation and execution
A robust pattern lets AI interpret information and propose an operation, while application code validates and executes the operation. The proposal should be structured enough to inspect: affected record, requested change, evidence, and unresolved assumptions.
The validation layer checks identity, permissions, required fields, current state, and business constraints. It should operate even when the proposed action appears persuasive or the assistant claims that approval has already been obtained.
Execution then uses a supported interface with a defined outcome. The resulting record or operation status becomes the basis for the assistant's response. This prevents a generated narrative from becoming the only account of what the system did.
Keep the boundaries visible in logs and user interfaces. A proposed action, a rejected proposal, a pending operation, and a confirmed result should remain distinguishable throughout the task lifecycle.
Work through an illustrative purchasing exception
Suppose a supplier writes that an item is unavailable and offers a substitute. A fixed intake step identifies the purchase order and captures the message. The application verifies that the sender and order reference are appropriate for the workflow.
An assistant can compare the offered item with approved product information and retrieve the relevant order details. If the substitution terms are incomplete, it can prepare a clarification request. These are interpretation and evidence-gathering activities.
The purchasing application's rules still decide who can approve a substitution and whether the proposed change is valid. A reviewer sees the specific replacement, quantity, price implications, and supporting information before making the decision.
After approval, the execution service updates the order through its supported operation and records confirmation. If the update fails or its outcome is uncertain, the system exposes that state instead of telling the supplier the substitution is accepted prematurely.
Define tools around narrow business capabilities
An agent should have a small set of tools relevant to its task. Reading a purchase order, retrieving a product specification, and preparing a clarification draft are easier to control than unrestricted access to a database or arbitrary network requests.
Each tool needs a validated input schema and a clear response contract. Include not-found, forbidden, ambiguous, and unavailable outcomes. The agent should be able to stop or ask for help when the available evidence does not support progress.
Separate read tools from write tools. Different credentials or execution paths may be appropriate. A research step should not acquire the ability to change records merely because the overall workflow eventually includes a write.
Review what tool outputs reveal. Return only the data needed for the task and enforce resource permissions at the owning service. A narrow operation with an excessively broad response can still expose unnecessary information.
Treat retrieved text as evidence rather than instruction
Agents may read supplier messages, documents, web pages, or internal notes. Any of those can contain text that attempts to redirect behaviour. The system should not treat such content as authority to change tools, permissions, or the task objective.
Keep high-trust application instructions separate from external material and validate actions outside the model. Even a well-designed prompt cannot replace server-side checks on allowed operations and destinations.
For the purchasing example, a supplier attachment saying to send internal pricing data elsewhere should remain document content, not become a command. The assistant's accessible tools and data policies should prevent the unrelated action.
OWASP's AI agent security guidance addresses prompt injection and tool-use risks. Apply it to the actual data and action paths in your system, including information returned by otherwise legitimate internal APIs.
Give every adaptive run a stopping condition
An agent needs a clear definition of completion. For an investigation, that may be a supported proposal or a documented unresolved question. “Keep working until the issue is solved” is too broad when the system cannot control all dependencies.
Set limits on elapsed time, tool calls, cost, and repeated unsuccessful attempts. When a limit is reached, preserve the useful evidence and route the case appropriately. A bounded incomplete result is preferable to an indefinite loop.
Detect repeated actions that do not add information. If the same lookup returns the same unavailable state, the runtime should apply retry policy or stop. The model should not be solely responsible for managing operational traffic.
Include a user or operator cancellation path. Explain which work can stop immediately and which submitted operations need confirmation. Cancellation should not erase the record of actions that already completed.
Store workflow state outside conversation history
A conversation can help communicate context, but important business state belongs in application storage. Persist the task identifier, proposal version, approvals, operation references, and confirmed outcomes in a form the system can query reliably.
This matters when a process restarts, a user returns later, or another employee takes over. The application should not need the model to reconstruct whether a message was sent from a long transcript.
Use explicit state transitions for the execution path. Pending approval, approved, submitted, confirmed, failed, and uncertain may require different handling. Choose the states that reflect the actual operation rather than a generic running or done flag.
Apply concurrency controls where multiple actors can change the same record. Before execution, check that the approved proposal still applies to the current version. An agent working from stale information should not overwrite a later human decision.
Design recovery before expanding authority
A read-only investigation can usually be restarted with limited consequences. A workflow that sends messages or changes orders requires duplicate prevention and a plan for uncertain outcomes.
Use stable operation references and destination-supported idempotency where available. If a request times out, reconcile with the destination before repeating a consequential action. The absence of a response does not establish that the action failed.
For several related writes, define what to do if only some complete. A compensating action may be necessary, or a person may need to resolve the case. Do not assume a distributed workflow can be rolled back like one local database transaction.
Provide an exception queue that explains the affected business records and next steps. Recovery should be a supported operational capability, not an improvised sequence of database edits during an incident.
Evaluate the task rather than the conversation alone
A convincing explanation can hide an incorrect tool choice or an uncompleted operation. Evaluate the final business state, evidence quality, permission enforcement, and recovery behaviour alongside the assistant's language.
Create cases that require different paths, including a straightforward resolution, missing information, conflicting records, an unauthorised request, a failing dependency, and a case that should be escalated. The correct outcome may be to stop rather than act.
Measure unnecessary tool calls and review effort as well as successful completion. An agent that eventually reaches the right answer through excessive calls may be too slow or costly for the intended workflow.
Test rules independently from model behaviour. A forbidden operation should remain forbidden under every prompt and model version. This separation gives the team a stable safety and correctness foundation while the adaptive component evolves.
Compare operating cost with the simpler alternative
Agent costs include more than token usage. Retrieval, tool execution, queue management, review, tracing, evaluation, and incident response all contribute. The more variable the workflow, the more attention it may require during rollout.
Compare against a fixed workflow and a manual exception queue. If most cases follow a known path, conventional automation may handle them efficiently while a smaller assistant supports the difficult remainder.
Measure cost per accepted outcome rather than per generated response. Include declined cases and work returned to staff. A low apparent cost can disappear when users must repeatedly verify or repair the result.
Consider latency in the product experience. A background investigation may tolerate several steps; an interactive checkout usually has a different time budget. Architecture should follow the user's task and the business deadline.
## Decide when the agent should ask a person
Escalation should follow a defined need for judgement or missing information. In the purchasing example, an unclear replacement specification may require a buyer's decision, while an unavailable lookup may simply require a later retry. These are different stopping reasons.
Return a concise package with the evidence gathered, unresolved question, and any proposal prepared. The person taking over should not have to repeat every lookup. Preserve source references and confirmed state so the handoff remains useful after a delay.
Avoid escalating every low-confidence phrase without considering the task. A draft wording preference may be easy for the user to edit, while uncertainty about the affected supplier demands clarification before action. The consequence should guide the review boundary.
Measure escalation quality during evaluation. Track whether the assigned person could resolve the case, whether necessary evidence was present, and whether the agent continued after it should have stopped. This makes human involvement an observable part of the design.
Keep ownership aligned with the decisions being made
Product owners should define the intended outcome and acceptable boundaries. Domain owners should define the business rules. Engineering should implement enforceable tools and state handling. Operations should own the procedures for exceptions and interruption.
One person may cover several roles in a small organisation, but the responsibilities still need to be explicit. Otherwise, prompt changes can quietly become policy changes and unresolved cases can fall between teams.
Review the design when new capabilities are proposed. Adding a tool that sends an external message changes the consequence of a run even if the user-facing feature name stays the same. Revisit approval, recovery, and evaluation before granting that access.
A bounded agent is maintained through these decisions as much as through code. Clear ownership gives the business a way to improve its behaviour deliberately instead of treating unexpected outcomes as mysterious properties of the model.
Expand autonomy only when evidence supports it
Start with observation or proposal generation where practical. Compare the assistant's output with real decisions and inspect disagreements. This reveals where the task boundary or tool contract needs improvement before execution authority increases.
When a narrow operation proves useful, define the conditions under which it can proceed and the cases that still require review. These conditions should be enforceable by the application and understandable to the process owner.
Treat model, prompt, and tool changes as changes to a maintained product. Rerun representative evaluations and observe the rollout. A new model may improve some tasks while altering behaviour at an important boundary.
For your next custom software feature, identify one place where fixed rules already work and one place where people must interpret uncertain information. Preserve the first in explicit application logic. Explore AI assistance for the second with bounded tools, inspectable proposals, and confirmed outcomes. That division gives adaptive behaviour a useful role without making the business rules depend on generated judgement.