What you need to know
Learn to separate model proposals from authorized actions, bind approvals to exact arguments and handle retries using a runnable in-memory tool example, solved exercises and a sandbox project.
An agent becomes consequential when a proposed action changes something outside the model. The important skill is not merely selecting a tool name. It is defining the action contract, enforcing permission, recognizing an uncertain result and recovering without repeating an unintended side effect. Begin in a sandbox where failures are safe and observable.
This guide uses an original in-memory record-closure tool. No real jobs are changed, no messages are sent and no model API is called. The example illustrates approval binding and repeated-operation handling, not a production transaction system or a complete security implementation. Google's function-calling reference provides background on model tool requests; application controls remain your responsibility.
Before you start
Understand dictionaries, exceptions and the difference between reading data and mutating state. Know why a request timeout does not establish whether a remote action succeeded. Use fictional records for the exercise; do not connect it to actual publishing, payments, email or account management while testing basic control flow.
A fixed workflow may be the correct starting design. If every task always follows the same validated steps, introducing an agent can add uncertainty without benefit. Choose autonomous tool selection only when you can explain what useful decision it makes and how that decision will be evaluated.
Learning sequence
- Define a narrow tool contract with explicit arguments, targets, permission requirements and outcomes.
- Separate a model's proposed action from the application's authorization decision. A tool suggestion is not permission.
- Bind human approval to the exact target, action and arguments, with appropriate validity and revocation rules.
- Save operation identity and state, then test repeat requests, conflicts and crashes around side effects.
- Add step and time budgets, cancellation and trajectory evaluation. Inspect what happened, not only the final message shown to the user.
Keep untrusted observations separate from control instructions. A website returned by a tool can contain malicious text; it cannot grant access to another record or authorize an additional action. A system prompt helps describe intent but cannot replace backend access enforcement.
Worked example
The action is a tuple containing the action name and target ID. The trusted caller supplies allowed target IDs and an approval matching that tuple. A completed operation is remembered under its operation ID. Reusing that ID with a different proposal is a conflict rather than an opportunity to execute again.
def close_record(proposal, approval, operation_id, allowed_ids, records, completed):
if not isinstance(proposal, tuple) or len(proposal) != 2:
raise ValueError("invalid proposal")
action, target = proposal
if action != "close" or target not in allowed_ids:
raise PermissionError("action not authorized")
if approval != proposal:
raise PermissionError("approval does not match action")
if not isinstance(operation_id, str) or not operation_id.strip():
raise ValueError("missing operation identity")
if operation_id in completed:
prior_proposal, result = completed[operation_id]
if prior_proposal != proposal:
raise ValueError("operation identity conflict")
return dict(result)
if target not in records:
raise ValueError("unknown target")
records[target] = "closed"
result = {"target": target, "status": "closed"}
completed[operation_id] = (proposal, dict(result))
return result
records = {"job-a": "open", "job-b": "open"}
completed = {}
proposal = ("close", "job-a")
first = close_record(proposal, proposal, "op-1", {"job-a"}, records, completed)
again = close_record(proposal, proposal, "op-1", {"job-a"}, records, completed)
assert first == again
assert len(completed) == 1
assert records == {"job-a": "closed", "job-b": "open"}
try:
close_record(("close", "job-b"), proposal, "op-2", {"job-b"}, records, completed)
except PermissionError:
pass
else:
raise AssertionError("changed proposal should need matching approval")
print("one recorded operation; changed proposal rejected")
The return values are copied so a caller changing the returned dictionary does not alter the saved result. Permission and approval are checked before either a new action or a repeated-result response. The example does not create an approval service; its supplied arguments stand in for trusted application decisions. Never let a model populate allowed_ids or manufacture the approved tuple.
The largest limitation is durability. A crash between updating records and saving completed would leave an uncertain outcome, and two concurrent calls could race. A real database-backed version needs an appropriate atomic boundary, uniqueness enforcement and a clear reconciliation strategy. Do not claim that this dictionary implementation provides exactly-once effects across processes or devices.
For approvals in a real product, bind additional relevant fields such as requester, expiry and record version. If a record changes after review, decide whether approval must be renewed. Cancellation should stop scheduling new work and reconcile in-flight actions; it does not automatically undo a write already committed elsewhere.
Exercises and solutions
Exercise 1: Change the approved target
A user approved closing job-a. The model later proposes closing job-b with the same approval. Should execution continue because both records are visible to the user?
Solution: No. Read access and general action permission are not approval for this specific proposal. Bind approval to the target and arguments and request fresh approval when they change. The example rejects the mismatch even if job-b is present in the permitted target set.
Exercise 2: Retry after an unknown outcome
A remote tool commits a write, but its response is lost. Can the agent assume failure and call it again with a new operation ID?
Solution: That can repeat the effect. Reconcile using a durable identity recognized by the receiver, or query the existing operation result. Reuse identity only under the receiving service's documented idempotency contract. If you cannot establish the outcome safely, mark the action uncertain for reconciliation rather than declaring success or blindly duplicating it.
Exercise 3: Stop a non-progressing agent
An agent keeps searching two equivalent phrases and gains no new evidence. What should the runner record when it stops?
Solution: Record the exhausted step or time budget, repeated actions, last useful observation and the unresolved task. Do not report budget exhaustion as task completion. Let a person decide whether to revise or resume, and ensure new attempts cannot reset the budget indefinitely without visibility.
Mini-project
Build a fictional administrative assistant that can propose changes but only execute one narrow approved tool. Use an in-memory store first, then document a durable-store design separately. Include scenarios for an unauthorized target, changed approval, repeated operation, conflicting operation identity, cancellation and a tool result containing hostile instructions.
Deliver a typed proposal format, a transition diagram, a test fixture and a readable action trace. Show the requested action, application decision, observed outcome and final task status as separate facts. Any durable or concurrent design you have not implemented must be labelled a proposal, not a tested guarantee.
Completion criteria: no unauthorized target is mutated; changed proposals do not inherit approval; a repeat of the same completed operation returns its result; conflicting reuse is rejected; and every non-success outcome has an explicit explanation. Describe the crash window and test what the user sees when an action is still uncertain.
Common mistakes
- Treating a model's tool selection as authorization.
- Approving a broad goal once and reusing it for different concrete actions.
- Assuming checkpoints eliminate every duplicate side effect.
- Retrying a mutating tool with a fresh identity after every timeout.
- Reporting cancellation as proof that nothing happened.
- Adding several agents without comparing them to a simpler controlled workflow.
Self-assessment
Can you identify the trusted boundary, show exactly what approval covers and explain the unknown-outcome state? Can you point to a test where the final answer looks reasonable but the tool trajectory is unacceptable? These are practical agent-engineering skills even when your system uses only one model and one tool.
Connect this skill to roles and jobs
Read the AI Agent Engineer career guide, practise AI Agent Engineer interview questions and explore AI-agent jobs. Check the actual action and safety responsibilities in each listing. Return to the AI Skills overview for the broader foundation.
Methodology
Editorial synthesis of cited sourcesAI-assisted original educational material. Explanations, code, fictional fixtures, exercise solutions and mini-project acceptance criteria were prepared for this site, not reproduced from the references. Official Google references support background concepts, not an endorsement or validation of these projects. Runnable Python examples use the standard library; the SQL fixture is checked with SQLite and is not a BigQuery deployment tutorial. Samples demonstrate bounded concepts, not production-ready systems. Measurements and scenario values are synthetic, not benchmark results. Mini-projects are suggested exercises, not claims of completed deployments. No paid model calls are needed to run the examples. Related jobs use a skill or specialization filter and may include adjacent roles. References checked 17 October 2026. No hiring guarantees or unmeasured demand rankings are implied.
Read our editorial and research policy →Sources
- Function calling
Google AI for Developers · Checked 17 October 2026