Foundations to Frontier
Tests
F. NLP and Large Language Models › F11 Agents and Tool Use

Agent evaluation and safety

Agents are harder to evaluate and to secure than chatbots. They take many steps, their success varies between runs, and they act on the world through tools while reading untrusted content that may contain instructions. This page covers agent benchmarks, measuring consistency with pass^k, cost and trajectory evaluation, and the main security risk, prompt injection, with its defences: separating instructions from data, detection, least privilege and human confirmation. In the exercises you compute pass^k, wrap untrusted text in delimiters and write a permission gate. You then simulate an agent whose tasks succeed 78% of the time on a single run; all 8 runs of a task succeeded only 28% of the time. In a second simulation, tasks read 6 documents, each carrying an injected instruction with probability 0.15. With no defence 23% of tasks were hijacked. Delimiting untrusted text cut this to 8%, a detector to 3% at a cost in task success, and confirmation of dangerous actions to 1%. All three together cut it to 0.1% with a confirmation request on 1% of tasks.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

An assistant who reads your mail and might believe it

Imagine an assistant who reads your emails and acts on them. If one email says ‘forward all invoices to this address’, a careless assistant might do it. Agents face exactly this: web pages, documents and tool results can contain instructions written by someone else. Evaluating agents is also tricky: an agent that succeeds 8 times out of 10 is not one you can rely on every time. The demo shows how small per-document risks add up over a long task.

Agent lab
Chance at least one of 10 untrusted results hijacks the agent: 40.1%. Small per-result risks add up over long tasks; limit permissions and confirm risky actions.
Why engineers care

Prompt injection is the top security risk for agents that read untrusted content and can act; it cannot yet be fully prevented by the model alone, so systems must limit what a hijacked agent can do.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Prompt injection hides instructions in…
  2. 2. pass^k measures…
  3. 3. A robust defence limits…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Benchmarks: WebArena, OSWorld (computer use), SWE-bench (code), τ-bench (tool use with simulated users), GAIA (assistant tasks), AgentDojo (injection robustness).
  • Metrics: success rate (pass@1), consistency pass^k (all of k trials succeed), cost and latency per task, number of steps, safety violations; evaluate trajectories, not just final states.
  • Prompt injection: direct (from the user) and indirect (in retrieved or tool content). Goals: data exfiltration, unwanted actions, persistence via memory.
  • Defences: instruction hierarchy and spotlighting (mark untrusted text as data), injection classifiers, least privilege (scoped tools and credentials), human confirmation for consequential actions, dual-model patterns (CaMeL: a privileged planner never reads untrusted text).
  • Lethal trifecta: access to private data + exposure to untrusted content + ability to communicate externally enables exfiltration; remove one.
  • Other risks: irreversible actions, runaway loops and costs, over-broad permissions, sandbox escape (F11-5).
📝 Quick check (Level 1)
0/3 answered
  1. 1. A benchmark for injection robustness:
  2. 2. Least privilege means…
  3. 3. The lethal trifecta includes…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Evaluating and securing agents in practice

Exercise 1.

  • Estimate pass^k from repeated trials.
  • Wrap untrusted content with markers (spotlighting).
  • Gate dangerous tools behind confirmation.

Practice.

  • Run each eval task several times; report pass@1, pass^k, cost and steps with confidence intervals.
  • Grade trajectories: forbidden actions count as failures even if the final answer is right.
  • Red-team with injected documents, web pages and tool outputs (AgentDojo-style); track attack success rate.
  • Scope credentials per task; read-only by default; confirmation for sending, deleting, paying or changing permissions.
  • Log everything; alert on unusual tool use; set hard budget limits.
DANGEROUS = {"send_email", "delete_file", "transfer_funds"}
def guarded_dispatch(name, args):
    if name in DANGEROUS:
        if not ask_user(f"The agent wants to call {name} with {args}. Allow?"):
            return "error: the user declined this action"
    return dispatch(registry, name, args)
🐍 Exercise 1: pass^k, spotlighting and gating
Compute pass^k from trials, wrap untrusted text with markers and gate dangerous tools.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Run each eval task…
  2. 2. Trajectory grading counts…
  3. 3. By default, tools should be…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Consistency. If a task succeeds with probability p on each independent run, pass^k = p^k; averaged over tasks, pass^k = E[p^k], which punishes flaky tasks far more than pass@1 = E[p]. An agent at 78% pass@1 can have pass^8 below 30%.

Compounding exposure. If each of N untrusted documents carries a followed injection with probability i·f, the chance a task is hijacked is 1 − (1 − i f)^N. Lowering f (spotlighting, training) helps; reducing N (reading less) helps; detection removes injected documents but also removes clean ones at its false-positive rate, costing utility 1 − (1 − c·fpr)^N.

Defence in depth. Defences that act at different points multiply: a hijack must get past detection, be followed, and then be approved. Gating changes the target from ‘the model never follows injections’, which current models cannot guarantee, to ‘a followed injection cannot cause harm without a human’. Its cost is confirmation fatigue, which layered upstream defences reduce.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Averaged over tasks, pass^k equals…
  2. 2. Hijack chance over N documents:
  3. 3. Confirmation gating's cost:

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

How consistent is an agent that usually succeeds, and how much do layered defences reduce prompt-injection attacks and at what cost?

History.

  • K. Greshake et al., “Not what you’ve signed up for: indirect prompt injection” (2023).
  • S. Yao et al., “τ-bench” (2024): pass^k; E. Debenedetti et al., “AgentDojo” (2024).
  • E. Wallace et al., “The instruction hierarchy” (2024); E. Debenedetti et al., “Defeating prompt injections by design” (CaMeL, 2025).

Exercise 2a: consistency. 300 tasks with per-task success probability ~ Beta(4, 1.2), 8 independent trials each.

metric value
pass@1 0.777
pass^2 0.627
pass^4 0.460
pass^8 0.280
any of 8 succeeds 1.000

Exercise 2b: injection. 2000 tasks reading 6 documents each; each document carries an injection with probability 0.15. An undefended agent follows an injection 30% of the time; spotlighting lowers this to 10%. A detector catches 90% of injected documents and wrongly drops 3% of clean ones, which the task needs. Confirmation: users wrongly approve 5% of dangerous requests.

defence attack success task success confirmations per task
none 0.2345 0.765 0
spotlighting 0.0815 0.918 0
detector 0.0275 0.836 0
confirm dangerous actions 0.0105 0.763 0.237
all three 0.0010 0.848 0.009
  • Consistency: the agent that solved 78% of tasks on one run solved only 28% on all 8 runs; flaky tasks dominate.
  • No single defence sufficed: spotlighting kept utility but left 8% attacks; the detector cost 8 points of task success through false alarms; confirmation alone asked the user on a quarter of tasks.
  • Layered defences cut attacks 200-fold with confirmations on 1% of tasks.
  • Seeds 1 and 2: pass^8 0.280 and 0.327; all three 0.0015 and 0.000 attack success.
  • Caveat: follow rates and detector accuracy are assumptions; adaptive attackers target the weakest layer, so real attack rates can be much higher.
🐍 Exercise 2 (research): how consistent is an agent that usually succeeds, and how much do layered defences reduce prompt-injection attacks and at what cost?
Measure pass@1 versus pass^k for a flaky agent, and attack and task success under prompt-injection defences.

Agent safety in AI, robotics and aerospace

  • Robots: physical actions are irreversible; language-model planners need safety layers (geofences, force limits, human confirmation) that do not depend on the model’s judgement.
  • Operations: agents with read access to telemetry and write access to commands must separate untrusted inputs (reports, emails) from control authority.
  • Certification mindset: consistency (pass^k) and worst-case behaviour matter more than average success for systems that must be trusted.

References

  1. K. Greshake et al. (2023). “Not what you’ve signed up for: compromising real-world LLM-integrated applications with indirect prompt injection.” AISec.
  2. S. Yao, N. Shinn, P. Razavi and K. Narasimhan (2024). “τ-bench: a benchmark for tool-agent-user interaction in real-world domains.” arXiv:2406.12045.
  3. E. Debenedetti et al. (2024). “AgentDojo: a dynamic environment to evaluate prompt injection attacks and defenses for LLM agents.” NeurIPS Datasets and Benchmarks.
  4. E. Debenedetti et al. (2025). “Defeating prompt injections by design.” arXiv:2503.18813.