Design GenAI Fine-Tuning and Agent Tradeoffs
Two SigmaSoftware Engineer · Technical ScreenLast updated
Design an enterprise GenAI research agent platform, evaluating trade-offs between fine-tuning methods (Full, LoRA, QLoRA) versus RAG, alongside agent orchestration, structured outputs, and safety controls.
Scenario
Design an internal financial research agent for a quantitative hedge fund. Quantitative researchers and analysts will use this agent to parse unstructured market reports, analyze earnings call transcripts, extract key financial metrics, and execute multi-step research workflows (e.g., pulling internal factor risk exposures, running custom backtests, and summarizing regulatory filings).
The platform must deliver accurate, deterministic data for downstream quantitative models while supporting conversational research exploration.
Functional Requirements
- Domain Adaptation: Adapt open-source foundation models (e.g., Llama-3-70B) to understand proprietary firm terminology, financial metrics, and specific tabular extraction formats.
- Agentic Workflow: Support multi-step tool use, including querying internal timeseries databases, searching vector stores of SEC filings, and invoking backtest APIs.
- Deterministic Output: Output structured JSON schemas validated against strict type constraints for programmatic ingestion.
- Guardrails & Auditability: Provide end-to-end tracing, tool execution validation, hallucination detection on numerical figures, and full reproducibility.
Non-Functional Requirements
- Throughput & Scale: Support ~1,000 concurrent researchers, averaging 50,000 agent interactions per day, with peak spikes during earnings seasons (up to 5x).
- Latency: Single-turn tool execution P95 < 2.5 seconds; multi-step agent research workflows P95 < 12 seconds.
- Resource Constraints: Maximize GPU utilization across limited internal clusters (e.g., NVIDIA H100/A100 nodes).
- Reliability: Agent loops must terminate safely with zero infinite loops and graceful fallback if intermediate tools fail.
What Your Design Should Cover
- Model Adaptation Trade-offs: Compare Full Fine-Tuning (FFT), LoRA, QLoRA, and pure in-context learning (RAG). Discuss memory footprint, training throughput, serving costs, and catatrophic forgetting risks for each.
- Agent Architecture & Orchestration: Define the agent pattern (ReAct, Plan-and-Solve, or DAG-based state machines). Detail state management, tool execution sandboxing, and context window budget management.
- Schema Validation & Constrained Decoding: Compare system prompt enforcement, function calling APIs, and grammar-constrained decoding (e.g., outlines, JSON schema masks at logit generation).
- Serving & Multi-Adapter Infrastructure: Architecture for serving multiple task-specific adapters on a shared base model (e.g., vLLM Multi-LoRA / S-LoRA).
- Observability & Evaluation: Metrics for agent step-success rates, tool choice accuracy, and numerical hallucination auditing.
Hints
Hint 1
Consider the memory savings of adapter-based approaches (LoRA/QLoRA) during inference, specifically how frameworks like S-LoRA dynamic-batch multiple adapters over a single base model.
Hint 2
For enforcing structured JSON output, evaluate why prompt-based validation is insufficient for production pipelines and how logit-bias or grammar-constrained decoding guarantees valid schemas.
Hint 3
Distinguish between when domain knowledge should live in model weights (fine-tuning) versus when it should be dynamically retrieved (RAG and live API calls).
Follow-up questions
- If an analyst detects that the agent extracted an incorrect revenue number from an SEC filing, how does your system trace the root cause (retrieval vs. extraction vs. tool execution)?
- How does your multi-LoRA serving layer manage memory fragmentation and dynamic routing when switching between different specialized adapters at runtime?
- Under what specific criteria would you decide to upgrade from a QLoRA fine-tuned 8-bit model to a Full Fine-Tuning 16-bit run?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.