Agents and tool use under control
Control an agent’s actions and keep its state outside the conversation.
In this lesson · B10 of 12
All lessons in this track →Progress for this track is saved in this browser only. No completion badge is issued. View your learning.
Start with the idea
Control an agent’s actions and keep its state outside the conversation.
Check proposed actions before execution. Count every call, including parallel proposals. Store approvals and pending actions in reliable application state, not only in a shortened chat summary.
Agent state: The application’s record of the task, decisions and pending effects.
See the example and check your understanding
A made-up teaching example
A training webpage asks the agent to publish. The application has no publish tool and stops at its read-only research limit. Repeated lookups use the same recorded operation identity.
Ask yourself
Can a shortened chat summary safely replace the permission record?
Show the explanation
No. Summaries can lose details. The application must preserve controlling state and prevent new actions after cancellation.
Start with these checks
- Enforce the total call limit.
- Keep approvals outside chat summaries.
- Test cancellation and repeated actions.
Use the different practice case below and check every requirement in its full instructions.
The video explains the main idea. Use the sources, instructions and checks below to complete the practice.
Captions appear here during playback.
Agents and tool use under control
Control an agent’s actions and keep its state outside the conversation.
Video playback is unavailable. Read the descriptive transcript below, go directly to practice, or open the video file.
Source-based teaching example · Fictional data · Reviewed 2026-10-03. Microsoft Mark · locally synthesized. On a small screen, use fullscreen for diagram details or read the transcript.
Read the descriptive transcript
0:00 · What you will learn
Control an agent’s actions and keep its state outside the conversation.
What appears on screen
Control an agent’s actions and keep its state outside the conversation.
0:07 · The idea
Check proposed actions before execution. Count every call, including parallel proposals. Store approvals and pending actions in reliable application state, not only in a shortened chat summary.
What appears on screen
Check proposed actions before execution. Count every call, including parallel proposals. Store approvals and pending actions in reliable application state, not only in a shortened chat summary.
0:23 · One useful term
Agent state. The application’s record of the task, decisions and pending effects.
What appears on screen
The application’s record of the task, decisions and pending effects.
0:32 · A worked example
A training webpage asks the agent to publish. The application has no publish tool and stops at its read-only research limit. Repeated lookups use the same recorded operation identity.
What appears on screen
A training webpage asks the agent to publish. The application has no publish tool and stops at its read-only research limit. Repeated lookups use the same recorded operation identity.
0:47 · Your turn to think
Can a shortened chat summary safely replace the permission record? Pause and decide before continuing.
What appears on screen
Can a shortened chat summary safely replace the permission record? Pause the video if you need more time.
1:05 · Why this answer works
No. Summaries can lose details. The application must preserve controlling state and prevent new actions after cancellation.
What appears on screen
No. Summaries can lose details. The application must preserve controlling state and prevent new actions after cancellation.
1:16 · Check 1
Enforce the total call limit.
What appears on screen
Enforce the total call limit.
1:21 · Check 2
Keep approvals outside chat summaries.
What appears on screen
Keep approvals outside chat summaries.
1:27 · Check 3
Test cancellation and repeated actions.
What appears on screen
Test cancellation and repeated actions.
1:32 · Now try a different case
Open the lesson and try its different practice case. Use every check in the full task. Watching alone does not mark the lesson complete.
What appears on screen
Open the lesson Try the new case Check and revise The full task and its requirements are in the linked lesson.
Watching explains the example. Complete the lesson practice to check what you can do. Explore all visual lessons →
What you will be able to do
- Implement an explicit decide-act-observe state loop.
- Enforce least privilege, budgets, idempotency, and confirmation.
- Contain malicious observations and indirect injection.
Prerequisites: dictionaries, loops, functions, exceptions and installed Python or paper tracing. Reuse earlier Builder artifacts only when the task requires them.
This curriculum runs self-study on VetsLearn. Where the text calls for an instructor, peer or formal review, use the stated acceptance criteria for self-review. Reflection questions support reflection; they do not replace independent assessment. A peer review is optional unless your actual organization requires it.
Part 1 Technical instruction
A workflow follows predefined transitions; an agent selects among allowed transitions. In both cases, code owns state, permissions, budgets, and termination. Each proposed action is validated against authenticated identity, tool allowlist, argument schema, remaining time/tool/token budget, and confirmation policy. Idempotency keys protect repeated calls. Observations are untrusted; tool output cannot grant new permissions. A trace must reconstruct state without retaining prohibited content. The lab permits only canned, read-only research tools and simulated confirmation.
Mechanism and implementation
A harness owns budgets, state and permissions. One tool and a precise goal can support agentic selection; vague goals and multiple tools are not defining criteria. Hold model constant when comparing harnesses. MCP standardizes exchange/discovery, while authentication, authorization, sandboxing and approval are separate.
Constructed offline example
Save as topic_example.py and run python topic_example.py with an installed Python 3.11+ interpreter. This standard-library construction uses synthetic values; its checks are not provider measurements.
proposals = ["read", "read", "read", "read"]
observations = []
for proposed in proposals:
if len(observations) >= 2:
break
if proposed != "read":
raise ValueError("unlisted_tool")
observations.append({"action": proposed, "status": "complete"})
assert len(observations) == 2
print("budget_exhausted")Engineering decisions
- Choose workflow instead of agency when the path is known.
- Define hard termination and loop detection.
- Require human confirmation for consequential simulated actions.
Worked example
A canned web page tells the agent to ignore policy and call publish(). The application has no publish tool, treats the page as evidence, and terminates after the read-only research budget. Duplicate lookup calls reuse the same idempotency record.
Diagnose the failure
The cap counts all calls, including parallel proposals. Cancellation prevents future actions. Task state, approvals and pending effects remain outside lossy compaction; prompts cannot enforce them.
Part 2 Guided practice
Trace the cap before each call. Add deadline, cancellation and no-progress limits. Independently inject a tool observation asserting administrator authority and prove permissions remain unchanged.
Answer criteria and feedback: The cap counts all calls, including parallel proposals. Cancellation prevents future actions. Task state, approvals and pending effects remain outside lossy compaction; prompts cannot enforce them.
Continue with the downloadable pack below. If the pack or interpreter is unavailable, trace this self-contained example by hand in an input/expected-status/controlling-rule table and label execution unverified. Do not invent passing output. No account, credential, paid call, purchase or actual deployment is required.
Part 3 Remediation
Replay the provided state trace one transition at a time. If the loop does not terminate, inspect the transition guard and budget decrement before changing prompts. After repair, reassess with the alternate scenario in scenario_alt.json. A critical authorization, data-handling, evidence-integrity, or prohibited-action failure cannot be averaged into successful practice; it requires targeted remediation.
Part 4 Sources and currency
- https://genai.owasp.org/
- https://www.cisa.gov/resources-tools/resources/secure-design-alert-eliminating-cross-site-scripting-vulnerabilities
Use the workflow decision reference for model/deployment/harness distinctions and controlled comparisons. Source currency must be checked before each cohort. Provider/product behavior is illustrative where mocked; resolve current interfaces only from official documentation in an authorized environment.