KatInterview

Design a Governed AI Agent for Automated Trade Execution

System DesignModel answer
HardModel answerSystem Designagentic-systemsfinancial-infrastructurerisk-management

Last updated

Design a safety-first, ML-driven order generation system with deterministic validation gates, idempotent execution, and a fully replayable audit trail.

Context

A large asset management firm runs hundreds of investment strategies across equities, futures, and FX derivatives. Each strategy has a target allocation that drifts over time as markets move. You are asked to design an AI-driven rebalancing agent that continuously monitors these drift signals and alpha model outputs, then proposes corrective trades.

Because ML and LLM-based systems can produce unreliable outputs under unusual market conditions, no model-generated trade instruction may reach an execution venue directly. Every proposed order must clear a sequence of deterministic rule checks and, where warranted, receive explicit human sign-off before anything is routed.

Functional Requirements

  • Proposal engine: Consume target weights, live positions, cash balances, and market feeds to produce structured trade proposals: instrument, side, quantity, notional, and order type.
  • Governance pipeline: Every proposal must pass through, in order:
    • A freshness check verifying that prices and positions have not moved beyond tolerance since the proposal was generated.
    • Entitlement and mandate checks: restricted instruments, leverage ceilings, sector concentration caps.
    • Hard pre-trade risk checks: value-at-risk limits, drawdown caps, liquidity constraints.
    • An escalation layer routing large or sensitive orders to a human approval workflow.
  • Execution with exactly-once semantics: Proposals that clear all gates must be routed without duplicates even under retries or partial failures.
  • Immutable audit trail: Every event — proposal, tool call, check outcome, human decision, fill — must be stored in a way that allows full reconstruction of what happened and why.

Non-Functional Requirements

  • Scale: ~5,000 active strategies, up to 100,000 candidate orders per rebalancing window.
  • Latency: Under 500 ms end-to-end for automated paths; sub-second dashboard updates for human reviewers.
  • Isolation: No cross-strategy information leakage. Proprietary signals must stay within their owning strategy pod.

What Your Answer Should Cover

  1. Component architecture: How the agent, state store, governance engine, and order router fit together, and why those boundaries exist.
  2. Typed data model: What the proposal and validation records look like as structured schemas (not free-form text).
  3. Validation sequence: The ordered checks between proposal generation and execution, and the rationale for that ordering.
  4. Concurrency and freshness: How the system handles race conditions when market data changes between when a proposal is generated and when it is approved.
  5. Exactly-once routing: The mechanism that prevents duplicate orders under retries or node failures.
  6. Audit and replay: How the event log is structured so that any past decision can be reconstructed offline.
  7. Security and isolation: How the system prevents alpha leakage and keeps execution credentials away from the model layer.

Hints

Hint 1

Start by drawing a strict privilege boundary: the agent can read state and write proposals, but it should hold zero execution credentials. Ask yourself what would happen if the model were compromised or hallucinated a large order.

Hint 2

The freshness check is not just 'is the data recent?' — it needs to compare the exact snapshot version the model used against the current version and compute actual drift in bps. A stale-but-within-tolerance proposal should be re-priced and allowed through; only genuinely stale proposals should be rejected.

Hint 3

Exactly-once execution in a distributed system is really idempotent at-least-once. Make the order ID deterministic (hash of plan ID and leg index), use an outbox pattern to durably record the routing intent before sending to the venue, and rely on the venue rejecting duplicate client order IDs.