An agent that can call write operations on your Order Service needs the same guardrails as any other client with write access. Classify every tool as read-only or state-changing, and let only the state-changing ones pass through an approval gate. In the example below, the agent may call getOrder freely, but cancelOrder pauses until a human or a policy engine approves the call. The gate must live in your Java code and not in the prompt, because a prompt instruction is only a suggestion, while a code check is a guarantee. This keeps the blast radius small, and you get an audit trail of every approved action for free.
// Context: an agent talks to the Order Service only through these tools.public interface OrderTool { String name(); boolean changesState(); // read-only vs. state-changing String execute(String orderId);}public class ApprovalGate { private final Approver approver; // human UI or policy engine public ApprovalGate(Approver approver) { this.approver = approver; } public String call(OrderTool tool, String orderId) { if (tool.changesState() && !approver.approves(tool.name(), orderId)) { return "DENIED: " + tool.name() + " on order " + orderId; } return tool.execute(orderId); // getOrder runs directly, cancelOrder only after approval }}

Schreibe einen Kommentar