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.

1:151:27
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

1:15 · section reference included

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.

TierMechanismResponsibility
Tier oneRules or traditional MLHandle clear approval and rejection cases
Tier twoAgentic analysisExamine 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.

3:303:42
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

3:30 · section reference included

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.

5:476:02
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

5:47 · section reference included

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.

Diagram showing a user command entering an event stream, with CDC change feed connections to timeline, customer activity, and risk projections beside a transaction context.Open full source frame
An event stream feeds read projections through CDC.

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.

8:178:35
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

8:17 · section reference included

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:

  1. Decompose the incoming task into smaller tasks.
  2. Process those tasks using the model and available tools.
  3. Check whether the goal has been reached.
  4. 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.

11:4111:55
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

11:41 · section reference included

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.

13:4013:52
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

13:40 · section reference included

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 contextProjected evidence
TransactionsCounts, averages, average amounts, recent transactions
DevicesTrust scores, location histories, IP addresses
AccountsAccount status, KYC status, account age, customer tenure
PaymentsRecent 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.

Architecture diagram showing event sources above an event store and SQL/NoSQL storage, followed by a projection/materialized view layer, agentic layer, verdict tool, short-term memory, and saga orchestration.Open full source frame
Event sources connect storage and projections to an agentic layer and saga orchestration.
16:5817:06
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

16:58 · section reference included

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.

19:0019:11
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

19:00 · section reference included

Resources

From the talk

Transcript download
Full transcript

Loading transcript…