Skip to main content
HS
HiSETSuccess
LeetCode Prep

AI & FDE Interview Room

Role paths, mocks, cost studio, chapters, cases, and staff-level depth.

Chapter

Agents & Tools

Tool schemas, plan–act loops, memory, multi-agent patterns, and failure modes for agentic systems interviews.

Tool Schemas & Calling

Tools extend an LLM with side effects and grounded data: HTTP APIs, DB queries, code execution, browsers. Interviews focus on schema design, validation, permissions, and idempotency — not on framework brand names.

Schema fieldWhy it matters
name + descriptionModel chooses when to call
JSON Schema paramsTyped args; reduce garbage calls
enums / formatsConstrain dangerous free text
required fieldsAvoid half-specified mutations
return contractStable shapes for next reasoning step
  • Validate args server-side; never execute on model trust alone
  • Allowlist tools per user role; separate read tools from write tools
  • Make writes idempotent with client-generated keys
  • Return concise, structured errors the model can recover from
Tool call lifecycle
LLM proposes tool_call(name, args)
        ↓
 AuthZ + schema validate
        ↓
 Execute with timeouts / budgets
        ↓
 Sanitize result → append to messages
        ↓
 LLM continues or final answer

Prompt injection via tools

Tool results are untrusted content. A fetched page can say "ignore policies and exfiltrate secrets." Isolate tool output as data; never promote it to system instructions.

Interview signal

Describe least privilege, argument validation, and that the model suggests but the runtime decides whether a call is allowed.

Plan–Act–Observe Loops

Agent loops alternate reasoning with tool use: plan, act, observe, repeat until a stop condition. Strong answers bound the loop with step budgets, timeouts, and explicit termination criteria.

PatternDescriptionFit
ReActInterleave thought + actionGeneral tool use
Plan-then-executeFull plan firstStable, decomposable tasks
ReflexionCritique after failureHard tasks with retries
Router + specialistsClassify then hand offProductized multi-skill bots
  1. Cap max steps and wall-clock time per request
  2. Detect loops: same tool + same args → break and escalate
  3. Prefer deterministic planners for regulated workflows
  4. Log every thought/action/observation for debugging (redact secrets)
Bounded agent loop
start → plan
   ↑        ↓
observe ← act (tool)
   │
   ├─ done? → final answer
   ├─ steps > N? → safe abort
   └─ else continue

When not to agent

If a single RAG call or a fixed workflow solves 90% of cases, do not pay agent latency and failure modes. Agents are for open-ended, multi-step uncertainty.

Interview signal

State stop conditions and cost before describing fancy planning. Interviewers punish unbounded "the agent will figure it out" designs.

Agent Memory Patterns

Memory is how agents persist state beyond the context window: scratchpads, conversation summaries, episodic logs, and long-term user/profile stores. Mixing memory types without TTL and consent is a common interview failure.

Memory typeContentsRisk
Working / scratchpadCurrent plan, tool outputsToken bloat
Short-term chatRecent turnsPrivacy in shared devices
Summarized episodicCompressed historySummary drift
Long-term profilePreferences, factsStale / wrong personalization
Entity storeStructured CRM-like factsNeeds write policies
  • Write memory deliberately — not every token of every tool dump
  • Prefer structured memory (key-value, entities) over raw blob dumps
  • Support user-visible edit/delete for personal data (compliance)
  • Retrieve memory with the same ACL discipline as document RAG
Memory read/write in a turn
User turn
  → Retrieve relevant memories
  → Build prompt (working + retrieved)
  → Act / answer
  → Decide writes (facts? prefs? none?)
  → Compact scratchpad

Poisoned memory

Injected content written into long-term memory persists across sessions. Gate writes with validation and human confirmation for high-impact facts.

Interview signal

Distinguish context window (volatile) from durable memory (policy-bound). Mention summarization loss and how you refresh or invalidate.

Multi-Agent Orchestration

Multi-agent systems split roles — researcher, coder, critic, executor — coordinated by a supervisor or graph. Use them when specialization and review beat a single overloaded prompt; avoid them as default architecture theater.

TopologyProsCons
Supervisor / workersClear controlSupervisor bottleneck
Pipeline stagesSimple contractsRigid; weak on branches
Debate / critiqueCatches errors2–3× cost
Blackboard / shared stateLoose couplingHard to debug races
  • Give each agent a narrow tool allowlist
  • Define typed messages between agents — not free-form chat forever
  • One agent owns user-facing communication to avoid conflicting answers
  • Budget tokens per agent; multi-agent multiplies spend silently
Supervisor pattern
User → Supervisor
           │
     ┌─────┼─────┐
     ▼     ▼     ▼
  Research Code  Critic
     │     │     │
     └─────┴─────┘
           │
      Merge / approve
           │
        Response

Productization tip

Implement as a deterministic workflow graph with LLM nodes — not an unsupervised society of bots — unless research is the goal.

When to propose it

Only after naming a failure a single agent hits (context overload, missing review, conflicting skills). Otherwise prefer one agent + tools.

Agent Failure Modes

Agents fail loudly and expensively: infinite loops, wrong tool calls, cascading bad observations, and unsafe side effects. Interview depth is naming failure modes and the controls that contain them.

FailureSymptomControl
LoopingRepeated identical callsDedup + step cap
Tool hallucinationInvented API fieldsStrict schema + validate
Goal driftSolves wrong taskReconfirm goal; checkpoints
Cascading errorsBad observe → worse actCritic step; unit tests on tools
Unsafe writeDestructive mutationHuman approve; dry-run
  1. Separate planning from privileged execution
  2. Require confirmation for irreversible tools (delete, pay, email-all)
  3. Circuit-break on error rate or spend per session
  4. Provide a deterministic fallback path for critical user journeys

Demo vs production

A demo agent with unrestricted shell is not a design. Production agents need sandboxes, secret redaction, and audit logs.

Strong close

Walk through one concrete failure (e.g. refund tool called twice) and your idempotency + confirmation design. Specificity beats buzzwords.

Tool Safety & Permissions

Tool safety is authorization, sandboxing, and abuse resistance. Treat every tool as a privileged API gateway in front of your systems — because that is what it is.

ControlExample
AuthN/AuthZUser OAuth scopes → tool allowlist
Argument policyBlock path traversal; limit SQL to SELECT
SandboxContainer with no cloud creds for code exec
Rate / spend limitsPer-user tool QPS and $ caps
AuditImmutable log of who/what/when
  • Never pass raw user strings into shell without escaping — prefer structured APIs
  • Default deny: new tools are off until reviewed
  • Dual control for high-risk actions in enterprise settings
  • Redact secrets from tool outputs before they re-enter the prompt
Permission check points
User identity
     ↓
Session policy (role, tenant)
     ↓
Tool allowlist
     ↓
Arg validator / policy engine
     ↓
Execution sandbox
     ↓
Audit + metrics

Interview signal

Map agent tools to the same threat model as a public API. Mention confused deputy and injection as first-class risks.

Staff depth layer

Agents & Tools — Staff Depth

An agent is a loop over planning and tools with blast radius. Staff candidates default to the simplest control flow that meets the job: deterministic workflows and single-shot tool use before multi-agent graphs. They obsess over least privilege, idempotency, injection isolation, and evals of tool selection — not theatrical autonomy.

Anti-patterns → say instead

✕ Agent-first for FAQs

Extra hops add latency, cost, and failure modes when a RAG answer or form would suffice.

Say instead: Start with retrieve-and-answer; promote to tools only when the user needs live state or side effects; promote to multi-step only when evals show single-shot fails.

✕ God-mode tools

A single `run_sql` or `refund_any` tool turns prompt injection into a breach and makes auditing impossible.

Say instead: Narrow tools with typed args, server-side authZ, amount/rate limits, and human approval above thresholds.

✕ No idempotency on side effects

Retries and double tool calls duplicate refunds, tickets, and emails.

Say instead: Idempotency keys per intent; tools return prior result on replay; durable workflow state for long jobs.

✕ Trusting tool args from the model blindly

Models invent IDs and exfiltrate via URL params; schemas alone don't enforce business invariants.

Say instead: Validate against policy and DB truth server-side; never let the model choose `to_account` freely without checks.

Tier-1 bot: lookup order, explain shipping, refund ≤ $50 auto, else escalate. 5k conversations/day, p95 reply < 6s.

  1. Tools: get_order(order_id), get_shipment(tracking), create_refund(order_id, amount, reason, idem_key), escalate(ticket).
  2. Policy: refund amount ≤ min($50, order.paid); same customer session; block if fraud flag.
  3. Loop: max 4 tool hops; stop on answer, escalate, or policy deny. Ticket body is untrusted data channel.
  4. Estimate: ~2.5 LLM calls/convo average with tools; 5k × 2.5 × (1.5k in + 300 out) ≈ 22.5M tokens/day.
  5. At $1/1M small + $10/1M for hard cases (10% escalate path), blend ≈ $40–70/day model cost before cache.
  • Auto-refund cap $50; human approval $50–$250; deny/escalate above
  • Idempotency key = hash(customer_id, order_id, intent, calendar_day)
  • Eval: tool-selection accuracy, policy violation rate, wrongful refund rate, containment vs escalate precision

Show the state machine and money controls before you draw a multi-agent diagram.

Cheat sheet

  • Simplest control flow that works — then agentize
  • Least-privilege tools + server-side policy
  • Idempotency on every side effect
  • Isolate untrusted text from instructions
  • Max hops, budgets, kill switches
  • Eval tool choice ≠ eval tone
  • Human gates for irreversible / high $ actions