Clear
Your agent must run reliably, but your single LLM provider had an outage that took your whole product down.
How would you design the system for resilience against provider outages?
General Medium

Answer:

  1. Add fallback providers: Route to a backup model when the primary fails, so outages don't halt you.

  2. Abstract behind a gateway: Wrap providers uniformly, so failover is seamless.

  3. Use circuit breakers: Stop calling a failing provider and switch fast, so you don't hang on a dead one.

  4. Degrade gracefully: Serve cached or reduced responses during outages, so users retain some function.

  5. Monitor provider health: Track latency and errors, so failover triggers before users notice.

Your agent's retrieval returns relevant chunks, but the model's answers ignore chunks that appear in the middle of a long context.
How would you design the system to counter the lost-in-the-middle effect?
General Medium

Answer:

  1. Rerank and position well: Place the most relevant chunks at the start and end, so they aren't lost in the middle.

  2. Limit context size: Provide fewer, more relevant chunks, so nothing important is buried.

  3. Rerank aggressively: Ensure only the best chunks are included, so the model isn't diluted.

  4. Force multi-source citation: Require citing several chunks, so the model must engage with all provided context.

  5. Test middle-context recall: Evaluate whether mid-context facts are used, so the effect is measured.

Your agent batches requests to improve GPU throughput, but latency-sensitive requests get stuck waiting for a batch to fill.
How would you design batching to balance throughput against latency?
General Medium

Answer:

  1. Use continuous batching: Add and remove requests dynamically like vLLM, so requests don't wait for a full batch.

  2. Set a max wait time: Flush partial batches after a deadline, so latency is bounded.

  3. Separate latency tiers: Batch throughput-oriented work separately from interactive, so each gets suitable handling.

  4. Size batches adaptively: Adjust batch size to load, so you balance throughput and latency dynamically.

  5. Prioritize interactive requests: Let latency-sensitive ones jump the queue, so they aren't stuck.

Your agent's prompt injection defenses catch known attacks, but a novel injection in a retrieved web page still got through.
How would you design defense-in-depth against prompt injection?
General Medium

Answer:

  1. Separate instructions from data: Structurally delimit untrusted content, so it's treated as data, not commands.

  2. Apply least privilege: Limit tool scopes and credentials, so a successful injection has limited blast radius.

  3. Gate high-impact actions: Require confirmation for consequential steps, so injection can't complete damage alone.

  4. Block untrusted-driven egress: Prevent data flowing to endpoints suggested by content, so exfiltration is stopped.

  5. Red-team continuously: Probe with novel injections, so defenses evolve against new attacks.

Your agent quantized its model to save memory, but quality dropped on exactly the hard cases that matter most.
How would you design the process to quantize without losing critical quality?
General Medium

Answer:

  1. Evaluate on hard cases: Test quantized quality on the cases that matter, so degradation is measured where it counts.

  2. Choose the right method: Compare AWQ, GPTQ, and FP8 for your model, so you pick the least lossy.

  3. Try mixed precision: Keep sensitive layers at higher precision, so critical quality is preserved.

  4. Tune the trade-off: Balance memory savings against quality loss, so you don't over-quantize.

  5. Validate before deploying: Confirm quantized quality meets the bar, so regressions don't ship.

Your RAG agent handles questions that need information from multiple hops — the answer to one lookup drives the next — but it retrieves once and fails.
How would you design the system for multi-hop retrieval?
General Medium

Answer:

  1. Retrieve iteratively: Use each hop's result to form the next query, so chained lookups work.

  2. Decompose the question: Break multi-hop questions into sub-questions, so each hop is explicit.

  3. Track intermediate findings: Carry results across hops, so later retrieval builds on earlier.

  4. Bound the hops: Cap iterations, so multi-hop retrieval doesn't run away.

  5. Verify the chain: Check each hop's result supports the next, so errors don't compound.

Your multi-agent system deadlocks when two agents each wait for the other to act.
How would you design the system to prevent and break agent deadlocks?
General Medium

Answer:

  1. Use a supervisor: Have a coordinator break ties and assign turns, so agents don't circularly wait.

  2. Set timeouts: Bound how long an agent waits, so deadlocks self-resolve.

  3. Order resource acquisition: Impose a consistent acquisition order, so circular waits can't form.

  4. Detect cycles: Monitor for mutual waiting, so deadlocks are caught and broken.

  5. Define clear ownership: Assign task ownership unambiguously, so agents don't both wait to act.

Your agent uses an LLM judge to grade outputs, but its scores contradict human reviewers on borderline cases.
How would you design the system to make the LLM judge trustworthy?
General Medium

Answer:

  1. Calibrate against humans: Validate judge scores on a human-labeled set, so agreement is measured.

  2. Use explicit rubrics: Grade against clear, granular criteria, so scoring is consistent.

  3. Control for bias: Counter position, length, and self-preference effects, so scores aren't skewed.

  4. Ensemble judgments: Average multiple runs or models, so variance drops.

  5. Audit disagreements: Review judge-human mismatches, so systematic errors are found and corrected.

Your agent uses KV-cache to speed up generation, but under high concurrency the cache memory runs out and requests start failing.
How would you design the system to manage KV-cache memory under load?
General Medium

Answer:

  1. Use paged attention: Allocate KV-cache in pages like vLLM, so memory is used efficiently and fragmentation drops.

  2. Cap concurrent sequences: Limit simultaneous generations to what memory allows, so you don't over-commit.

  3. Evict or preempt: Swap out lower-priority sequences when memory is tight, so high-priority ones proceed.

  4. Bound context length: Limit sequence length, so per-request cache stays predictable.

  5. Monitor cache pressure: Track memory usage, so you throttle before failures occur.

Your agent works, but when it fails, you have logs from five different systems and no way to see the full request flow.
How would you design observability to trace a request across all systems?
General Medium

Answer:

  1. Propagate a trace ID: Attach one correlation ID from entry through every system, so the flow is linkable.

  2. Centralize telemetry: Aggregate logs and metrics in one place, so you don't chase five dashboards.

  3. Log at each hop: Capture input and output at every stage, so the path is reconstructable.

  4. Visualize the trace: Render the full request flow, so failures are locatable at a glance.

  5. Correlate across systems: Link related events by trace ID, so the complete picture assembles.

Your agent's quality is inconsistent, and you suspect the prompt but have no systematic way to test prompt variations.
How would you design the process to systematically optimize prompts?
General Medium

Answer:

  1. Test against an eval set: Measure each prompt variant on a fixed set, so improvements are objective.

  2. Change one thing at a time: Vary single elements, so impact is attributable.

  3. Ablate sections: Remove parts to find what matters, so dead weight is identified.

  4. Version prompts: Track variants and their scores, so you can compare and revert.

  5. Guard against overfitting: Validate on held-out cases, so gains generalize.

Your agent processes user files, but a maliciously crafted file caused it to execute unintended behavior.
How would you design the system to safely handle potentially malicious files?
General Medium

Answer:

  1. Validate and scan files: Check type and scan for threats before processing, so malicious files are caught.

  2. Sandbox parsing: Extract content in isolation, so a malicious file can't compromise the system.

  3. Treat content as untrusted: Never let file content issue instructions, so injection via files is blocked.

  4. Limit resource use: Cap file size and processing, so files can't exhaust resources.

  5. Fail safely: Handle unparseable or suspicious files cleanly, so failures don't cause harm.

Your agent's LLM occasionally returns a refusal or safety response to a legitimate internal request, breaking an automated pipeline.
How would you design the system to handle unexpected model refusals in automated flows?
General Medium

Answer:

  1. Detect refusals: Recognize when the model declined rather than answered, so it's not treated as valid output.

  2. Retry with rephrasing: Reformulate and retry legitimate requests, so occasional refusals are overcome.

  3. Provide clear context: Frame internal requests to avoid triggering refusals, so they succeed.

  4. Fall back gracefully: Handle persistent refusals without crashing, so the pipeline continues.

  5. Log refusal patterns: Track what triggers them, so recurring false refusals are addressed.

Your agent runs fine at current load, but you're about to 10x traffic and don't know if it will hold.
How would you design the process to validate the system will scale before the traffic arrives?
General Medium

Answer:

  1. Load-test at target scale: Simulate 10x traffic, so you find limits before production does.

  2. Identify bottlenecks: Determine what breaks first, so you know where to reinforce.

  3. Test dependencies too: Load the vector DB, provider limits, and tools, so the weakest link surfaces.

  4. Verify horizontal scaling: Confirm adding capacity actually helps, so scaling works as assumed.

  5. Provision headroom: Ensure capacity ahead of the ramp, so you're not scrambling.

Your agent handles document Q&A, but when a document is updated, cached answers based on the old version stay wrong.
How would you design the system to keep answers consistent with updated documents?
General Medium

Answer:

  1. Link answers to document versions: Track which version each answer used, so staleness is detectable.

  2. Invalidate on update: Clear cached answers when their source document changes, so stale ones aren't served.

  3. Re-index changed documents: Update retrieval when documents change, so new answers use current content.

  4. Version cache keys: Include document version in keys, so updated docs miss stale cache.

  5. Verify freshness on serve: Check the answer's source is current, so staleness is caught.

Your agent's answers depend on a config file that a teammate edited, and now it behaves differently with no code change to blame.
How would you design the system to make config changes traceable and safe?
General Medium

Answer:

  1. Version config: Track config in source control with history, so changes are auditable.

  2. Require review: Gate config changes behind approval, so risky edits are caught.

  3. Validate on load: Check config against a schema, so invalid values are rejected.

  4. Tag requests with config version: Record which config each request used, so behavior maps to config.

  5. Enable fast rollback: Revert config independently, so a bad change is quickly undone.

Your agent generates SQL from natural language, but a generated query once locked a production table and caused an outage.
How would you design the system to make generated SQL safe to run?
General Medium

Answer:

  1. Enforce read-only access: Run generated SQL under a restricted account, so it can't write or lock harmfully.

  2. Validate before executing: Parse and check the query against an allow-list, so dangerous queries are blocked.

  3. Set query limits: Apply row limits and timeouts, so runaway queries are bounded.

  4. Run against a replica: Execute on a read replica, so production isn't affected.

  5. Preview before running: Show the query for confirmation on risky operations, so users catch problems.

Your agent's retrieval works, but users searching for exact phrases or codes get poor results because semantic search fuzzes them.
How would you design retrieval to handle both exact and semantic matches?
General Medium

Answer:

  1. Use hybrid search: Combine keyword and vector search, so exact and semantic queries both work.

  2. Detect exact-match intent: Route code and quoted phrases to keyword search, so precision is preserved.

  3. Weight by query type: Favor keyword matching for identifiers and semantic for concepts, so each fits.

  4. Index for exact match: Maintain a keyword index alongside vectors, so exact lookups are fast.

  5. Merge and rerank: Combine both result sets and rerank, so the best of each surfaces.

Your agent uses speculative execution to cut latency, but the wasted work on wrong guesses is inflating your costs.
How would you design speculative execution to balance latency against wasted cost?
General Medium

Answer:

  1. Speculate only on likely paths: Prefetch high-probability next steps, so waste stays low.

  2. Gate on cost: Skip speculation for expensive operations, so wrong guesses don't cost much.

  3. Cancel early: Abort speculative work once the real path is known, so waste is minimized.

  4. Speculate for latency-critical paths only: Reserve it where speed matters most, so cost is justified.

  5. Measure the trade-off: Track wasted cost against latency saved, so speculation stays worthwhile.

Your agent's eval scores are high, but production quality is clearly worse, and the gap is growing.
How would you design the process to close the eval-production gap?
General Medium

Answer:

  1. Build evals from production: Source test cases from real traffic, so evals reflect actual usage.

  2. Include the hard long tail: Add real edge cases, so evals aren't dominated by easy ones.

  3. Match production conditions: Test with realistic noise and formats, so results predict reality.

  4. Correlate eval with live metrics: Check that eval wins translate to production gains, so you trust the evals.

  5. Refresh continuously: Feed new production failures into evals, so the gap doesn't reopen.