Skip to main content

60 Advanced Exercises

#ProblemExpected outcomeHintRelated chapters
121Classify five AI flows as model call, workflow, graph, agent, or multi-agent.Precise control-pattern reasoning.Who chooses the next step?156–157
122Implement a bounded ReAct loop around two safe read tools.Max steps, tool validation, terminal answer.Model proposes; executor owns calls.158
123Add repeated-tool-call detection to the loop.Loop exits/escalates on no progress.Hash normalized call name+args.158, 170
124Build a planner/executor workflow for travel research without booking.Typed plan, observations, bounded revision.Keep actions read-only.159
125Turn a fixed planner flow into deterministic code and compare.Evidence about when planning was unnecessary.Measure quality/cost/latency.157, 159
126Build a router for support, sales, and technical requests.Correct route plus fallback/uncertain state.Hard authorization before routing.160
127Build a supervisor that delegates to two specialist workers.Bounded delegation and typed outputs.Supervisor owns budget.160, 162
128Add critique/revision with max two iterations.Rubric-driven improvement without loop.Stop on acceptance threshold.161
129Compare critique by same model vs separate judge model.Bias/quality/cost discussion backed by eval.Use identical cases.161, 184
130Fan out three research workers and synthesize results.Parallel work with deduped evidence.Separate worker state.162
131Add dynamic retrieval decisions to a RAG agent.Agent retrieves only when needed and remains bounded.Static RAG is baseline.163
132Evaluate agentic RAG vs fixed RAG.Task success plus tool steps/cost/latency.Final answer alone is insufficient.163, 185
133Propose a problem where multi-agent is worse than single-agent.Cost/coordination rationale.Avoid hype.164
134Compare one general agent to three specialists on a dataset.Empirical specialization decision.Same budget if possible.164
135Design shared vs isolated state for a multi-agent code review.Minimal artifact sharing and provenance.Avoid giant shared scratchpad.165
136Prevent cyclic supervisor delegation.Max depth/delegations and visited-task detection.Convergence must be explicit.166
137Define conflict resolution for two agents citing different policies.Authoritative-source or escalation strategy.Do not vote blindly.166
138Inventory “memory” in an existing chatbot.Context/history/checkpoint/profile/db clearly separated.Name mechanisms.167
139Design long-term preference memory with user controls.Consent, source, expiry, edit/delete.Persistence creates privacy obligations.168
140Implement memory retrieval scoped by user+tenant.No cross-user personalization leakage.Server-derived identity.168, 189
141Model an approval request table for HITL.Action hash, actor, decision, expiry, timestamps.Bind to exact action.169
142Recheck authorization after an approval wait.Revoked permission blocks execution.Time passes while interrupted.169–170
143Define agent budgets for steps, tokens, elapsed time, and cost.Independent hard limits.Budget is application state/policy.170
144Build a kill switch for all write tools.Central deterministic disable path.Incident control must bypass model.170, 190
145Explain MCP to someone who thinks it is an agent framework.Protocol/connectivity vs orchestration distinction.Host/client/server/primitives.171
146Draw host→client→server trust boundaries for three MCP servers.One client/server relationship and local policy.Connecting server is trust decision.172
147Decide whether capability should be MCP tool, resource, or prompt.Semantic primitive choice.Action vs data vs reusable prompt.173
148Configure stdio vs Streamable HTTP for local and remote integrations.Correct transport rationale.Remote needs HTTP security.174
149Explain why legacy HTTP+SSE should not be new default.Streamable HTTP is modern stable transport.Backward compatibility only.174
150Implement a stable-v1 MCP get-order server tool.Zod validation and safe content result.Use current stable baseline docs.176
151Build an MCP client that lists tools before exposing them.Discovery intersected with local allowlist.Discovery ≠ permission.177
152Simulate a malicious tool description requesting secrets.Local policy prevents privilege expansion.Treat metadata as untrusted.178
153Simulate prompt injection from an MCP resource.Resource text cannot authorize tool use.Context and capability are separate.178
154Design OAuth scopes for Gmail read vs send tools.Least-privilege read/write separation.One token need not have all scopes.179–180
155Explain PKCE and why public clients need it.Code interception protection reasoning.Challenge/verifier pair.179
156Define refresh-token storage controls.Encryption, rotation/revocation, no logs/model context.Long-lived credential is high value.179
157Prevent OAuth token passthrough to another service.Audience/resource-specific token usage.Token is not a universal credential.179
158Add per-tool permission metadata to a registry.Permission, risk, scope, idempotency declared.Executor consumes metadata.180
159Create a golden eval dataset from 20 production failures.Redacted versioned cases with expected properties.Failures are regression assets.181–182
160Choose deterministic vs LLM graders for ten criteria.Objective checks stay deterministic.Use judge only where subjective.183–184
161Build a pairwise LLM judge with randomized candidate order.Bias-reduced rubric comparison.Calibrate to human labels.184
162Add tool trajectory grading.Right tool/args/order/budget assessed.Final answer can hide bad actions.185
163Add agent no-progress metric.Repeated calls/steps identified.Trajectory is data.185
164Define a trace span model for RAG + tool agent.Parent request with retrieval/model/tool/graph spans.One trace ID.186
165Redact PII and secrets from trace payloads.Useful metadata retained without raw sensitive values.Log IDs/categories, not everything.186
166Convert thumbs-up/down into curated eval cases.Feedback traced, reviewed, versioned.Raw feedback is noisy.187
167Threat-model indirect prompt injection via retrieved web page.Data-flow + capability controls identified.Assume model is influenced.188
168Demonstrate confused deputy risk with an overprivileged email tool.Actor/action/resource policy fix.Model intent is not authority.189
169Write a cross-tenant retrieval penetration test.Attacker query never sees other tenant chunks.Test filters and caches.189
170Design SSRF defenses for a URL-fetch tool.Scheme/host/IP/redirect/egress controls.URL validation alone is not enough.190
171Design filesystem sandbox rules for a coding agent.Workspace root, deny secrets, quotas, isolated process.Least privilege.190
172Add shell-command allow/deny policy without relying on prompt.Deterministic sandbox/executor restriction.Parsing commands is hard; isolation matters.190
173Build an incident drill: tool called twice.Stop writes, inspect trace/idempotency, remediate.Preserve evidence.058, 185, 197
174Build an incident drill: poisoned RAG document.Quarantine source, trace affected answers, reindex.Injection is data supply-chain issue.188
175Build an incident drill: MCP server suddenly adds a write tool.Discovery diff blocked pending policy/review.New capability is not auto-approved.177–180
176Build an incident drill: eval quality drops after model update.Freeze rollout, compare versions/cases, rollback.Version everything.181–187
177Build an incident drill: cross-tenant cache leak.Disable cache, scope keys, assess exposure, tests.Tenant identity in cache key.189, 194
178Add model/tool/rag risk register to a design.Explicit threats, mitigations, monitoring, owner.Architecture includes operations.188–190
179Design secure capability onboarding for third-party MCP servers.Trust review, allowlists, scopes, sandbox, audit.Installation is supply-chain boundary.171–180, 190
180Build an agent demo that survives adversarial prompts and tool failures.Bounded, authorized, observable, evaluated execution.Reliability comes from system boundaries.156–190