Prev Next

AI / AI Agents & Skills Interview questions

Last updated

1. What is an AI agent? 2. Describe the agent loop? 3. What are the core components of an AI agent? 4. What is tool use in LLM agents? 5. What is an agent skill? 6. What is a SKILL.md file? 7. What is the Model Context Protocol (MCP)? 8. What is the ReAct pattern? 9. What are the types of agent memory? 10. What is a subagent? 11. What is a system prompt in an agent? 12. What is a multi-agent system? 13. What is planning in AI agents? 14. What is human-in-the-loop in agents? 15. What are guardrails in AI agents? 16. Define prompt injection in AI agents? 17. What is the context window in agent workflows? 18. What is an agent evaluation? 19. How do you use RAG with an AI agent? 20. List common agentic design patterns? 21. What is the difference between an AI agent and a chatbot? 22. What is the difference between a workflow and an agent? 23. What is the difference between a skill and an MCP tool? 24. How does progressive disclosure work in agent skills? 25. Why do skill descriptions matter for triggering? 26. How does an agent decide which tool to call? 27. What is the difference between ReAct and plan-and-execute? 28. Why do agents fail on long-running tasks? 29. How do you handle tool errors in an agent? 30. How does context compaction work in agents? 31. When should you use multiple agents instead of one? 32. Explain the orchestrator-worker pattern? 33. How do you design a good tool for an agent? 34. How do you defend agents against prompt injection? 35. How do you evaluate an AI agent? 36. How do you make agent tool calls safe to retry? 37. Why use skills instead of fine-tuning? 38. How can you optimize agent cost and latency? 39. How do you troubleshoot an agent stuck in a loop? 40. Explain the execution flow of an agent skill invocation? 41. Explain the lifecycle of an agent task from request to answer? 42. How do you apply least privilege to agent permissions? 43. How do you persist state across agent sessions? 44. When should tool calls run in parallel? 45. How do you troubleshoot a skill that never triggers? 46. How do you trace and debug agents in production? 47. Explain the internal working of an MCP client-server exchange? 48. Why do too many tools hurt agent accuracy? 49. What happens when a tool returns a very large result? 50. Why should skills bundle executable scripts?

1. What is an AI agent?

An AI agent is a system where a language model decides, step by step, which actions to take to reach a goal, runs those actions through tools, and uses the results to pick the next step.

Unlike a single prompt-and-response call, the model controls the flow. It can search, read files, call APIs or write code, and it stops only when it judges the task done or a limit is reached.

A minimal agent is just three things: a model, a set of tools, and a loop that feeds tool results back to the model.

Take quiz
What makes a system an agent rather than a single LLM call?
It always uses the largest available model
It returns its answer in JSON format
The model chooses actions and loops on tool results
In a minimal agent, tool results are:
fed back to the model to choose the next step
discarded once they are logged
shown only to the end user

2. Describe the agent loop?

The agent loop is the repeated cycle in which the model reasons, calls a tool, observes the result and decides again until the task is finished.

  1. Send the goal, tool definitions and history to the model.
  2. The model replies with either a final answer or a tool call.
  3. The application runs the requested tool.
  4. The result is appended to the conversation.
  5. Repeat until the model answers without a tool call, or a step limit hits.
flowchart LR
  A["Goal + history"] --> B["Model call"]
  B --> C{Tool call?}
  C -- Yes --> D["Run tool"]
  D --> E["Append result"]
  E --> B
  C -- No --> F["Final answer"]

Always add a maximum iteration count so a confused agent cannot loop forever.

Take quiz
Who actually executes a tool call in the loop?
The application runtime around the model
The model, directly from its weights
The end user, by hand
The loop normally ends when:
the first tool returns any result
the model answers without a tool call, or a limit is hit
the context window is cleared

3. What are the core components of an AI agent?

Most agents are built from the same five parts, whatever framework wraps them.

Component Role
Model Reasons about the goal and picks the next action.
Instructions System prompt with role, rules and output format.
Tools Functions or APIs the agent can call to act on the world.
Memory / context Conversation history plus any external store it can read.
Runtime loop Code that executes tools, enforces limits and feeds results back.

Guardrails and logging usually sit around the loop rather than inside the model.

Take quiz
Which component turns a model's decision into a real action?
The system prompt alone
Tools executed by the runtime loop
The tokenizer
Where do step limits and result handling live?
Inside the model weights
In the user's browser
In the runtime loop

4. What is tool use in LLM agents?

Tool use (also called function calling) lets a model request an action by emitting a structured call, a tool name plus JSON arguments, instead of plain text.

You describe each tool with a name, a description and a JSON schema for its inputs. The model never runs anything itself. Your code runs the tool and returns the output as a new message.

{
  "type": "tool_use",
  "name": "get_weather",
  "input": { "city": "Charlotte" }
}

This is what lets an agent search the web, query a database or edit files.

Take quiz
In tool use, what does the model produce?
The tool's actual output
A compiled binary of the function
A structured request with a tool name and arguments
What defines the shape of a tool's inputs?
A JSON schema supplied with the tool definition
The user's chat history
The model's temperature setting

5. What is an agent skill?

An agent skill is a packaged folder of instructions, and optionally scripts and reference files, that an agent loads on demand to do a specialized task well.

Think of it as an onboarding guide for one job, such as building a spreadsheet or reviewing a contract. The agent reads it only when the task calls for it, so it adds no cost to unrelated work.

Each skill has a short name and description that tell the agent when it applies.

Take quiz
An agent skill is best described as:
a folder of instructions and resources loaded on demand
a new model fine-tuned for one task
a hardware plugin for the agent
What tells the agent when a skill applies?
The size of the skill folder
The skill's name and description
The user's account tier

6. What is a SKILL.md file?

SKILL.md is the entry-point file of a skill. It begins with YAML frontmatter holding the skill's name and description, followed by Markdown instructions.

---
name: invoice-review
description: Review supplier invoices for errors. Use when the user uploads an invoice or asks to check billing.
---
# Invoice review
1. Extract line items.
2. Compare totals against the purchase order.
3. Flag mismatches in a short table.

The frontmatter is always visible to the agent. The body is read only after the skill is chosen.

Take quiz
Which fields belong in SKILL.md frontmatter?
author and license key
name and description
model and temperature
When does the agent read the body of SKILL.md?
At every startup regardless of the task
Only when the user pastes it into chat
After it decides the skill is relevant

7. What is the Model Context Protocol (MCP)?

MCP is an open protocol, introduced by Anthropic, that standardizes how AI applications connect to external tools and data sources.

Instead of writing a custom integration for every app and service pair, a service exposes an MCP server and any MCP client can use it. Messages use JSON-RPC 2.0.

A server can offer three kinds of capability: tools (actions), resources (data to read) and prompts (reusable templates).

Two common transports are stdio, for servers running locally as a child process, and streamable HTTP, for remote servers. Many popular tools, such as file systems, databases and issue trackers, already have ready-made MCP servers.

Take quiz
What problem does MCP mainly solve?
Training models faster
Compressing long prompts
Custom one-off integrations between apps and services
Which is NOT one of the main MCP server capabilities?
Model weights
Tools
Resources

8. What is the ReAct pattern?

ReAct (Reason + Act) is a prompting pattern where the model alternates between writing a short thought, taking an action, and reading the observation that comes back.

Thought: I need the user's order status.
Action: lookup_order(id=4821)
Observation: shipped, arrives Friday
Thought: I can answer now.
Answer: Your order ships Friday.

Reasoning guides which tool to use, and tool results keep the reasoning grounded in real data rather than guesses.

Modern APIs with native tool calling have largely absorbed this pattern, but the idea still holds: interleaving a brief rationale with tool results makes runs easier to debug, since you can read why each action was taken.

Take quiz
In ReAct, what comes right after an Action?
An Observation containing the tool result
A new system prompt
The final answer, always
What does ReAct combine?
Retrieval and caching
Reasoning and acting
Training and evaluation

9. What are the types of agent memory?

Agent memory is usually split by how long the information lives and where it is stored.

Short-term Long-term
Lives in the context window for the current task. Lives in external storage such as files, databases or vector stores.
Lost when the session ends or context is trimmed. Survives across sessions and is retrieved when needed.

Long-term memory is often further described as episodic (past events), semantic (facts) and procedural (how to do things, which skills resemble).

In practice, most agents combine both. They keep the live task in context and write key facts, such as user preferences or finished steps, to a file or store they can reload in the next session.

Take quiz
Where does short-term agent memory live?
In a vector database
In the context window
In the model's weights
Procedural memory in agents refers to:
a log of past conversations
a list of user facts
how to perform tasks

10. What is a subagent?

A subagent is a separate agent instance, started by a parent agent to handle a focused subtask in its own fresh context window.

It gets its own instructions and sometimes a limited tool set. When it finishes, it returns a short result to the parent, not its whole working history.

That keeps the parent's context clean and lets independent subtasks, like searching three codebases, run in parallel.

Example: a code-review agent might spawn one subagent per changed module. Each reads its module in depth, then sends back a three-line verdict, so the parent never has to hold every file in its own context.

Take quiz
What does a subagent usually return to its parent?
Its entire context window
Nothing at all
A condensed result of its work
A key benefit of using a subagent is:
it keeps the parent's context window clean
it removes the need for tools
it guarantees correct answers

11. What is a system prompt in an agent?

The system prompt is the standing instruction block sent with every model call. It defines the agent's role, rules, tool-use guidance, tone and output format.

For agents it also tells the model when to use each tool, when to ask the user for clarification, and when to stop. Because it is resent every turn, a bloated system prompt costs tokens each time.

Keep it specific and short, and move rarely used guidance into skills.

Example: "You are a billing support agent. Use lookup_invoice before quoting amounts. If the customer asks for a refund over $200, escalate to a human." Rules phrased with a reason behind them tend to be followed more reliably than bare commands.

Take quiz
How often is the system prompt sent to the model?
With every model call
Only on the very first message
Only when a tool fails
A good place for rarely needed, task-specific guidance is:
the system prompt, always
a skill loaded on demand
the tool's return value

12. What is a multi-agent system?

A multi-agent system uses several agents, each with its own role, prompt and tools, that cooperate on one larger goal.

A common setup has a lead agent that splits the work and specialist agents, such as researcher, coder and reviewer, that handle the pieces. Results flow back to the lead, which combines them.

The gain is specialization and parallel work. The cost is extra tokens, coordination overhead and harder debugging.

Common coordination styles are a supervisor that assigns work, a pipeline where each agent passes output to the next, and peer review where one agent critiques another. Pick the simplest layout that matches how the task naturally splits.

Take quiz
In a typical multi-agent setup, who combines the specialists' results?
The tokenizer
The lead or orchestrating agent
Each specialist independently
A main drawback of multi-agent systems is:
they cannot use tools
they only work offline
higher token cost and coordination overhead

13. What is planning in AI agents?

Planning is the agent's step of breaking a goal into ordered subtasks before, or while, it acts.

A plan can be a short checklist the model writes itself, a structured to-do list tool, or the output of a dedicated planner agent. Good plans name dependencies, so step three does not start before step two's output exists.

Plans should stay revisable. If a tool result contradicts the plan, the agent should update it rather than march on.

Example: for "add a login page", a plan might read: inspect the existing routes, create the form component, wire up the auth call, add tests, then run them. Each item gives the agent a clear checkpoint to verify.

Take quiz
What does planning produce?
A fine-tuned model
A new tool schema
An ordered breakdown of subtasks
If a tool result contradicts the plan, the agent should:
revise the plan
ignore the result and continue
delete its memory

14. What is human-in-the-loop in agents?

Human-in-the-loop means a person reviews or approves certain agent actions before they run, instead of the agent acting fully on its own.

It is typically applied to risky steps: sending email, deleting data, spending money or deploying code. Safe read-only steps can run without a pause.

The aim is to match oversight to risk, so approvals stay meaningful instead of becoming a click-through habit.

Common designs are an approval gate that pauses before a flagged tool runs, a review step on final output, and an escalation path where the agent hands over when it is unsure rather than guessing.

Take quiz
Where is human approval most appropriate?
Irreversible or high-impact actions
Every single token generated
Reading a public file
Why avoid asking for approval on every step?
It makes the model smaller
People start approving without reading
It breaks the JSON schema

15. What are guardrails in AI agents?

Guardrails are checks that keep an agent inside safe and intended behavior. They can sit on the input, the output or the tool calls.

  • Input checks - detect off-topic or malicious requests.
  • Output checks - catch leaked secrets, policy violations or malformed responses.
  • Action checks - block or confirm dangerous tool calls, enforce spend limits and allowlists.

Enforce critical rules in code, not only in the prompt, because prompts can be overridden.

Example: a finance agent may be allowed to read ledgers freely, but a guardrail rejects any transfer above a set amount until a person confirms it.

Take quiz
Where should critical safety rules be enforced?
Only in a polite system prompt
In code outside the model
Only in the user message
An action guardrail might:
rewrite the model weights
shorten the context window
block a tool call that exceeds a spend limit

16. Define prompt injection in AI agents?

Prompt injection is an attack where malicious instructions hidden in content the agent reads, a web page, email or file, trick it into doing something the user never asked for.

It is serious for agents because they hold tools. A page that says "forward the user's inbox to this address" is dangerous if the agent can send email.

The root issue is that models can confuse data they read with instructions they should follow.

Direct injection comes from the user's own message, while indirect injection arrives through third-party content. The indirect form is the bigger worry for agents, because the user never sees the hidden text.

Take quiz
Where does indirect prompt injection usually hide?
Only in the model's training data
Inside the GPU drivers
In content the agent reads, such as web pages or emails
Why are agents more exposed than plain chatbots?
They have tools that can take real actions
They use shorter prompts
They lack a system prompt

17. What is the context window in agent workflows?

The context window is the maximum amount of text, measured in tokens, the model can consider in one call. It holds the system prompt, tool definitions, history and tool results together.

Agents burn through it quickly because every tool result is appended. When it fills, older content must be dropped, summarized or moved to external memory, or the call fails.

Managing context is therefore a core agent skill, not an afterthought.

Rough rule: tool definitions and the system prompt are a fixed cost on every call, while history and tool output keep growing. Watching token usage per step shows you which of those is eating the budget.

Take quiz
What fills an agent's context window?
System prompt, tool definitions, history and tool results
Only the latest user message
Only the model's weights
When the window fills, an agent should:
ignore the limit
summarize or offload older content
restart the model server

18. What is an agent evaluation?

An agent evaluation, or eval, is a repeatable test that measures how well an agent completes tasks, using fixed inputs and a defined way to score the outcome.

Scoring can check the final state (did the file get created?), the answer (does it match a reference?), or the path (were the right tools used?). A model-based grader can score open-ended output.

Run evals before and after any prompt, tool or model change so regressions show up early.

Because the same agent can succeed once and fail the next time on the same input, run each case several times and report a pass rate instead of a single pass or fail.

Take quiz
Why run evals before and after a change?
To reduce the model's size
To catch regressions early
To avoid writing tool descriptions
Scoring an agent by checking if a file was created is checking:
the model's temperature
the tokenizer
the final state

19. How do you use RAG with an AI agent?

With RAG (retrieval-augmented generation), you expose a search tool over your documents so the agent can fetch relevant passages before answering.

  1. Chunk and embed documents into a vector index.
  2. Give the agent a search_docs(query) tool.
  3. The agent writes its own query, reads the returned chunks, and may search again.
  4. It answers from the retrieved text and cites the source.

This is "agentic RAG": the agent decides when and what to retrieve, rather than retrieval running blindly on every question.

Quality depends heavily on chunk size, embedding choice and how well the agent phrases its query. If answers look wrong, inspect what was retrieved before blaming the model.

Take quiz
In agentic RAG, who decides what to search for?
A fixed rule that never changes
The vector database
The agent, by writing its own queries
Retrieved chunks are most useful because they:
ground the answer in your own documents
increase the model's parameter count
replace the system prompt

20. List common agentic design patterns?

Anthropic's guidance on building effective agents highlights a handful of reusable patterns.

  • Prompt chaining - a fixed sequence of calls, each feeding the next.
  • Routing - classify the input and send it to a specialized path.
  • Parallelization - run independent subtasks at once, or vote across runs.
  • Orchestrator-workers - a lead model delegates dynamic subtasks.
  • Evaluator-optimizer - one model drafts, another critiques, in a loop.

Start with the simplest one that works and add complexity only when measurements justify it.

Take quiz
Which pattern sends an input to a specialized path based on its type?
Routing
Prompt chaining
Evaluator-optimizer
The evaluator-optimizer pattern works by:
splitting a prompt by length
one model drafting and another critiquing in a loop
caching every response

21. What is the difference between an AI agent and a chatbot?

A chatbot responds to messages. An agent pursues a goal, and takes actions to get there.

Chatbot AI Agent
One reply per user message. Many model calls per user request.
Mostly produces text. Calls tools that change real systems.
User drives every step. Agent decides the next step itself.

The line blurs, since a chatbot with a search tool already behaves a little like an agent.

Example: asked to "book the cheapest flight to Denver", a chatbot lists tips, while an agent searches fares, compares them, asks for confirmation, and completes the booking through a booking tool.

The extra autonomy brings extra risk, so agents need limits, logging and approvals that chatbots rarely require.

Take quiz
Which is true of an agent but not a plain chatbot?
It uses a language model
It makes multiple model calls and tool calls per request
It accepts text input
Who drives each next step in an agent?
Always the user
The operating system
The agent itself

22. What is the difference between a workflow and an agent?

In a workflow, your code defines the path: steps run in a predetermined order and the model fills in each step. In an agent, the model decides the path at run time.

Workflows are more predictable, cheaper and easier to test, so they suit tasks with known steps, like extract, validate, then save. Agents suit open-ended tasks where the number of steps cannot be known in advance, like fixing an unfamiliar bug.

A practical rule is to use a workflow whenever the steps are stable, and reach for an agent only when they are not.

Many production systems are hybrids: a workflow handles the stable outer steps, and an agent runs inside one step, such as research, where the path is unknown.

Take quiz
Who decides the sequence of steps in a workflow?
The model at run time
The end user
The developer's code
Which task suits an agent better than a workflow?
Debugging an unfamiliar codebase
Converting a date format
Sending a fixed welcome email

23. What is the difference between a skill and an MCP tool?

They solve different problems and often work together.

Skill MCP tool
Teaches the agent how to do a task. Gives the agent a capability to act or fetch data.
Mostly instructions, sometimes scripts. A callable function served by an MCP server.
Loaded into context when relevant. Definition is listed to the model up front.

Example: an MCP tool connects to your CRM, and a skill explains your team's process for writing a renewal summary from that data.

The two are complementary rather than competing. A skill can even tell the agent which MCP tools to call and in what order, so one carries the procedure and the other carries the access.

Take quiz
A skill mainly provides:
knowledge of how to perform a task
a network connection to a service
extra GPU memory
An MCP tool mainly provides:
a style guide for writing
a callable capability such as querying a service
a replacement for the system prompt

24. How does progressive disclosure work in agent skills?

Progressive disclosure means a skill reveals its content in layers, so the agent only pays the token cost for what the task needs.

  1. Level 1: only each skill's name and description sit in the system prompt at startup.
  2. Level 2: when a task matches, the agent reads the full SKILL.md body.
  3. Level 3: extra files and scripts, referenced from SKILL.md, are opened or run only if required.

Because of this, you can install dozens of skills while keeping the base context small.

Example: with 40 skills installed and about 100 tokens of metadata each, startup costs roughly 4,000 tokens, instead of loading every full instruction set up front. Detailed content enters context only for the one or two skills actually used.

Take quiz
What is loaded at startup for each installed skill?
The complete SKILL.md and all scripts
Only its name and description
Nothing at all
Why does this design save tokens?
Skills are compressed into binary
Skills skip the context window
Detailed content loads only when the task needs it

25. Why do skill descriptions matter for triggering?

The description is the only part of a skill the agent sees before deciding to use it, so it acts as the trigger. If it is vague, the skill is missed. If it is too broad, the skill fires when it should not.

A good description states both what the skill does and when to use it, with the words a user would actually say.

Weak:   Helps with documents.
Strong: Create and edit Word (.docx) files. Use when the user
        asks for a Word document, memo or formatted report.

Test a description by writing five different ways a user might ask for the task and checking that the skill fires for each. Also write one near-miss request that should not trigger it.

Take quiz
What should a strong skill description include?
Only the author's name
A full copy of the instructions
What the skill does and when to use it
A vague description most likely causes:
the skill not being selected
faster model inference
a larger context window

26. How does an agent decide which tool to call?

The model reads the tool names, descriptions and parameter schemas in its context and picks the one that best fits the current step. There is no hidden router; it is the model's own judgment based on that text.

That is why description quality drives accuracy. Two tools with overlapping descriptions will be confused, and a tool whose description omits its limits will be misused.

You can steer the choice with clear descriptions, instructions in the system prompt, or by forcing a specific tool in the API when a step must happen.

Example: if the tools are search_orders and get_order, a description saying the second needs an exact order ID tells the model to use the first when it only has a customer name.

Take quiz
What mainly drives which tool the model picks?
Tool names, descriptions and schemas in context
A hidden routing table in the API
Random selection
Overlapping tool descriptions lead to:
lower token usage
the model confusing the tools
automatic merging of the tools

27. What is the difference between ReAct and plan-and-execute?

ReAct decides one step at a time, adapting after every observation. Plan-and-execute writes a full plan first and then carries it out, possibly with a cheaper model for execution.

ReAct Plan-and-execute
Flexible, reacts to surprises. More structured and easier to review upfront.
Can drift without a clear goal. Needs replanning when results diverge.

Many real agents blend both: plan briefly, act in ReAct style, and replan when something breaks.

Choose ReAct for exploratory work where the next step depends on what you find, such as debugging. Choose plan-and-execute when the task is large but predictable, since the upfront plan is reviewable and keeps a long run on track.

Take quiz
Which approach adapts after every single observation?
A fixed plan that never changes
ReAct
Static prompt chaining
A weakness of plan-and-execute is:
it cannot use tools
it only works with one tool
it needs replanning when results diverge from the plan

28. Why do agents fail on long-running tasks?

Errors and context both accumulate. Each step has a small chance of going wrong, and over dozens of steps those chances compound.

Typical causes:

  • Context bloat - old tool output crowds out the goal.
  • Goal drift - the agent forgets the original request.
  • Compounding mistakes - an early wrong assumption poisons later steps.
  • Lost state - nothing records what is already done.

Mitigations include progress files, periodic summaries, checkpoints and verification after each major step.

If each step is 95% reliable, a 20-step task finishes cleanly only about a third of the time. That is why shorter chains, verification points and checkpoints matter more than raw model strength.

Take quiz
What is 'goal drift'?
The model changing languages
A tool returning slowly
The agent gradually forgetting the original request
A good mitigation for lost state is:
a progress file recording completed steps
a larger temperature
removing all tools

29. How do you handle tool errors in an agent?

Return the error to the model as a clear, readable tool result instead of crashing the loop. A message like "File not found: report.csv. Available files: sales.csv" lets the model correct itself.

  1. Catch exceptions in the tool wrapper.
  2. Return a short message saying what failed and what to try.
  3. Retry automatically only for transient errors such as timeouts.
  4. Cap total retries so the agent cannot spin.

Avoid dumping raw stack traces. They waste tokens and rarely help the model.

Also distinguish error types. A transient error, such as a timeout, deserves a retry. A fixable error, such as a wrong argument, needs feedback. A fatal error, such as missing permission, should stop and report to the user.

Take quiz
What is the best way to report a tool failure to the model?
A clear message saying what failed and what to try
A raw 500-line stack trace
Silently skipping the result
Automatic retries are most suitable for:
invalid argument errors
transient errors like timeouts
permission denied errors

30. How does context compaction work in agents?

Context compaction shrinks a long history so the agent can keep working. When usage nears a threshold, the older part of the conversation is summarized and replaced with that summary.

A good summary keeps the goal, decisions made, files changed, open problems and next steps. It drops raw tool output that is no longer needed.

Related techniques include clearing stale tool results, and writing notes to an external file so facts survive even after the context is trimmed.

Compaction trades detail for room, so tune it. Summarizing too early loses useful facts, while summarizing too late risks hitting the limit mid-step. Many setups trigger it at a fixed share of the window, such as when usage passes roughly 80%.

Take quiz
What does compaction replace older history with?
A random sample of messages
A summary of it
Nothing, the history just ends
Which belongs in a good compaction summary?
Every raw tool result
The tokenizer vocabulary
The goal, decisions and next steps

31. When should you use multiple agents instead of one?

Use multiple agents when the work is parallelizable, needs separate contexts, or benefits from specialized instructions. Otherwise a single agent with good tools is simpler and cheaper.

  • Breadth tasks - researching many independent sources at once.
  • Context isolation - a noisy subtask would flood the main context.
  • Distinct roles - a reviewer that should not share the author's assumptions.

Avoid it for tightly coupled work where every step depends on shared state. Coordination costs and extra tokens will outweigh the gain.

Before splitting, measure a single-agent baseline. If one agent with better tools already hits your quality target, the multi-agent version only adds cost, latency and more places for things to go wrong.

Take quiz
Which task best justifies multiple agents?
A short two-step calculation
Renaming a single variable
Researching many independent sources in parallel
A reason to avoid multi-agent design is:
tightly coupled steps that all share state
the need for parallel work
the need for context isolation

32. Explain the orchestrator-worker pattern?

In the orchestrator-worker pattern, a lead model analyzes the request, decides at run time which subtasks are needed, hands each to a worker, and then synthesizes the results.

flowchart TD
  U["User request"] --> O[Orchestrator]
  O --> W1["Worker: subtask A"]
  O --> W2["Worker: subtask B"]
  O --> W3["Worker: subtask C"]
  W1 --> S["Orchestrator synthesizes"]
  W2 --> S
  W3 --> S
  S --> R["Final answer"]

It differs from plain parallelization because the subtasks are not fixed in advance. The orchestrator chooses them based on the input, which suits things like multi-file code changes or broad research.

Give each worker a clear objective, an output format and the tools it needs. Vague delegation leads to duplicated or missed work.

Take quiz
What does the orchestrator do after the workers finish?
Synthesizes their results into one answer
Deletes the workers' output
Retrains the workers
What separates orchestrator-workers from plain parallelization?
It uses no model at all
The subtasks are chosen dynamically at run time
It forbids tool use

33. How do you design a good tool for an agent?

Design tools the way you would design an API for a new teammate who cannot ask questions: clear, narrow and forgiving.

  1. Give it a precise name and a description covering when to use it and its limits.
  2. Keep parameters few, typed and documented, with examples for tricky formats.
  3. Return concise, relevant output. Trim noise, and use readable names instead of opaque IDs.
  4. Make errors instructive, saying how to fix the call.
  5. Combine chatty low-level calls into one task-level tool when they are always used together.

Test by watching real agent runs. Wherever the model misuses a tool, the fix is usually in the description or the output.

Take quiz
What should a tool's error message do?
Return only a numeric code
Explain how to fix the call
Hide what went wrong
When is merging several low-level tools into one sensible?
When they are never used
When descriptions are too short
When they are almost always used together

34. How do you defend agents against prompt injection?

No single fix exists, so layer several defenses and assume some injections will get through.

  • Least privilege - give the agent only the tools and data the task needs.
  • Separate trust levels - treat fetched content as data, and label it clearly as untrusted.
  • Confirm risky actions - require human approval for sends, deletes and payments.
  • Break the "lethal trifecta" - avoid combining private data, untrusted content and an outbound channel in one session.
  • Monitor and filter - scan inputs and outputs, and log all tool calls.

The strongest protection is architectural: limit what a hijacked agent could possibly do.

Take quiz
Which defense limits damage even when an injection succeeds?
A longer system prompt
A higher temperature
Least privilege on tools and data
Fetched web content should be treated as:
untrusted data
trusted instructions
part of the system prompt

35. How do you evaluate an AI agent?

Start with a set of realistic tasks, each with a clear success condition, and run the agent on them repeatedly. Agents are non-deterministic, so one pass proves little.

What you measure How
Outcome Check the end state, such as tests passing or a record created.
Trajectory Review tool calls for wasted or unsafe steps.
Cost and latency Track tokens, steps and wall time per task.
Quality Use a rubric-based model grader for open-ended output, spot-checked by humans.

Grade the outcome rather than a required path, or you will punish valid alternative solutions.

Include hard cases: ambiguous requests, missing data, tools that fail, and attempts to push the agent off task. Easy tasks alone will make almost any agent look good.

Take quiz
Why run each eval task multiple times?
Agents are non-deterministic
To increase the context window
To avoid writing graders
Checking whether unit tests pass after a coding agent runs is measuring:
tokenizer speed
outcome
system prompt length

36. How do you make agent tool calls safe to retry?

Make the tool idempotent: calling it twice with the same input should leave the system in the same state as calling it once.

  • Pass an idempotency key with writes such as payments or order creation, so the server ignores duplicates.
  • Prefer "set status to shipped" over "increment shipped count".
  • Check existence first, for example create-if-not-exists.
  • Return the existing result when a duplicate is detected.

This matters because agents retry after timeouts and may not know whether the first attempt succeeded.

Example: a create-invoice tool takes idempotency_key = order-4821. If the first call times out and the agent retries, the server recognizes the key and returns the invoice already created instead of billing twice.

Take quiz
What does an idempotency key prevent?
Slow model responses
Duplicate side effects from repeated calls
Long system prompts
Which operation is naturally idempotent?
Add one to the shipped counter
Append a new log line each time
Set the order status to shipped

37. Why use skills instead of fine-tuning?

Skills change behavior through readable instructions, so they are faster, cheaper and easier to maintain than retraining a model.

Skills Fine-tuning
Edit a text file and the change is live. Needs a new training run and evaluation.
Human-readable and reviewable. Knowledge is buried in weights.
Works with any compatible model version. Tied to one base model.

Fine-tuning still makes sense for deep style changes or high-volume narrow tasks, but for team procedures and domain know-how, skills are usually the better first choice.

The two also combine well. A skill can capture the team's evolving procedures, while a fine-tuned model, if you have one, supplies baseline domain fluency or tone.

Take quiz
A key maintenance advantage of skills is:
they require retraining each time
they hide logic inside model weights
changes are made by editing readable files
Fine-tuning may still be preferred for:
deep style changes or high-volume narrow tasks
storing a team's checklist
documenting a weekly process

38. How can you optimize agent cost and latency?

Most of an agent's cost comes from repeatedly resending a growing context, so attack that first.

  1. Prompt caching - cache the stable prefix (system prompt, tools) so repeat calls are cheaper and faster.
  2. Trim tool output - return only the fields the model needs.
  3. Parallel tool calls - run independent calls together to cut wall time.
  4. Right-size models - use a smaller model for simple subagents or routing.
  5. Skills over bloated prompts - load instructions only when relevant.
  6. Step limits - stop runaway loops early.

Measure before tuning. Log tokens per step and per tool, find the top cost driver, and fix that first. Caching and output trimming are usually the cheapest wins, and model downsizing needs an eval to confirm quality holds.

Take quiz
Which technique makes repeated calls cheaper by reusing the stable prefix?
Prompt caching
Raising the temperature
Adding more tools
Running independent tool calls together mainly reduces:
the number of tools
wall-clock latency
the context window size

39. How do you troubleshoot an agent stuck in a loop?

Read the trace first. Looping nearly always shows up as the same tool call repeated with the same or slightly changed arguments.

  1. Find the repeat. Which call, and what result came back each time?
  2. Check the result. Often the tool returns an unhelpful or empty response, so the model keeps trying.
  3. Improve feedback. Make the error say what to change, or say clearly that nothing exists.
  4. Clarify the stop condition in the instructions.
  5. Add guards: a max step count and detection of repeated identical calls that forces a replan or escalation to a human.

A frequent real cause is a search tool that returns zero results with no explanation, so the model keeps rephrasing. A message such as "0 matches in 1,200 files; try a broader term" often breaks the cycle on its own.

Take quiz
What does a stuck loop usually look like in a trace?
The model refusing all input
The same tool call repeated over and over
Empty system prompt
A programmatic guard against loops is:
a larger context window
removing the tool descriptions
a maximum step count plus repeat-call detection

40. Explain the execution flow of an agent skill invocation?

A skill invocation is a short chain of decisions, and the agent only reads what it needs at each stage.

flowchart TD
  A["Startup: load skill names + descriptions"] --> B["User request arrives"]
  B --> C{Description matches task?}
  C -- No --> G["Answer without skill"]
  C -- Yes --> D["Read SKILL.md body"]
  D --> E{Needs extra files or scripts?}
  E -- Yes --> F["Open file or run script, only output enters context"]
  E -- No --> H["Follow instructions"]
  F --> H
  H --> I["Final result"]

The match in step three is the model's judgment against the descriptions. Script source is not loaded into context; only its output is, which keeps long procedures cheap.

If a skill misfires, check step three first. Most selection problems trace back to a weak or overlapping description, not to the instructions in the body.

Take quiz
What does the agent compare against the user request to pick a skill?
The full text of every SKILL.md
The user's previous password
The skill descriptions loaded at startup
When a skill script runs, what enters the context?
Only the script's output
The entire script source code
Every file in the skill folder

41. Explain the lifecycle of an agent task from request to answer?

A task moves through setup, a repeating work cycle, and a wrap-up.

sequenceDiagram
  participant U as User
  participant R as Runtime
  participant M as Model
  participant T as Tool
  U->>R: Request
  R->>M: Prompt + tools + history
  M-->>R: Tool call
  R->>T: Execute
  T-->>R: Result
  R->>M: Append result
  M-->>R: Final answer
  R-->>U: Response

Between the first and last calls the loop may repeat many times. The runtime also enforces limits, logs each step, and may pause for human approval before risky tools. If context fills, it compacts history before the next model call.

Failure points sit at each hop: a model may pick the wrong tool, a tool may error or time out, or context may fill. Good runtimes handle each explicitly, with retries, feedback to the model, or compaction, and stop with a clear message when the step limit is reached.

Take quiz
Who sends the tool's result back to the model?
The runtime
The user directly
The tokenizer
What may the runtime do before a risky tool runs?
Skip the model entirely
Pause for human approval
Clear all tool definitions

42. How do you apply least privilege to agent permissions?

Give the agent the minimum access that lets it finish the task, and nothing standing beyond it.

  • Scope tools - expose only what the task needs, with read-only versions where possible.
  • Scope credentials - use short-lived, narrowly scoped tokens, not a personal admin key.
  • Scope the environment - run in a sandbox with limited file paths and an allowlist of network domains.
  • Gate escalation - require approval to widen permissions mid-task.

Assume the agent can be manipulated. Permissions then bound the worst case.

Example: an agent that summarizes support tickets needs read access to the ticket system only. Giving it write or delete access for convenience turns a hijacked session into a data-loss incident. Review permissions on a schedule, since tools added later tend to widen access quietly.

Take quiz
Which credential choice follows least privilege?
A permanent admin API key
A short-lived, narrowly scoped token
A shared team password
A network allowlist limits an agent to:
any site on the internet
no tools at all
approved domains only

43. How do you persist state across agent sessions?

Since the context window disappears when a session ends, anything worth keeping must be written outside it.

  • Progress files - a plain text or JSON file listing done, pending and blocked items.
  • Memory stores - key-value or vector stores for user facts and past decisions.
  • Version control - commits and notes that document what changed and why.

At the start of a new session, the agent reads these first to rebuild its bearings. Keep them short and structured, and update them as work is done, not only at the end.

Example progress file: done: [schema, API routes]; pending: [auth tests]; blocked: [staging credentials]. A fresh session reads that line and resumes at the right place without re-deriving everything. Avoid storing secrets in these files, because they are read back into context and may be logged.

Take quiz
Why must state be written outside the context window?
The model forbids long text
Tools cannot read files
The context is lost when the session ends
What should a new session do first?
Read the saved progress or memory
Delete old notes
Guess where it stopped

44. When should tool calls run in parallel?

Run them in parallel when they are independent, meaning no call needs another call's output, and when they are safe to run at the same time.

Parallel Sequential
Reading three separate files. Search for a file, then read the one found.
Checking weather in several cities. Create a record, then update that same record.

Parallel calls cut latency. Avoid them for writes that could conflict, or when rate limits would make bursts fail.

Most agent APIs let the model emit several tool calls in one turn. Your runtime then executes them concurrently and returns all results together, which makes the next model call one round trip instead of several. If one call in a parallel batch fails, return that error alongside the successes so the model can retry only the failed one.

Take quiz
Which pair of calls is safe to run in parallel?
Reading three unrelated files
Creating a record and then editing it
Searching for a file and then opening the result
What is the main benefit of parallel tool calls?
Smaller models
Lower latency
Fewer tools needed

45. How do you troubleshoot a skill that never triggers?

Work from the cheapest check to the most involved.

  1. Confirm it is installed and the folder structure and SKILL.md frontmatter are valid.
  2. Read the description as if you were the model. Does it name the task and the words users say?
  3. Test with an explicit request that clearly matches. If it still fails, the problem is likely loading, not wording.
  4. Check for overlap with another skill whose description is broader and wins.
  5. Rewrite and retest with several phrasings of the same request.

Remember that over-triggering is the opposite failure. If the skill fires on unrelated requests, narrow the description by naming the file types or situations where it applies. Keep a small test prompt set so every description edit can be checked quickly.

Take quiz
What is the first thing to confirm when a skill never triggers?
That the model temperature is zero
That it is installed with valid frontmatter
That the context window is empty
A broader skill with an overlapping description can cause:
your skill to run twice always
the model to be retrained
it to be chosen instead of yours

46. How do you trace and debug agents in production?

Record every step so you can replay a failed run exactly as the agent saw it.

  • Trace each run with a run ID: prompts, model responses, tool calls, arguments, results and timing.
  • Track metrics - success rate, steps per task, tokens, cost and error rate per tool.
  • Sample and review real transcripts regularly, including successful ones.
  • Turn failures into evals so the same bug cannot return unnoticed.

Redact secrets and personal data from logs, since traces contain everything the agent read.

Add alerts on signals such as unusual step counts, repeated identical calls, spikes in cost, and tool error rates. These often reveal a regression before users complain. Keep trace retention short and access-controlled, because transcripts can hold sensitive user data.

Take quiz
Why give each agent run an ID in traces?
To shrink the context window
To change the model version
So a failed run can be found and replayed
What should happen to a discovered production failure?
It becomes a new eval case
It is deleted from logs
It is ignored if rare

47. Explain the internal working of an MCP client-server exchange?

An MCP session starts with a handshake, then moves into discovery and calls, all as JSON-RPC messages over a transport such as stdio or streamable HTTP.

sequenceDiagram
  participant C as MCP Client
  participant S as MCP Server
  C->>S: initialize (capabilities)
  S-->>C: server capabilities
  C->>S: tools/list
  S-->>C: tool definitions
  C->>S: tools/call (name, arguments)
  S-->>C: result

The client's host application shows the discovered tool definitions to the model. When the model requests a tool, the client forwards it as tools/call, and the server's result goes back into the conversation.

Servers can also send notifications, for instance when their tool list changes, so a client can refresh what it shows the model. Capability negotiation in the first step means each side only uses features the other supports.

Take quiz
Which message asks an MCP server what tools it offers?
tools/list
tools/delete
model/train
The first step of an MCP session is:
a tools/call with arguments
an initialize handshake that exchanges capabilities
a full database dump

48. Why do too many tools hurt agent accuracy?

Every tool definition sits in the context, so a long tool list costs tokens on every call and gives the model more near-duplicates to confuse.

With dozens of tools, similar names and overlapping descriptions lead to wrong picks. Selection accuracy drops, and the model may skip the best tool for a mediocre one nearby.

Fixes include trimming to what the task needs, merging overlapping tools, grouping tools behind a router or subagent, and loading tool definitions on demand rather than all at once.

A useful target is to expose only the handful of tools a given task needs. If you truly need many, group them by domain and let a router or subagent pick the group first. Re-measure tool-selection accuracy in your evals each time you add a tool, so you notice the drop early.

Take quiz
Why does a long tool list reduce accuracy?
Tools stop working past ten
Overlapping tools are easier to confuse
The model forgets how to use JSON
One fix for a huge tool set is to:
add more similar tools
remove all descriptions
load tool definitions only when needed

49. What happens when a tool returns a very large result?

The result is appended to the context in full, so a huge output can eat most of the window, push out the goal and instructions, raise cost, and in the worst case cause the call to fail for exceeding the limit.

It also hurts quality. Important details get buried and the model may miss them.

Design tools to prevent it: paginate, accept filters and limits, return summaries with a pointer to details, or save the bulk to a file and return only the path and a preview.

Example: instead of returning 10,000 log lines, a search_logs tool returns the 20 best matches, a total count, and a cursor for the next page. The model gets what it needs and can ask for more.

Take quiz
What is a common way to handle large tool output?
Paste everything into the system prompt
Disable the context window
Paginate or return a summary with a pointer
A giant tool result mainly risks:
crowding out the goal and instructions
improving model memory
reducing token cost

50. Why should skills bundle executable scripts?

Scripts give a skill deterministic behavior for steps where the model should not improvise, such as parsing a file, validating a form or converting a format.

They also save tokens. The agent runs the script and only the output enters the context, rather than the model generating, or re-reading, the same code each time.

Bundle a script when the task is repetitive, error-prone to write from scratch, or needs exact output. Keep the SKILL.md focused on when to run it and how to interpret what it prints.

Example: a spreadsheet skill can include a script that recalculates formulas and reports any error cells. The agent runs it after every edit, so correctness checking never depends on the model remembering to do it.

Take quiz
What enters the context when a bundled script runs?
Its output
The full script source every time
The whole skill folder
Scripts are best suited to steps that are:
purely creative writing
repetitive and need exact, repeatable results
impossible to automate
«
»

Comments & Discussions