AI Engineer World's Fair 2026
Let's integrate AI Agents in Event-Sourced Systems
Loading slides…
Read the talk
Let's integrate AI Agents in Event-Sourced Systems
A declined laptop purchase exposes the missing context in fraud decisions. Event projections and a two-tier orchestrator give agents a bounded role inside an existing payment workflow.
From a talk by Divakar Kumar
Before you start: Familiarity with asynchronous messaging, database read models, and basic agent tool use will help you follow the architecture.
Why was the purchase declined?
Divakar Kumar waited for an offer before buying the laptop he uses for this presentation. It cost roughly $3,500. He entered his card details, clicked Buy, and the transaction was declined. Assuming a network problem or an input mistake, he tried again. The second attempt failed too. Before a third attempt, customer service called to ask whether he was making the purchase.
He confirmed that he was, then asked why the transaction had been blocked. Customer service could not explain it. Kumar suspected that a rules engine or an ML model had reacted to his transaction history or an amount threshold, but the actual cause remained unknown. The system had made a consequential decision without giving the person handling the customer a useful explanation.
Adding a nondeterministic agent to an already uncertain decision sounds risky. The opportunity here is to give that agent something the existing decision path lacks: enough real-time context to assess an ambiguous transaction. Relevant evidence exists across the business, but it lives in separate domain boundaries. The architectural problem is to gather that evidence and make it available at the point of decision.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Keep the existing engine; escalate the gray zone
Kumar’s team had used a rules engine about five years earlier. It worked for familiar cases, but changing fraud tactics demanded continual updates to static rules. The team then worked with a third-party provider to train an ML model using transaction history and other features. Its risk score supplied another way to approve or block a transaction.
Both approaches could handle clear decisions: approve below a risk threshold and block above another. The difficult cases fell between those boundaries. Instead of replacing the existing systems, the team added a second processing tier for this gray zone.
| Tier | Mechanism | Responsibility |
|---|---|---|
| Tier one | Rules or traditional ML | Handle clear approval and rejection cases |
| Tier two | Agentic analysis | Examine ambiguous cases using additional context |
The agent is an escalation path inside the business workflow. No numerical thresholds are specified; the design separates routine decisions from cases that need further investigation.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Connect the evidence across bounded contexts
The transaction context knows the merchant, amount, and other transaction details. It does not own the customer profile, payment history, or device information. These are separate bounded contexts: each maintains its own domain model, with explicit integration relationships between them. The boundary does not prohibit exchanging information; it prevents one context from treating another’s internal model as its own. In Kumar’s architecture, communication between these services is asynchronous.
The other contexts supply different kinds of evidence:
- Accounts: Customer information and know-your-customer, or KYC, compliance.
- Devices: Device fingerprints, browser fingerprints, and operating systems.
- Payments: Payment information, including chargebacks.
Each context has useful evidence, but none alone provides the full picture needed for an ambiguous fraud decision.
The team extended an existing orchestration layer to include agentic processing. It behaves like a saga orchestrator, coordinating work across services while a message broker carries events to interested consumers. This gives the agent a place in the existing business process and preserves the event-based communication between contexts.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Turn event history into queryable context
Inside the transaction context, a transaction-created domain event starts the transaction’s lifecycle. Integration events arrive from other contexts; Kumar’s examples include transaction rejected, payment approved, and payment rejected. The team stores these facts in Azure Cosmos DB, using event sourcing: commands lead to recorded business events, and the store appends those events instead of overwriting the transaction’s history with its latest state.
The next step is to make that history efficient to read. The Cosmos DB change feed notifies consumers of changes so they can update read-optimized projections. Current platform semantics matter when implementing this path: ordering is within partition keys rather than global, and the change-feed processor provides at-least-once delivery. Consumers therefore need to tolerate repeated delivery. Kumar separates read models for timelines, customer information, and fraud indicators rather than querying the raw event stream for every question.
Other teams do not have to adopt event sourcing to participate. They can publish integration events through a message broker. A worker consumes those messages, transforms them, and updates the projection layer. Whether changes arrive through CDC or through the broker, the destination is a cross-context materialized view, which Kumar also calls the semantic layer. Here, “semantic” means context assembled for the agent to use; it does not require every source system to share a storage model.
A small TypeScript projection illustrates the worker’s job. A new transaction updates a customer’s count and total, while an already-seen event leaves the projection unchanged:
typescript
type TransactionCreated = {
id: string;
customerId: string;
amountCents: number;
};
type CustomerProjection = {
customerId: string;
transactionCount: number;
totalAmountCents: number;
appliedEventIds: string[];
};
function projectTransaction(
current: CustomerProjection,
event: TransactionCreated,
): CustomerProjection {
if (event.customerId !== current.customerId) {
throw new Error("Customer mismatch");
}
if (current.appliedEventIds.includes(event.id)) return current;
return {
...current,
transactionCount: current.transactionCount + 1,
totalAmountCents: current.totalAmountCents + event.amountCents,
appliedEventIds: [...current.appliedEventIds, event.id],
};
}
const before: CustomerProjection = {
customerId: "customer-7",
transactionCount: 2,
totalAmountCents: 10000,
appliedEventIds: ["event-1", "event-2"],
};
const event: TransactionCreated = {
id: "event-3",
customerId: "customer-7",
amountCents: 350000,
};
const after = projectTransaction(before, event);
// Count: 3; total: 360000 cents. Reapplying event-3 changes nothing.
These teaching values make the transformation concrete. The worker produces a queryable summary; it does not decide whether the purchase is fraudulent. In a persistent consumer, the projection update and duplicate-delivery bookkeeping need to be committed atomically.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Give the agent tools—and a stopping point
The agent combines three components: a language model, tools, and memory. The model need not be a large proprietary model; Kumar allows for small language models and open-source models. Tools connect its reasoning to external APIs or methods in the application layer.
For this fraud workflow, the team uses short-term, in-memory state. Kumar states a transaction-processing requirement of under 500 milliseconds. That is an SLA target, not a measured result shown in the talk. It motivates keeping the agent’s working context short-lived and limiting the work performed during a decision.
The execution loop is straightforward:
- Decompose the incoming task into smaller tasks.
- Process those tasks using the model and available tools.
- Check whether the goal has been reached.
- Continue only while further work is needed and the stopping condition permits it.
Kumar mentions use-case-specific metrics for breaking out of the loop, without specifying their values. The essential constraint is that the agent cannot keep investigating indefinitely while a payment waits.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Fan out the investigation, then return an event
The transaction aggregate emits an event that is translated into an integration event and sent through the broker to orchestration. Separate sub-orchestrators handle the two tiers. Tier one runs the existing rules or ML processing; tier two fans an escalated event out to a risk analyzer and a behavior analyzer. Each investigates through its own tools, and both return their responses to a verdict stage.
That verdict stage can be a metric, an application-level if condition, or another agent. Kumar reports false positives with metric-based verdicts and describes trying a third agent to synthesize the two specialist responses. He does not provide a quantified improvement. The resulting verdict is emitted back to the message broker, allowing the saga to proceed into the payment context and then return to the transaction context. The agent’s conclusion enters the same event flow as the rest of the business process.
The specialists differ in the evidence they inspect:
- Risk analysis: Tools retrieve fraud history and relevant device-trust information from the semantic projections. The team is also moving selected business-specific rules into tools.
- Behavior analysis: Two plugins examine transaction patterns. Kumar does not name the plugins or detail their algorithms.
Their responses feed the final consensus, which is published as an event for interested contexts to consume. Moving selected rules into tools does not remove tier one; it makes those checks available within the agent’s investigation as well.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
What the tools read
The orchestration layer gathers context through tools that read the projections. The materialized view exposes a more useful decision surface than an isolated transaction amount:
| Source context | Projected evidence |
|---|---|
| Transactions | Counts, averages, average amounts, recent transactions |
| Devices | Trust scores, location histories, IP addresses |
| Accounts | Account status, KYC status, account age, customer tenure |
| Payments | Recent payment information |
These features let the agents consider the transaction alongside device, customer, and payment evidence. The tools provide access to that assembled context without requiring the model to reconstruct it from every source system during the request.
The full architecture does not depend on every source being Cosmos DB or even NoSQL. Relational and NoSQL databases can both feed the projection layer. Above that layer, agentic orchestration combines context access, a verdict tool, and short-term memory; its result passes back to saga orchestration. The durable integration points are the contextual read model and the event returned to the workflow. Those interfaces let an agent participate in an established architecture without making every service an agent system.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
The proof of concept reaches the event pipeline
Kumar closes with a proof of concept built on synthetic data. Transaction, account, and device contexts feed projections through CDC, making their events available in the semantic layer. When the simulation starts, events populate and propagate through the transaction, account, and payment layers. He then points to the processing path beginning with tier-one ML analysis.
The demonstration slows before showing the completed agent outcome. Kumar tentatively attributes the delay to a database running in serverless mode. He describes the intended continuation: two specialists produce their conclusions, a third agent makes the final decision, and that decision becomes an event on the broker. The completed three-agent verdict is not demonstrated in the recorded sequence. The intended handoff remains concrete: the broker delivers the decision, and the business-defined saga continues from there.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Resources
From the talk
Documentation for consuming database changes asynchronously, including ordering, delivery semantics, and change-feed modes.
Further reading
Microsoft's shopping-cart sample demonstrates an append-only event store and change-feed-driven read models.
- Bounded ContextArticle
Martin Fowler explains domain-model boundaries and explicit integration relationships between contexts.
Official agenda with an on-demand recording link for Kumar's session on event sourcing, change feed, and fraud detection across heterogeneous data sources.
Full transcript
Loading transcript…