home
›
cheatsheets
›
ai_engineering
›
ai_agents
Free to read Every card and diagram, and Quiz me
2
Free account Star cards. Your Quiz me marks are kept, so next time you drill just what you missed
3
Pro All 54 answers on this sheet, My sheet across every topic, and PDFs
A free account keeps your stars and Quiz me marks. Pro adds all 54 answers on this sheet, My sheet across every topic, and PDFs.
/
Read
Quiz me
Comfortable
Compact
My misses 0
Click any code to copy it
Done 0 /0
To review 0
On this sheet
The model
01 The agent loop02 Tool calling03 Planning, reflection & RAG04 Memory & context05 Multi-agent systems06 Frameworks & SDKs07 Failures & recovery08 Guardrails & security09 Evals, tracing & cost10 Computer & browser agents
The model An agent is a model in a loop. Each turn it calls a tool, reads the real result and picks the next step. It stops when it answers instead of calling a tool. The model only asks for a tool call. Your code runs it, so validation, permissions and approval gates belong in code, not in the prompt. The API remembers nothing. Your code resends the whole history every turn, and tool output fills the context window fastest. The model picks the path, so steps, cost and latency change from run to run. Bound every loop with a step cap, a token budget and a deadline. Build the simplest thing that works . Try one call, then a fixed workflow, then one agent. Add more agents only for a reason you can name. The loop repeats REASON, ACT and OBSERVE until the model answers without a tool call. The model never runs a tool. Your code does, after its checks.
The agent loop what makes a system an agent Agent or single LLM call Define an AI agent An LLM with a goal and tools that picks its own steps.
Say who picks the next step Your code, in a single call. The model, in an agent.
Tip You trade predictability for flexibility, so cap steps and spend.
The system prompt Say what a system prompt sets Role, scope, tool policy, when to stop, output format.
Keep it stable and small Caching reuses a fixed prefix. Task detail goes in the user turn.
Trap It steers but enforces nothing. Tool output can argue against it.
The reason-act-observe loop while True: step = model(messages) reason if not step.tool_calls: return step.text an answer ends it result = run_tool(step.tool_calls) act messages += [step, result] observe
Say what makes the loop agentic The model picks each step based on real results.
Say what ReAct is A 2022 pattern that grounds each thought in a real tool result.
Tip Agents now use native tool calling instead of parsing Thought: text.
Workflow or agent Tell a workflow from an agent A workflow's steps live in code. An agent picks its own.
Decide if a process needs an agent Is the path fixed? Do the tools exist? What does an error cost?
Tip Start deterministic. Add agency only where fixed logic fails.
Trap No reliable write API means no agent, just a demo.
Planning, reflection & RAG how an agent plans, checks its work and looks things up ReAct or plan-then-execute Adapt Cheap Fan out Audit
ReAct. Best on unknown ground, like debugging and search. Decide one step at a time
Plan-then-execute. Best for known, independent steps. Write the whole plan up front
better worse
Tip Most production agents plan, execute, and replan on failure.
Trap ReAct can drift and loop. Plan-then-execute can follow a stale plan.
Reflection Say what reflection is The agent critiques its own output, then revises it.
Know when reflection pays off When tests, a compiler or a schema can check the output.
Tip Cap it at one or two rounds, and stop once the check passes.
Trap Without an outside check it rarely helps. A model that missed an error often misses it again.
Agentic RAG Compare agentic and classic RAG Classic retrieves once. Agentic lets the model retrieve zero to N times.
Know when agentic RAG wins Comparisons, and multi-hop questions that chain lookups.
Tip Cap retrieval rounds and log every generated query.
Trap For single-fact lookups, classic RAG is cheaper and easier to test.
Memory & context what the model sees on each turn Agent memory Say what the model remembers Nothing. Memory is text you put back in context.
Name the four kinds of memory Working memory, plus episodic, semantic and procedural.
Say what each long-term kind holds Episodic holds past runs, semantic holds facts, procedural holds how-tos.
Say what a write policy decides Which facts persist, when they commit and how they merge.
Store a fact that's already there Update or supersede the old row. Never blind-append.
Tip Most agents start with working memory plus one key-value store of user facts.
Trap The agent reads its own writes back, so one wrong or injected fact sticks. Gate writes from tool output.
Why context runs out Say why long runs fill the window Context is append-only. Every tool result stays in.
Say when quality starts to drop Well before the limit. Models attend poorly to the middle.
Pick the first fix Cap tool output. Return slices, IDs or counts.
Define context engineering Choosing what fills the window on every turn.
Tip Then try compaction, notes in files, subagents and retrieval.
Compaction and multi-day runs Say what compaction does It summarizes old turns and keeps the recent ones as is.
Name what compaction must keep The system prompt, tool schemas, goal, past writes and dead ends.
Run an agent over several days Update a progress file after each step. Each session starts from it.
Tip Keep the full transcript on disk behind a read tool.
Trap Never cut between a tool_use and its tool_result.
Subagents Say what a subagent is A separate agent for one narrow task. Only its result comes back.
Know when to use a subagent Wide read-only exploration. Keep writes on the main thread.
Tip A search can burn 100k tokens inside it. The parent sees a paragraph.
Trap The parent can't see what a subagent missed. A vague summary loses it for good.
Multi-agent systems when to split the work, and how agents pass it on One agent or many Define a multi-agent system Several agents, each with its own prompt, tools and window.
Say why teams start with one agent One trace to debug, a smaller bill, no context lost in handoffs.
Know when many agents win Independent, read-heavy subtasks with short results.
Recall Anthropic's token numbers Multi-agent research used about 15x a chat's tokens. One agent used 4x.
Tip Go multi-agent only for a failure you can name.
Trap Subagents can't see each other's choices, so they duplicate work.
Supervisor or handoff supervisor worker worker worker supervisor It sends each worker a brief and merges the results. Workers never talk to each other.triage refunds user handoff Triage passes the conversation on. Refunds answers, and Triage never resumes.Describe the supervisor pattern One orchestrator briefs workers and merges their results.
Name where a supervisor breaks Lossy briefs, gaps, a flooded context, unchecked results.
Say what an OpenAI SDK handoff is A transfer_to_<agent> call. The new agent owns the rest of the turn.
Pick a handoff or an agent as a tool Hand off so one agent owns the rest. Use as_tool to merge results.
Tip Have workers return a fixed shape, never a raw transcript.
Trap A worker knows only its brief. Gaps in it produce confident, wrong work.
Workflow patterns Run known steps in order Prompt chaining. Each output feeds the next step.
Send each input to a specialist Routing. Classify first, then pass it on.
Fan out and merge Parallelization. Split into sections, or run it several times and vote.
Loop until the output passes Evaluator-optimizer. A generator and a critic take turns.
Tip Your code holds the control flow, so you can test and trace it.
Trap Peer networks that pass control freely are hard to trace. Use them last.
Agents talking to agents Connect agents in one process Shared state, an agent as a tool, or a handoff.
Connect agents across owners A2A. Agents publish Agent Cards and send Tasks as JSON-RPC over HTTP.
Tip MCP connects agents to tools. A2A connects agents to each other.
Frameworks & SDKs what each one gives you, and when to skip them Pick a framework, or none Resume long runs after a crash LangGraph. A state graph that checkpoints every step.
Demo role-based agents fast CrewAI. You write roles and tasks. The loop is implicit.
Build agents on .NET and Azure Microsoft Agent Framework, successor to AutoGen and Semantic Kernel.
Know when to skip a framework One loop, a few tools and one model provider.
Tip Without a framework, you write retries, tracing and checkpoints yourself.
Trap MCP and A2A are protocols, not frameworks. Any framework can speak them.
LangGraph Say how LangGraph models an agent A state graph. Nodes are functions and edges are control flow.
Save state after every step graph = builder.compile(checkpointer=InMemorySaver())
Resume a run paused by interrupt() graph.invoke(Command(resume=True), config)
Trap Interrupts need a checkpointer, and InMemorySaver dies with the process.
OpenAI and Claude agent SDKs Name the OpenAI SDK's building blocks Agents, tools, handoffs, guardrails and sessions, run by Runner.
Run an agent with saved history await Runner.run(triage, "where is my refund?", session=session)
Say what the Claude Agent SDK adds The agent loop, file and Bash tools, subagents, hooks and compaction.
Know when to use the raw API instead For your own loop or state store, or another language.
Tip An OpenAI handoff swaps the active agent inside one run, with one history and trace.
Trap The Claude Agent SDK owns the loop. Custom control flow or your own checkpoints fight it.
Failures & recovery keep a run from looping, repeating or dying Classic failure modes Name the classic failure modes Goal drift, doom loops, context rot, silent success, duplicate writes and injection.
Catch silent success Read the real state back. Never trust the agent's report.
Tip At 2% error per step, over half of 40-step runs fail.
Trap Silent success looks green in the logs. Grade the final state, not the transcript.
A failing tool call Handle bad arguments or a missing record Return a tool_result with is_error: true so the model can adjust.
Handle timeouts, 429 and 5xx errors Retry with backoff in the tool wrapper. The model never sees them.
Write the error message What failed, why, and what to try next.
Tip Cap attempts per tool, then report the failure honestly.
Stop endless loops Set hard budgets Max steps, a deadline and a token cap, enforced outside the model.
Catch a loop that makes no progress Hash each tool call with its arguments. On a repeat, nudge the model.
Handle a run that hits its budget Force a final answer, return the partial work and flag it for a human.
Tip LangGraph has recursion_limit. The OpenAI SDK has max_turns.
Trap The usual cause is a tool that fails softly, with an empty list or a vague error.
Idempotent tools Say why tools must be idempotent Timeouts, crashes and resumed runs repeat calls. A repeat must not charge twice.
Make a write safe to retry Send an idempotency key. A dedupe store replays the first result.
Trap Store the key durably, or a restart mints a new one and charges again.
Long runs and resumable streams Survive crashes, deploys and restarts Commit the run's state after every step, so any worker can resume it.
Replay a step safely after a crash Save the model's reply before its tools run. Key writes by tool call id.
Resume a dropped stream Number every event in a log. The client replays from the last one it saw.
Tip Temporal, Restate and LangGraph checkpointers do this for you.
Trap Don't hold one HTTP request open for an hour. Return a run id.
Guardrails & security limit what a wrong or hijacked run can do Human approval gates Define human-in-the-loop The agent pauses at a tool call and waits for approve, edit or reject.
Know which calls need approval Hard to undo or outward-facing, like payments or deletes.
Enforce the gate In your executor, not the prompt. A model told to ask can skip it.
Tip Gate each call. One approval never covers the next step.
Trap Gate everything and reviewers approve without reading.
Guardrails Place guardrails in the loop Input, every tool call, output, and caps across the run.
Pick the check that matters most The tool call. Every side effect goes through one.
Tip Fail closed on writes. A prompt instruction isn't a guardrail.
Trap Every guardrail is a classifier. Track false positives, or teams switch it off.
Sandbox and credentials Isolate tool code A container or microVM with a read-only disk and no network by default.
Keep credentials out of the sandbox A proxy injects a short-lived token into each call.
Decide whose permissions apply The end user's, not the agent's, or you build a confused deputy.
Give an agent production access The agent never holds one. A broker mints a short-lived, scoped token per task.
Tip Treat each tool call as a request, not a decision. Log the policy decision too.
Trap A raw SQL or shell tool leaves the blast radius to the prompt. Narrow typed tools put it in the signature.
Prompt injection Define prompt injection Text the agent reads carries instructions, and the model follows them.
Name the lethal trifecta Private data, untrusted content and a way to send data out.
Mitigate prompt injection Break one leg with controls outside the model. No prompt wording fixes it.
Tip Assume some injections land. Keep the blast radius small.
Trap An allowlisted domain can still leak data through a query string.
Evals, tracing & cost prove it works, see why it failed, and cap the bill Evaluate an agent Say how agent evals differ Grade the end state, not the exact path. A shorter route should pass.
Report reliability honestly Run each case n times. pass^k needs all k to pass.
Build a test bed that repeats A frozen sandbox with recorded tool responses and a fixed database.
Use an LLM judge Only for open-ended text, calibrated against human labels.
Tip Turn sampled production traces into new cases, and gate deploys on them.
Trap A mean score hides an agent that works 3 times in 5.
Agent benchmarks Measure fixing real GitHub issues SWE-bench Verified. Hidden tests must pass.
Measure tool use with a simulated user tau-bench. It checks the final database state and policy rules.
Measure function-calling accuracy BFCL, across parallel and multi-step calls.
Measure web and desktop use WebArena for web tasks. OSWorld for a real desktop.
Trap pass@1 hides variance, and scores shift with the tools and retries.
Trace an agent in production Say what a trace holds One run, with a span per model call and tool call.
Make traces portable Emit OpenTelemetry GenAI spans. Langfuse and LangSmith can read them.
Pick the online signals Success rate, tool errors, steps and cost per run.
Tip A rising step count is the earliest sign of looping, so alert on it.
Cost and latency Say what drives cost and latency Cost tracks tokens. Latency tracks sequential model calls.
Cut the cost of every turn Cache the fixed system-and-tools prefix.
Cut cost and latency together Send routine steps to a small model, and cap steps and tokens.
Tip Streaming removes no work. It only feels faster.
Trap Measure per trajectory. A cheap model that needs 3 extra turns costs more.
Computer & browser agents agents that click and type like a person Computer-use agents Say how a computer-use agent works It reads a screenshot and clicks or types at pixel coordinates.
Know when to use one Only when no API exists. Run it in a sandboxed VM.
Estimate a 40-step task's success About 13% at 95% per step. Errors compound.
Tip Target elements from the accessibility tree where you can.
Trap GUI actions aren't idempotent. A blind retry can submit a form twice.
DOM or vision browser agents Exact Cheap Canvas
A DOM agent reads the HTML. Canvas and iframes break it. Act on the page's elements
A vision agent clicks on pixels. Layout and scroll changes throw it off. Act on screenshots
yes no breaks
Tip Most stacks mix them. The DOM picks the target and a screenshot confirms it.
Trap Any page in your logged-in session can steer it. Use a throwaway profile.
Nothing matches. Try a shorter word, or clear the search.
Practice Guided practice One question at a time, with the ones you miss coming back.
Practice 54 interview questions Full answers, from beginner to expert.
Found this useful? Pass it on.
Share on LinkedIn
Share on X
Copy link
This sheet stays free. With Pro , you can:
Every answer on this sheet. Read the full answer to all 54 questions it links, not just the 7 free ones.
My sheet. The cards you star and the ones you miss in Quiz me, from every sheet, on one page to quiz and print.
PDFs. Download this sheet and My sheet, laid out for A4, with every question a link to its answer.
The rest of Pro. Every answer in the question library, and 1,000 AI credits a month.