Design an AI Agent That Processes a Data Stream
Build a service where an AI agent reads events from a live stream, decides what to do with each one and acts through a small set of tools, keeping up with the stream and never doing the same action twice.
Problem statement
Design a service where an AI agent processes a live stream of events. For this exercise, assume that for each event a team cares about, the agent reads it, decides what to do and acts through a small set of tools, and that the service must keep up with the stream without doing any action twice.
For this exercise, assume the company's services already publish events to a shared event stream: order updates, customer messages, device alerts and so on.
Each event has an ID, a type, a time, an entity key (the order, customer or device it is about) and a payload (the event's contents), which may include free text written by customers.
For this exercise, assume a team sets up an agent task with four parts: which events it handles (a filter on event type and fields), a priority (high, normal or low), a written instruction for the agent, and the tools the agent may call, such as look up an order, add an internal note, message a customer or cancel an order; some tools need a person's approval before they run.
The tools are other teams' existing services. For each matching event, an agent run reads the event and recent events for the same entity, asks an LLM (large language model) what to do, and calls tools until it is done.
Out of scope: training or tuning the model, building the tools themselves, and the screens for writing instructions.
What to build
- A team can create an agent task, change it (each change makes a new version) and pause it.
- Every event that matches an active task is handled by an agent run that reads the event and the entity's recent events, decides, and acts only through the task's tools. An event the service cannot handle is recorded as skipped with a reason, never silently lost.
- Each action a run decides on takes effect at most once, even when a run crashes and is retried or the stream delivers an event again.
- Operators can see each run (the event, the agent's decisions, each tool call and its result) and approve or reject actions that need approval.
At scale
- For this exercise, assume the stream carries about 50,000 events a second on average and up to 200,000 a second in peaks lasting up to 30 minutes, and about 2% of events match an active task: about 1,000 a second on average and 4,000 at peak.
- For this exercise, assume all tasks share one model quota of about 1,000 model calls a second, and a run usually makes 2 to 3 model calls.
- For this exercise, assume a matching event should normally be handled within 1 minute of arriving; in a peak, delays are acceptable, but every matching event is handled or recorded as skipped with a reason.
- For this exercise, assume the stream keeps events for 7 days and delivers each event at least once, sometimes again after a failure; runs, decisions and tool calls are kept for 90 days.