Architecture map and risk analysis

Study time
≈ 1.5 h (estimate)
Needs
L3-M01-L04
Updated
2026-11-04

Progress is saved in this browser only. No account, nothing is sent to a server.

Draft · reviewed by AI, not yet by a person. Content may change. English translation: AI-assisted, not human-reviewed.
On this page

Module: L3-M01 · Duration: ~90 min (estimate, including the independent exercise) · Previous: L04 · Next: L3-M02-L01 (module Tool Calling and Tool Contract Testing, not yet written)

1. Introduction

The previous four lessons split an agent into parts: model, tools, environment, loop, trace. This lesson puts them back together into the module's product: an agent architecture map with risk annotations. Here the map is data, not a drawing: nodes, edges, trust boundaries, loop limits, and a list of risks, each risk pointing at a node or an edge, with a score, a control and a test. Because it is data, a validator can check its internal consistency.

The starting point for risk is the OWASP project on LLM applications, where Excessive Agency has three root causes: excessive functionality, excessive permissions, excessive autonomy [R1]. This lesson turns those three root causes into fields of the map. What the lesson does not promise: the validator does not know whether the map matches the real system, and a "clean" map is not a safe system.

2. Learning objectives

  1. Describe an agent as data: nodes, edges, trust boundaries, loop limits. Read: §5.1; practice: §9.
  2. Attach risks to a node or an edge with a score, a control and a test. Practice: §8.2 part B, §9 (TODO 2).
  3. Map the three root causes of excessive agency onto the fields of the map. Read: §4.2.
  4. Run the validator and read each error code. Practice: §8.2 part C, §8.3 (lines 2 to 4), §9 (TODO 1).
  5. State what the validator does not know. Read: §6.1; practice: §8.3 (line 5).
  6. Turn risks that have no test yet into work for later lessons. Read: §6.2; practice: §8.3 (line 6).

3. Prerequisites and tools

  • L01 to L04 (the four parts of an agent, stop reasons, traces), L1-M04-L04 (prompt injection). The lab code is code-labs/l3-m01.
  • Separating the senses. The map here is a JSON data file, not a hand-drawn diagram (the diagram in §5.1 is only an illustration). A trust boundary is an edge joining a "trusted" node to an "untrusted" node in the map; this is the lab's definition. A control is something that reduces a risk (a quota, a person's approval); it differs from the loop guard (L02), which is only one control you might have. Declared-test coverage is the share of risks that declare a test; it differs from the coverage of a confidence interval (L2-M01-L04) and the coverage of a dataset (L2-M02-L02). The risk score is the product of severity and likelihood, each from 1 to 3; this scale is the lab's choice, not the standard of any source. A tool's permission is one of read, write, execute, network.

4. Concept explanation

4.1 What the map contains

Each node has an id, a type (human, model, tool, environment, orchestrator, observability, external_content) and a trust (trusted or untrusted). A tool node also has a permission, and if the permission is anything other than read it has an approval (human, or, only for the write permission, none_sandbox_only together with sandboxed: true, a declaration by the person drawing the map that the validator cannot check). The side_effect field in the data is only an annotation; the validator does not use it. The orchestrator node is the loop (application code) of L02, not the central model of the orchestrator-workers pattern [R2]. Model and tool nodes have an observed_by pointing to an observability node (L04). Each edge has from, to, data, and a mitigation if it starts from an untrusted node. stop_conditions records max_steps and budget (L02). Each risk has an id, a target (a node id, or edge:a->b), a category, a severity, a likelihood, controls and a test.

4.2 The three root causes of excessive agency, as fields

OWASP names three root causes: excessive functionality, excessive permissions and excessive autonomy; its example of excessive functionality is an extension with a function not needed for the intended operation, and of excessive autonomy an extension that deletes documents without asking the user [R1]. The mitigations the page proposes include reducing the number of extensions, reducing the functionality of each extension, avoiding open-ended extensions (such as "run a shell command" or "fetch a URL") in favor of narrower ones, reducing permissions, running in the user's context, and requiring a person to approve high-impact actions [R1]. The "Building effective agents" article also mentions that an agent can pause for human feedback at checkpoints, and advises thorough testing in a sandbox environment with suitable guardrails [R2].

The mapping onto the map: excessive functionality shows up when you count the tool nodes and ask about each one whether it is needed; excessive permissions is the permission field and the environment node the tool touches; excessive autonomy is the approval field: a tool that writes or opens the network without a person's approval or without being locked in a sandbox is a validator error code. This mapping is this lesson's way of reading, not a standard from [R1].

4.3 Where a risk attaches

A risk attaches to a node (this tool writes too much) or an edge (content from a lookup table goes into a tool call). The lab has eight categories: excessive_agency, direct_prompt_injection, indirect_prompt_injection, unbounded_loop, cost_runaway, sensitive_data_in_logs, tool_misuse_bad_arguments, silent_failure. Only the first comes from the page [R1] that was read; direct and indirect injection correspond to the LLM01 entry (L1-M04-L04); the rest are named by the lab. The score is severity × likelihood; from 6 up, at least one control is mandatory (HIGH_SCORE = 6, the lab's choice). Scoring is a person's judgment: two people may give different scores and both be reasonable.

5. Technical deep dive

5.1 The example map: HocVui Assistant

data/arch_example.json describes the fictional product with 10 nodes, 15 edges and 8 risks. There are four tool nodes (calc, lookup, notes_read read-only; notes_add writes, none_sandbox_only and sandboxed), one untrusted external-content node (kb_content, feeding lookup), the user as an untrusted node too, a sandbox directory and a trace store. stop_conditions are 8 steps and 40 cu.

Architecture diagram of HocVui Assistant (fictional): the user (untrusted) sends a task to the orchestrator; the orchestrator exchanges messages both ways with the simulated model and calls four tools, calc, lookup, notes_add (write, sandboxed) and notes_read; the kb_content (untrusted) entry text flows into lookup; notes_add and notes_read use the sandbox folder; the orchestrator sends the redacted trace and logs to the trace store.
Diagram: The example map: HocVui Assistant

The tools return results to the orchestrator (not drawn, to keep the diagram tidy); those return edges are what create the model-tool cycle the validator uses to require loop limits.

5.2 The validator's rules

validate_map returns a sorted list of CODE:location; empty means no rule fired. The groups:

  • Nodes and edges: DUPLICATE_ID, BAD_NODE_TYPE, BAD_TRUST, EXTERNAL_CONTENT_TRUSTED (an external-content node must be untrusted), EDGE_UNKNOWN_NODE, ISOLATED_NODE; malformed input returns MALFORMED_MAP.
  • Tools: TOOL_NO_PERMISSION; TOOL_WRITE_NO_APPROVAL (a permission other than read without approval: human; none_sandbox_only is accepted only for the write permission, together with sandboxed being exactly true); SIDE_EFFECT_TOOL_NO_RISK (a write, execute or network tool with no risk pointing at it).
  • Loop: NO_LOOP_BOUNDS when there is a cycle through a model node and a tool node and max_steps or budget is not an integer of 1 or more (the float 2.0 is rejected).
  • Trust: UNTRUSTED_EDGE_NO_MITIGATION (an edge leaving an untrusted node without a non-empty mitigation); BOUNDARY_EDGE_NO_RISK (an edge between a trusted and an untrusted node with no risk pointing at edge:a->b).
  • Observation: NOT_OBSERVED (model and tool nodes need an observed_by pointing at a node of kind observability, not any node).
  • Risks: RISK_BAD_TARGET, RISK_BAD_CATEGORY, RISK_BAD_SCORE (only the integers 1 to 3), RISK_NO_TEST, HIGH_RISK_NO_CONTROL, DUPLICATE_RISK_ID.

risk_table sorts risks by score descending and then by id; test_coverage is the fraction of risks whose test is a real test identifier (non-empty, not starting with untested), or None when there are no risks.

5.3 Reading the example's risk table

Three risks reach a score of 6: R2 (direct injection through the user edge into the orchestrator), R3 (indirect injection through the kb_content edge into lookup) and R4 (an unbounded loop at the orchestrator); each has a control. test_coverage is 5/8: three risks have no test yet (R2, R3, and R8 about silent failure) and carry an untested: note with a reason. The figure 5/8 counts only declared tests, it does not run them. Five of the declared tests are in this very lab; the test test_the_shipped_example_map_is_clean_and_its_declared_tests_exist checks that the declared test function names really exist in the file, and test_the_example_map_lists_exactly_the_tools_of_the_lab_with_their_permissions checks that the tool nodes match TOOL_SPECS. The first draft of this example map itself was missing the notes_read node; the second test caught it.

6. The QA perspective

6.1 What the validator does not know

  • Whether the map matches the real system: it only checks internal consistency; the tools-match-code test above is a small example of how to guard against drift.
  • Whether the list of risks is complete. When you add a web search tool with network permission and approval: human and a risk with a control, the validator goes quiet (§8.3, line 5), even if you forgot to add the untrusted external-content node that the tool brings in; the map is still "clean".
  • Whether the controls and tests exist and work: it accepts any non-empty controls list and any non-empty test string (the test test_the_validator_cannot_tell_whether_a_control_or_test_is_real pins that).
  • Whether the scores are reasonable, and whether the trust field is honest: it is set by the person drawing the map; only the external-content node is forced to be untrusted, and if a user or tool node is wrongly set to trusted, the matching edge is no longer a boundary.

6.2 Turning the map into a test plan

Each risk has a test: either a specific test identifier, or untested: with a reason. The untested: entries are work for later lessons: direct and indirect injection need adversarial case sets (the tool contract module L3-M02 and the safety module L3-M07, which exist only as plans in the roadmap so far), and silent failure needs an end-state oracle for every path (L3-M03). Keep the map next to the code, in the same repository and the same review process; whenever a tool is added, update the map in the same change.

6.3 Three common traps

Drawing the map once and letting it drift away from the code; scoring everything high "to be safe" (then the table distinguishes nothing); believing 5/8 is "62.5% safe", when it only says 5 of 8 risks have declared a test.

7. Real-world scenarios

Scenario 1 (fictional): "Adding a web search tool". The HocVui team wants the assistant to look things up on the web. When a web_search node with network permission is added, the validator returns SIDE_EFFECT_TOOL_NO_RISK and TOOL_WRITE_NO_APPROVAL; after adding approval: human only the missing-risk error is left; after adding a high-score risk without a control it gets HIGH_RISK_NO_CONTROL (§8.3). QA adds what the validator does not see: an untrusted external-content node and its edge into the orchestrator, together with an indirect injection risk.

Scenario 2 (fictional): "A clean map but the tests do not exist". A team member fills every risk with controls: ["magic"] and test: "tests/nowhere.py::test_nothing". The validator returns empty; test_coverage is 1. Only the test that checks that the function name really exists in the file would catch it. Lesson: treat declared-test coverage as a claim to be checked, not a measurement.

8. Hands-on tutorial

8.1 Setup

cd academy-content/code-labs/l3-m01
python3 -m venv .venv && source .venv/bin/activate     # Windows: .venv\Scripts\activate
python -m pip install -r requirements.txt
python -m pytest            # 79 passed

8.2 Run the demo

python -m lab.demo l05

Output (copied from a real run on Python 3.14.6 and 3.12.14, 2026-11-04; the two versions are identical). The map, tools and risks are fictional:

A. example map: HocVui Assistant (fictional) - nodes 10 edges 15 risks 8
   validate_map: []  declared-test coverage: 5/8
B. risk table
   R2 score=6 direct_prompt_injection -> edge:user->orchestrator
   R3 score=6 indirect_prompt_injection -> edge:kb_content->lookup
   R4 score=6 unbounded_loop -> orchestrator
   R5 score=4 cost_runaway -> model
   R6 score=4 sensitive_data_in_logs -> trace_store
   R8 score=4 silent_failure -> model
   R7 score=3 tool_misuse_bad_arguments -> calc
   R1 score=2 excessive_agency -> notes_add
C. break the map one rule at a time
   tool not observed: ['NOT_OBSERVED:calc']
   no max_steps: ['NO_LOOP_BOUNDS:loop']
   write tool without approval: ['TOOL_WRITE_NO_APPROVAL:notes_add']
   untrusted edge without mitigation: ['UNTRUSTED_EDGE_NO_MITIGATION:user->orchestrator']
   boundary edge without risk: ['BOUNDARY_EDGE_NO_RISK:kb_content->lookup']
   high risk without control: ['HIGH_RISK_NO_CONTROL:R4']

Reading the output: part A is the size of the map, the validator result (empty) and the declared-test coverage. Part B sorts the eight risks by score (R2, R3, R4 all at 6, ordered by id). Part C breaks the map one rule at a time and gives exactly one error code each time.

8.3 Try it yourself

Save it as try_l05.py in the lab's root directory (next to lab/, not inside lab/), run python try_l05.py, then delete the file:

import copy

from lab import data
from lab.archmap import risk_table, test_coverage, validate_map

m = data.load_json("arch_example.json")
print(validate_map(m), test_coverage(m))
web = {"id": "web_search", "type": "tool", "trust": "trusted", "permission": "network", "observed_by": "trace_store"}
m2 = copy.deepcopy(m)
m2["nodes"].append(web)
m2["edges"] += [{"from": "orchestrator", "to": "web_search", "data": "tool call"}, {"from": "web_search", "to": "orchestrator", "data": "result"}]
print(validate_map(m2))
m2["nodes"][-1]["approval"] = "human"
print(validate_map(m2))
m2["risks"].append({"id": "R9", "target": "web_search", "category": "excessive_agency", "severity": 3, "likelihood": 3, "controls": [], "test": "untested: later"})
print(validate_map(m2), [r["id"] for r in risk_table(m2)[:3]], test_coverage(m2))
m2["risks"][-1]["controls"] = ["a person approves every search"]
print(validate_map(m2))
print([r["id"] for r in m["risks"] if r["test"].startswith("untested")])

Output (Python 3.14.6 and 3.12.14 identical):

[] 5/8
['SIDE_EFFECT_TOOL_NO_RISK:web_search', 'TOOL_WRITE_NO_APPROVAL:web_search']
['SIDE_EFFECT_TOOL_NO_RISK:web_search']
['HIGH_RISK_NO_CONTROL:R9'] ['R9', 'R2', 'R3'] 5/9
[]
['R2', 'R3', 'R8']

Reading it: line 1: the original map is clean, coverage 5/8. Line 2: add a network tool with nothing attached: two errors (missing risk and missing approval). Line 3: add approval: human, a risk is still missing. Line 4: add a risk with score 9 (3 x 3) and no control: HIGH_RISK_NO_CONTROL:R9; R9 tops the table, and coverage drops to 5/9 because the new risk has no test yet. Line 5: add a control to R9, and the validator returns empty. Line 6: the original map's risks that declare untested: (R2, R3, R8), that is, work still owed to later lessons. No line complains about the missing untrusted external-content node: that is the blind spot of §6.1.

8.4 Run the lesson's tests

python -m pytest tests/test_l05_archmap.py -v

Result: 11 passed. Read test_the_shipped_example_map_is_clean_and_its_declared_tests_exist, test_tool_rules, test_loop_bounds_are_required_only_when_there_is_a_loop and test_the_validator_cannot_tell_whether_a_control_or_test_is_real. The tests run on the lab's JSON data in memory and read test files in the repository; no test writes a file.

8.5 Troubleshooting

Symptom Cause Fix
RISK_BAD_SCORE for a score you think is valid The value is not an integer from 1 to 3 (True, 2.0, 4 are all rejected) Use the integer 1, 2 or 3
NOT_OBSERVED even though observed_by is present The value points at a node that is not an observability node, or at the wrong id Point at a real node of kind observability
BOUNDARY_EDGE_NO_RISK even though a risk exists The target is not in the form edge:from->to or has the direction reversed Write edge: in the same direction as the edge

9. Independent exercise

Problem: Find the nodes that are not observed and write risk annotations for a map that has no risks yet.

Requirements: complete exercises/test_l05_archmap.py:

  1. TODO 1: my_unobserved(m): the sorted ids of the model and tool nodes that are not observed (observed_by must point at a node of kind observability).
  2. TODO 2: RISKS: a list of risks (id, target, category, severity, likelihood, controls, test) such that, after the nodes from TODO 1 are fixed (the test fixes them for you), validate_map returns empty and the declared-test coverage is not below 1/2.

Test data: exercises/ex_arch.json (a map with no risks, plus one more tool that sends mail and needs a person's approval).

Deliverable: the function and list above, in the file exercises/test_l05_archmap.py itself. The list of risks is the map's risk annotations.

Acceptance criteria: python -m pytest exercises/test_l05_archmap.py passes (2 tests), compared with lab.archmap. The tests do not check whether the risks you choose are complete and reasonable, do not check whether the scores are fair, and do not check whether the tests you declare exist.

Hints: TODO 2: run validate_map on the fixed map, read each code, and add exactly the risk the code asks for (which tool needs a risk, which edge crosses a trust boundary); a score of 6 or more needs a control; every risk needs a test string, including untested: with a reason. Think about the 1/2 coverage before declaring too many untested:.

10. Knowledge check

0/18 done · Results are kept in this browser only.

P02 · True or false

On map K, change the trust of the node user from untrusted to trusted. validate_map reports an error because a user cannot be trustworthy.

P04 · Select all that apply

Edit map K in four places: (a) add a tool node web_search (permission network, approval human, observed_by trace_log) with two edges to orch, and no risk points to it yet; (b) delete the observed_by of mail_send; (c) delete max_steps from stop_conditions; (d) delete the mitigation of the edge inbox_text->inbox_read. Select every code that validate_map returns.

P05 · Put in order

Put the steps of building and reviewing an agent architecture map in order, from the first to the last.

  1. Draw the data edges between the nodes; an edge leaving an untrusted node gets a mitigation
  2. Attach risks to nodes or edges, each risk with a score, a control and a test
  3. Read risk_table and test_coverage, and turn the untested: items into work for later lessons
  4. Record stop_conditions (max_steps and budget) for the loop
  5. List the nodes (human, model, tool, environment, orchestrator, observability, external_content) and set trust for each node
  6. Keep the map next to the code and edit it in the same change whenever a tool is added
  7. Run validate_map and fix each error code

P06 · Match

Match each concept with where it sits in the map or how it is used.

P07 · Spot the bug

A team member fills in risk K1 for map K. After adding it, validate_map reports BOUNDARY_EDGE_NO_RISK even though a risk for that edge exists. Find the bug.

{"id": "K1", "target": "edge:inbox_read->inbox_text", "category": "indirect_prompt_injection",
 "severity": 3, "likelihood": 3, "controls": ["text is data"], "test": "untested: no hostile messages yet"}

P08 · Short answer

A team member's report: "Map K reaches test_coverage 2/3, meaning it is 66.7% safe." State at least three things that are wrong or missing in this sentence, and how the untested: items should be handled.

P09 · Essay

Write 5-8 sentences: the team wants to add to map K a tool sms_send (permission network) that messages parents, and an external-content source parent_reply (the parent's reply) flowing into inbox_read. Adding only the node sms_send with two edges to orch makes validate_map return SIDE_EFFECT_TOOL_NO_RISK:sms_send; adding a risk of score 9 with no control returns HIGH_RISK_NO_CONTROL:K7; adding a control returns []. State what else must be added to the map beyond what the validator already demands, and why [] is not enough.

P11 · Recall

Lesson: L1-M04-L04

According to L1-M04-L04 §4.3, when writing tests for a prompt injection risk (like K1 and K4 on map K), what should be asserted?

P12 · Recall

Lesson: L3-M01-L02

Risk K5 (unbounded_loop at orch) lists the controls max_steps and loop guard. According to L3-M01-L02, which control blocks a tool call that repeats exactly the same key when the sandbox state does not change?

P13 · Recall

Lesson: L3-M01-L04

Risk K6 (sensitive_data_in_logs at trace_log) lists the control "redaction". According to L3-M01-L04, which statement must be recorded in K6's note as a blind spot of that control?

P14 · Multiple choice

Five risks (simulated) on a different map with (severity, likelihood): A (3, 1), B (2, 3), C (1, 3), D (3, 2), E (2, 3). risk_table sorts by descending score and then by id. Which id order is correct, and which risks must have at least one control (the lab's threshold is 6)?

P15 · Select all that apply

Select everything that validate_map does not know or does not check.

P16 · True or false

The score threshold 6, from which every risk must have at least one control, is a standard set by OWASP for every agent risk map.

P17 · Match

Match each validator code with the edit that causes it, each edit applied separately to a clean map K.

P18 · Multiple choice

On map K, add risk K7 (silent_failure, pointing to inbox_read, severity 1, likelihood 2, one control) with test equal to tests/nowhere.py::test_y (this file does not exist). What do validate_map and test_coverage return?

11. Summary

  • Concepts: an architecture map is data (nodes, edges, trust, loop limits, risks); the three root causes of excessive agency become the permission and approval fields and the list of tools [R1]; risk scores 1 to 9 on the lab's scale.
  • Skills: reading the validator's error codes, attaching risks to nodes and edges, turning untested: entries into work for later lessons.
  • Traps: treating a clean map as a safe system; trusting declared-test coverage; letting the map drift away from the code; missing the external-content node when adding a tool.
  • You can now: take an agent architecture drawing, turn it into data, run the validator, and say which risks still have no test, together with what the validator does not say.

12. References

ID Title Publisher URL Accessed Relevance
R1 LLM06:2025 Excessive Agency (OWASP Gen AI Security Project) OWASP https://genai.owasp.org/llmrisk/llm062025-excessive-agency/ 2026-11-04 Read the page text (definition, three root causes, examples, mitigations); the attack scenarios were not read
R2 Building effective agents Anthropic https://www.anthropic.com/engineering/building-effective-agents (redirects to /research/building-effective-agents) 2026-11-04 Read the page text (the passage on human checkpoints, testing in a sandbox); the two appendices were not read in full

Key terms (English ↔ Vietnamese)

English Tiếng Việt
Agent architecture map Bản đồ kiến trúc agent: nút, cạnh, ranh giới tin cậy, giới hạn vòng lặp, rủi ro, ở dạng dữ liệu
Risk annotation Ghi chú rủi ro: rủi ro gắn vào một nút hoặc cạnh của bản đồ
Trust boundary Ranh giới tin cậy: cạnh nối nút trusted với nút untrusted
Control Biện pháp kiểm soát: việc làm giảm một rủi ro
Risk score Điểm rủi ro: mức nghiêm trọng nhân khả năng xảy ra, thang 1 đến 9 của lab
Declared test Test đã khai: mã test ghi trong bản đồ; chưa chắc tồn tại hay chạy
Approval Duyệt: điều kiện người hoặc sandbox cho phép tool có tác động chạy