# Let's integrate AI Agents in Event-Sourced Systems

Divakar Kumar

AI Engineer World's Fair 2026

[Talk page](https://ai.engineer/talks/o6U_2vd967Y-lets-integrate-ai-agents-in-event-sourced) · [Video](https://www.youtube.com/watch?v=o6U_2vd967Y)

## 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.

Familiarity with asynchronous messaging, database read models, and basic agent tool use will help you follow the architecture.

### Why was the purchase declined?

[1:15](https://www.youtube.com/watch?v=o6U_2vd967Y&t=75s)

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.

### Keep the existing engine; escalate the gray zone

[3:30](https://www.youtube.com/watch?v=o6U_2vd967Y&t=210s)

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.

### Connect the evidence across bounded contexts

[5:47](https://www.youtube.com/watch?v=o6U_2vd967Y&t=347s)

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](https://martinfowler.com/bliki/BoundedContext.html)**: 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.

### Turn event history into queryable context

[8:17](https://www.youtube.com/watch?v=o6U_2vd967Y&t=497s)

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](https://learn.microsoft.com/en-us/azure/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.](https://ai.engineer/api/talk-essay-media/f342d3367c5cc2cf0eceb3a1110ab707e7fb279915b262a003073bb69915cba1)

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.

### Give the agent tools—and a stopping point

[11:41](https://www.youtube.com/watch?v=o6U_2vd967Y&t=701s)

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.

### Fan out the investigation, then return an event

[13:40](https://www.youtube.com/watch?v=o6U_2vd967Y&t=820s)

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.

### What the tools read

[16:58](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1018s)

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.

![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.](https://ai.engineer/api/talk-essay-media/268e3c5ac67c9dfc895c8ed92d4548e5fbfe080e9d36607af09decd3edab522c)

Event sources connect storage and projections to an agentic layer and saga orchestration.

### The proof of concept reaches the event pipeline

[19:00](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1140s)

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.

## Resources

- [Azure Cosmos DB change feed](https://learn.microsoft.com/en-us/azure/cosmos-db/change-feed) — Documentation for consuming database changes asynchronously, including ordering, delivery semantics, and change-feed modes.
- [Event sourcing with Azure Cosmos DB](https://learn.microsoft.com/en-us/samples/azure-samples/cosmos-db-design-patterns/event-sourcing/) — Microsoft's shopping-cart sample demonstrates an append-only event store and change-feed-driven read models.
- [Bounded Context](https://martinfowler.com/bliki/BoundedContext.html) — Martin Fowler explains domain-model boundaries and explicit integration relationships between contexts.
- [Divakar Kumar's fraud-detection session at Azure Cosmos DB Conf 2026](https://developer.azurecosmosdb.com/conf/) — Official agenda with an on-demand recording link for Kumar's session on event sourcing, change feed, and fraud detection across heterogeneous data sources.

## Slides

### Integrating AI Agents in Event-Sourced Systems

The talk explores adding AI agents to existing business workflows, using real-time fraud detection as its working example.

[0:25](https://www.youtube.com/watch?v=o6U_2vd967Y&t=25s) [Title slide for a talk on integrating AI agents in event-sourced systems.](https://assets.ai.engineer/sites/aiecode2025/sha256/018d52dcdeeeeb1b75305fe01e66d932cc9f787c4d17f6048f1d1ff4bf35d3fc.webp)

AI ENGINEER
World’s Fair

Let’s Integrate AI Agents in Event-Sourced Systems

LinkedIn: @ divakar-kumar

### Real-Time Fraud Detection

The talk turns to real-time fraud detection as the domain for the AI agent architecture.

[3:28](https://www.youtube.com/watch?v=o6U_2vd967Y&t=208s) [The words real-time fraud detection on a dark background.](https://assets.ai.engineer/sites/aiecode2025/sha256/9deff68aca635ba911eb0bf978c7c5e9068121d01e6c90767cdfb0346b5f721e.webp)

Real - time Fraud detection

### Rule-Based Approach

A rules engine evaluates card transactions and classifies them as fraud or not fraud. The speaker says maintaining its static rules became difficult as fraudsters tried new approaches.

[3:33](https://www.youtube.com/watch?v=o6U_2vd967Y&t=213s) [A card transaction passes through a rules engine to a fraud or not-fraud decision.](https://assets.ai.engineer/sites/aiecode2025/sha256/4b30c6f2f51d3d51d0784ddcd6404a95f0f0c0bd4b80bd2bceb1179e071f5181.webp)

Rule Based Approach

Rules Engine
1. · · · ·
2. · · · · ·
3. · · · · ·

Fraud
Not Fraud

### Traditional ML Approach

A third-party provider trained an ML model on transaction history and features. Its fraud score helped the team block or approve transactions.

[4:06](https://www.youtube.com/watch?v=o6U_2vd967Y&t=246s) [A card transaction passes through feature extraction and an ML model to produce a fraud score and decision.](https://assets.ai.engineer/sites/aiecode2025/sha256/4bfb727c76379b180dcb707f5a791fe2bcf926b841573120c18f34db4f23c354.webp)

Traditional ML Approach

Feature Extraction
ML Model
Fraud Score
Fraud
Not Fraud

### Fraud Risk Gray Zone

Transactions below a risk threshold are approved and those above another are blocked. In the gray zone, the system struggles to decide whether a transaction is fraudulent or legitimate.

[4:30](https://www.youtube.com/watch?v=o6U_2vd967Y&t=270s) [A risk scale shows low risk, a middle gray zone, and high risk.](https://assets.ai.engineer/sites/aiecode2025/sha256/8a1c5f860b094fc962aace38028092fd1677c5a42c29c62f98984bb4a32497be.webp)

Low Risk
Gray Zone
High Risk

### Two-Tier Fraud Processing

Tier one scores transactions, approving low-risk cases and rejecting high-risk ones. The middle 20–80% range is escalated to agentic AI processing.

[5:06](https://www.youtube.com/watch?v=o6U_2vd967Y&t=306s) [A tier-one rules or ML system produces a risk score for approval, escalation, or rejection; escalated cases proceed to tier-two agentic AI processing.](https://assets.ai.engineer/sites/aiecode2025/sha256/21433baed25ca00d053d120386f9d3cc3af4769aa66eb8c03afcb8780db567ad.webp)

Tier 1: Rule Based / Traditional ML Based

Risk Score (0-100%)

<20%: Approve ~70%
20-80%: Escalate ~15%
>80%: Reject ~15%

Tier 2: Agantic AI Processing

### Bounded contexts, orchestration, and messaging

An agentic store orchestrator coordinates communication among the transaction, payment, accounts, and device contexts. A message broker enables asynchronous communication across contexts.

[8:09](https://www.youtube.com/watch?v=o6U_2vd967Y&t=489s) [Transaction, payment, accounts, and device contexts surround an agentic orchestrator and connect to a message broker.](https://assets.ai.engineer/sites/aiecode2025/sha256/a60ed999f0ced15cb8ba39f650b3db344c026d4144540d2df2c8e09ff378e815.webp)

Transaction Context
Payment Context
Agentic Store Orchestrator
Accounts Context
Device Context
Message Broker

### Transaction context events

Transaction Created starts the transaction. Integration events arrive from other contexts, and the events are stored in a log using Cosmos DB as the event store.

[8:17](https://www.youtube.com/watch?v=o6U_2vd967Y&t=497s) [A transaction aggregate, transaction-created domain event, integration events, and an event log.](https://assets.ai.engineer/sites/aiecode2025/sha256/edef1f9cd05bc627d853689c16a77cd051970ae23651386f2d7c2f3f0bbade4f.webp)

Transaction Context

<< aggregate root >>
Transaction

<< domain event >>
Transaction Created

<< integration event >>
Transaction Rejected

<< integration event >>
Transaction Approved

<< integration event >>
Payment Completed

<< integration event >>
Payment Failed

Event Log
(transaction-events)

### Event stream and projections

A user command becomes an appended event; a change feed propagates updates to read models for timelines, customer activity, and risk.

[9:12](https://www.youtube.com/watch?v=o6U_2vd967Y&t=552s) [A user command feeds an event stream; a change feed supplies timeline, customer activity, and risk projections.](https://assets.ai.engineer/sites/aiecode2025/sha256/9fa91b8879592cd86254507f31a9adeb9a8715176b732b770fbe120c6235190e.webp)

Transaction Context

Projections
Timeline Projections
Customer activity
Risk view

CDC (change Feed)

User → Command → Event Stream
E1 → E2 → E3 → E4 → E5
Time

### Connecting contexts to projections

Transaction events feed timeline, customer activity and risk projections through a change feed. A message broker connects the accounts, payment and device contexts to the projections.

[10:26](https://www.youtube.com/watch?v=o6U_2vd967Y&t=626s) [A transaction event-stream and projection system connects through a message broker to accounts, payment, and device contexts.](https://assets.ai.engineer/sites/aiecode2025/sha256/23c4bf6e6941b33dd7817652588bd3956de28d6081d15a9f5d72696f1e5a01b6.webp)

Transaction Context

Timeline Projections
Customer activity
Risk view
Projections

CDC (change feed)

User → Command
Event Stream
E1 → E2 → E3 → E4 → E5
Time

Message Broker
Accounts Context
Payment Context
Device Context

### Building the projection layer

Events from different contexts travel through CDC or a message broker to a projection worker, which processes them into a materialized view.

[11:07](https://www.youtube.com/watch?v=o6U_2vd967Y&t=667s) [Transaction, payment, accounts and device contexts feed a projection worker through CDC or a message broker, producing a projection layer.](https://assets.ai.engineer/sites/aiecode2025/sha256/27a21f467d38cfccc143c55346a36601d87fbdaad35e9311a6e6276f4d121b9b.webp)

Transaction Context
Payment Context
Accounts Context
Device Context

CDC
Message Broker

Projection Worker Process

Projection Layer
NoSQL database

### Agent reasoning loop

A language model breaks a query into tasks and processes them with tools and memory. If the end goal is not reached, the agent repeats the loop.

[12:47](https://www.youtube.com/watch?v=o6U_2vd967Y&t=767s) [A client query enters an agent with a language model, tools and memory; tasks repeat until the end goal is reached.](https://assets.ai.engineer/sites/aiecode2025/sha256/7db0bde6a3a518a5a2de6e0e2b6bc507325a3a4b6cfb2c4ea6ea1df3a81ed363.webp)

Agents

Query or Event
Client
Reasoning
Language Models
SLM/LLM

Start
t1  t2  t3  t4  …  tn
Goal

API / Method calls
Tools
External access
Memory
Memory Management
Repository / in-memory

End Goal Reached
No
Yes

### Agent illustration

The speaker cautions that agents need a way to stop their loop. The metric used to break out can vary by use case.

[13:05](https://www.youtube.com/watch?v=o6U_2vd967Y&t=785s) [White outline of a sunglasses-wearing figure in a long coat with one arm extended.](https://assets.ai.engineer/sites/aiecode2025/sha256/6f2a3593bd8f46d3bf3b3708146fbc248fbf7e6c69d2475582a7b89450249772.webp)

### Agent loop

A metric can determine when to exit the agent loop and avoid an infinite loop. The stopping threshold varies by use case.

[13:26](https://www.youtube.com/watch?v=o6U_2vd967Y&t=806s) [Two arrows form a loop.](https://assets.ai.engineer/sites/aiecode2025/sha256/60e4195930eff95e98b8e15fd682582c46e80b9ae8e048a867057153247e4a80.webp)

### Tier-two analyst agents

Risk and behavior analysts use tools and memory to assess different signals. Their responses feed a final consensus, which is published as an event to the message broker.

[15:40](https://www.youtube.com/watch?v=o6U_2vd967Y&t=940s) [Risk and behavior analyst agents use language models, tools and memory, then contribute to a final consensus published through a message broker.](https://assets.ai.engineer/sites/aiecode2025/sha256/b6f4a6e864926458792a3627c81e18a52234c433d34f3dea71beac8f8d3c7b04.webp)

Tier-2

Risk Analyst Agent
Language Models
Tools
API / method calls
Memory
Repository / in memory
- Get Fraud History
- Analyze Device Trust
- Check Business Rules

Behavior Analyst Agent
Language Models
Tools
API / method calls
Memory
Repository / in memory
- Analyze Transaction Pattern
- Analyze Transaction Location

Final Consensus
Publish Decision
Message Broker

### How Does the Agent Gather Context?

The talk turns to how agents gather context.

[16:56](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1016s) [A handwritten question asks how the agent gathers context.](https://assets.ai.engineer/sites/aiecode2025/sha256/a6a8783c5839a875e4d4aad3d6996e2470153f94f344ccae53b0ef5929bf2008.webp)

How does the Agent gather Context?

### Context Gathering Architecture

Transaction, payment, account and device contexts feed projection workers through CDC and a message broker. The orchestration layer uses tools to consume data from the resulting projection layer.

[17:06](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1026s) [Transaction, payment, account and device contexts feed a projection layer through CDC, a message broker and projection workers.](https://assets.ai.engineer/sites/aiecode2025/sha256/9c19b96c8dec5229b8672aa5cab15601f29d78ee8c505ffa452f2b2c109b9b34.webp)

Transaction Context
Payment Context
Accounts Context
Device Context

CDC
Message Broker

Projection Worker Process

Projection Layer
NoSQL database

Agentic Store Orchestration

### Agents and Fraud Indicator Projections

Transaction, device, account and payment contexts feed fraud indicator projections. Risk and behavior analyst agents use tools to access the projections and reach conclusions.

[18:12](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1092s) [Four contexts feed fraud indicator projections used by risk and behavior analyst agents.](https://assets.ai.engineer/sites/aiecode2025/sha256/b44942b365dd87d766561a6f3cfe98eec3da87cb90bb135cf0e9e3405fb64d27.webp)

Transaction Context
De-normalize count, average amount, recent transactions

Device Context
De-normalize trust scores, location history

Account’s Context
De-normalize status, account age

Payment Context
De-normalize success, failure, recent payments

Fraud Indicator Projections

Risk Analyst Agent
Language Models
Tools
Memory
API / [illegible] calls
Repository / in memory

Get Fraud History
Analyze Device Trust

Behavior Analyst Agent
Language Models
Tools
Memory
API / [illegible] calls
Repository / in memory

Analyze Transaction Pattern
Analyze Transaction Location

### High-Level Agentic Architecture

Event sources feed stores and a projection layer that supplies context to agents. The agentic layer uses a verdict tool and short-term memory, then passes its result to saga orchestration.

[18:26](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1106s) [Event sources feed stores and a projection layer, followed by an agentic layer, verdict tool, short-term memory and saga orchestration.](https://assets.ai.engineer/sites/aiecode2025/sha256/489f821c71b83323e667d20603370ab5859bc449de12b017fd71141ca9f495fc.webp)

Event Sources

Event Store
SQL / NoSQL

Projection / Materialized View Layer

Agentic Layer

Verdict Tool
Short-term Memory

Saga Orchestration

### Live Fraud Detection Simulator

This synthetic-data proof of concept maps transaction, account and device contexts through projections to AI agents. In the captured view, the live panels are waiting for events, projection updates and fraud decisions.

[18:58](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1138s) [A fraud detection simulator shows controls, a service graph and live panels waiting for events, projection updates and fraud decisions.](https://assets.ai.engineer/sites/aiecode2025/sha256/be2be11c5b3da3810e962c9212e3f859c7a96835a35aa670eeb729913bdbcbbc.webp)

INTERACTIVE SIMULATOR
Live Fraud Detection
Detection rate: 0%

CONTROLS
SIMULATIONS REMAINING TODAY: 3/3
[illegible]

SCENARIO MODE
Coffee, groceries, gas, dining, shopping
NUMBER OF USERS
TPS PER USER: 0.5
Total: 5.0 TPS (10 × 0.5)
START

MANUAL EVENT TRIGGER
NORMAL
SUSPICIOUS

GRAY ZONE COMPARISON
NO AI
WITH AI
[illegible]
AI ENABLED

EVENT_DRIVEN_CHOREOGRAPHY
Legend: TX, PAY, ACC, FRAUD
SIMULATOR
SERVICE BUS
TRANSACTION SVC
AGENTICSTORE
ACCOUNT SVC
DEVICE SVC
COSMOS DB
AI AGENTS
PROJECTIONS
CHANGE FEED
REDIS PUB/SUB
SSE ENDPOINT
REACT UI

COSMOS DB - LIVE
Containers: account-events, payment-events, transaction-events
Waiting for events...

PROJECTIONS - LIVE
Materialized View: fraud-indicator-projections
Waiting for projection updates...

AI AGENTS - LIVE
Tiers: ML Auto-Approve/Reject, AI Deep Analysis
Waiting for fraud decisions...

### Thank You

The speaker invites questions offline or on LinkedIn; the closing slide provides a QR code for connecting.

[21:08](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1268s) [Closing slide with a line drawing, a LinkedIn connection prompt and QR code, and thank-you messages.](https://assets.ai.engineer/sites/aiecode2025/sha256/3772b70e312303dac29efef31b10505443ab00b7f0b1e77a4d6d353bab2e2837.webp)

Connect with me on LinkedIn

நன்றி!
Thank You!

## Full transcript

[0:00](https://www.youtube.com/watch?v=o6U_2vd967Y&t=0s) [on-hold music] Hello, everyone. Thanks for joining.

[0:16](https://www.youtube.com/watch?v=o6U_2vd967Y&t=16s) So I think, like, finally, we are at the last day of the conference. Personally, I had a great experience, learned a lot of new things. So I believe by the end of the session, you would have at least few key takeaways that you could apply in your work projects.

[0:33](https://www.youtube.com/watch?v=o6U_2vd967Y&t=33s) So what is it we are gonna learn? So we are gonna learn how to integrate AI agents in your existing system. So this system, it could be an event store system, or it could be an event-driven system, or it could be any architecture that your business has invested over the last few years, right?

[0:52](https://www.youtube.com/watch?v=o6U_2vd967Y&t=52s) Because I always believe that these AI agents are m- not just for the chatbots or the coding assistants, right? So the real value that you could bring out of these AI agents is, like, when you start to apply these into your business workflows.

[1:07](https://www.youtube.com/watch?v=o6U_2vd967Y&t=67s) And that is what we are gonna learn. And the problem space that we are gonna work on today is the real-time fraud detection. So let me start with an example.

[1:15](https://www.youtube.com/watch?v=o6U_2vd967Y&t=75s) So this is my personal experience. So, uh, exactly a month ago, I purchased, uh, like, I decided to purchase this laptop that I'm using for the presentation. So it's...

[1:27](https://www.youtube.com/watch?v=o6U_2vd967Y&t=87s) It costed me around, like, three thousand five hundred dollars. So I waited for a right moment. So I was seeing like whether I have a nice offers, and there was one moment, so I decided to buy.

[1:39](https://www.youtube.com/watch?v=o6U_2vd967Y&t=99s) I pro- provided my card details, and then I clicked on buy button, then my transaction got declined. So I thought, like, it was a network issue and some information has been misplaced.

[1:50](https://www.youtube.com/watch?v=o6U_2vd967Y&t=110s) So I tried the second attempt, and it was failed again. Before I tried the third attempt, so I got a call from the customer service asking to verify, like, if I'm doing that particular transaction.

[2:02](https://www.youtube.com/watch?v=o6U_2vd967Y&t=122s) And I was like, "Yes, I, I was trying to do this for the past few minutes." And I asked them like, "Why did you block my transaction?" Do you know what the response was?

[2:12](https://www.youtube.com/watch?v=o6U_2vd967Y&t=132s) They didn't know because-- I wouldn't blame, blame them because they didn't know, like, why it was blocked. It was somewhere in the system, either the rule-based engine or the ML-based engine would have taken that decision.

[2:24](https://www.youtube.com/watch?v=o6U_2vd967Y&t=144s) So it would have looked through my transaction history, or it would have have an average threshold beyond which, like, if it goes, like, just block the transaction. That would be the static rule that it would have had, because of which my transaction got declined.

[2:39](https://www.youtube.com/watch?v=o6U_2vd967Y&t=159s) So th-those are the key areas, like, those are the uncertain areas where we are trying to integrate the AI agents. Now, you might be thinking, like, what a great idiot, right?

[2:50](https://www.youtube.com/watch?v=o6U_2vd967Y&t=170s) Because it is already an uncertain case. Like, why do you want to introduce an AI agent? Because it is also a non-deterministic by nature, right? But the key point here that we are all trying to miss is that earlier in the rule-based engine or the ML-based engine, like, we don't have enough context.

[3:08](https://www.youtube.com/watch?v=o6U_2vd967Y&t=188s) We don't have enough real-time data that gets passed on to the system. And those are the real data, like, that we are trying to capture from different bounded contexts that we have in our domain.

[3:19](https://www.youtube.com/watch?v=o6U_2vd967Y&t=199s) And we are gonna see, like, how we could build that architecture so that the AI agent can make use of it and, uh, come up with an verdict.

[3:30](https://www.youtube.com/watch?v=o6U_2vd967Y&t=210s) So the domain that we are gonna, uh, talk about is the real-time fraud detection, as I mentioned before. So we had this rule-based engine, like, um, uh, five years before, and this rule-based engine was perfectly fine.

[3:42](https://www.youtube.com/watch?v=o6U_2vd967Y&t=222s) Like, it was working perfectly fine for a few of the cases and... But, but the problem with this rule-based engine is, like, the maintainability because the fraudsters are trying to get intrude into a system, like, by a lot of different ways, and you just need to keep on updating the static rules day by day, and it, it,

[4:00](https://www.youtube.com/watch?v=o6U_2vd967Y&t=240s) it's gonna be really difficult for you to manage. And that's when, like, we started to, um, tie up with a third-party provider, like, who helped us to, uh, develop this ML model.

[4:10](https://www.youtube.com/watch?v=o6U_2vd967Y&t=250s) So we, we have this, uh, ML-based approach, like, where, uh, we shared with them a transaction history or, uh, different features with them. Like, based on that, they trained the ML model, and we were able to get a risk score based on that which...

[4:25](https://www.youtube.com/watch?v=o6U_2vd967Y&t=265s) with which, like, we were, uh, able to block or approve the transaction. But the problem with either of these approaches, like, either, um, like we, we, we were able to handle most of the transaction because it would fall below a certain threshold, then we would approve the transaction.

[4:44](https://www.youtube.com/watch?v=o6U_2vd967Y&t=284s) And if it goes beyond a certain thresh-threshold, we would be blocking those transaction. But majority of the transaction, like, few of the transaction, like, goes under the gray zone area, and this is the area where it is really uncertain for those systems to really, um, come to a conclusion whether it is an, um, fraudulent transaction or a

[5:04](https://www.youtube.com/watch?v=o6U_2vd967Y&t=304s) legitimate transaction. So what we are trying to do is, like, we, we had, uh, build a system where we had both these tier one system, which has this rule-based or the traditional ML model, and then we also had a tier two system, which is agentic AI approach.

[5:23](https://www.youtube.com/watch?v=o6U_2vd967Y&t=323s) Like, um, most of the cases would be handled re-really well by these existing system we already had because our thought process is not to exclude the systems that we already had.

[5:35](https://www.youtube.com/watch?v=o6U_2vd967Y&t=335s) We were just trying to handle w- few of the areas, like that is the gray zone areas, with the help of agentic AI processing. So this is the approach, like, uh, that we decided, "Okay, let's move on with this approach."

[5:47](https://www.youtube.com/watch?v=o6U_2vd967Y&t=347s) But then our architecture, our, um, um, domain is really complicated. So this is our different bounded context that we have internally in our domain. So the transaction context holds all the details about your transactions.

[6:02](https://www.youtube.com/watch?v=o6U_2vd967Y&t=362s) Like, it knows about the merchants It knows about the amounts that, um, that you transact, and everything related to a transaction would be residing on this particular context. And it doesn't have any information about the customer it is handling, or it doesn't have any information about the payments or the device details.

[6:20](https://www.youtube.com/watch?v=o6U_2vd967Y&t=380s) That is what the con-- uh, bounded context means, right? Because if you are from the DDD background or, um, uh, software engineering, like you would know that these are different bounded contexts, like with-- like you wouldn't share the data among themselves.

[6:34](https://www.youtube.com/watch?v=o6U_2vd967Y&t=394s) Like you need to do an asynchronous way of communication and, um, like all sort of things like that you would do in a microservice communication would necessarily been done here as well.

[6:45](https://www.youtube.com/watch?v=o6U_2vd967Y&t=405s) So then we do have accounts context, all the details about the accounts like the KYC compliant, whether the user is KYC compliant or anything about the customer, like if you want to know about the customer, this would be the right context that we need to reach out to.

[7:01](https://www.youtube.com/watch?v=o6U_2vd967Y&t=421s) And there is a device context like we had stored, uh, all the device fingerprints, browser fingerprints, uh, the OS that they are using, um, over these device contexts, like that would be really helpful like for detecting these kinds of real-time frauds.

[7:16](https://www.youtube.com/watch?v=o6U_2vd967Y&t=436s) And finally, like we had payment context, so any sort of chargebacks or, um, uh, anything related to the payments will be residing on this particular context.

[7:26](https://www.youtube.com/watch?v=o6U_2vd967Y&t=446s) So now the problem that we have with this kind of an architecture is like, uh, we, we really, we really don't have a way or means to share these, uh, con-- uh, datas across different, um, uh, bounded contexts, right?

[7:40](https://www.youtube.com/watch?v=o6U_2vd967Y&t=460s) So that's where like we started to introduce an orchestrator layer. So earlier, like we had this orchestrator layer, but now we also have an agentic AI inside this orchestrator.

[7:51](https://www.youtube.com/watch?v=o6U_2vd967Y&t=471s) So what this orchestrator does is like similar to, um, a saga orchestration. So all the communication would go through this layer, and then it would be, um, communicated to other services, like who are interested in those events.

[8:05](https://www.youtube.com/watch?v=o6U_2vd967Y&t=485s) And that is how like we define this, uh, orchestration layer. And we also have an asynchronous way of communicating with-within other different contexts, like through a message broker.

[8:17](https://www.youtube.com/watch?v=o6U_2vd967Y&t=497s) If I zoom in a little bit on the transaction context, you could see what, what are the details that these transactions are holding. So, um, essentially like what happens is like when you have, um, a particular do-domain, you will be having different events that are emitted from that system.

[8:35](https://www.youtube.com/watch?v=o6U_2vd967Y&t=515s) So those are really called as domain events. And within our transaction context, like we do have transaction created domain event, which is the start of entire transaction, and we do have a lot of integration events.

[8:47](https://www.youtube.com/watch?v=o6U_2vd967Y&t=527s) So these are the events that comes from other contexts like payment context, uh, device context, or account context. So events like transaction rejected, payment approved, payment rejected would come from other systems to our, um, uh, transaction context.

[9:03](https://www.youtube.com/watch?v=o6U_2vd967Y&t=543s) And these entire informations are stored in our NoSQL database. Uh, we are currently using Cosmos DB as our event store. And we are following event sourcing as our methodology, uh, to store the events.

[9:16](https://www.youtube.com/watch?v=o6U_2vd967Y&t=556s) So what happens is like whenever a user initiate a command, so that goes into our event store as an event, as a business fact. So we are not mutating the state, but instead like we are appending all the events as when it arrives.

[9:30](https://www.youtube.com/watch?v=o6U_2vd967Y&t=570s) And what it really helped us to do is like, uh, once it arrives into the event store... So, so we have a kind of a mechanism called CDC or in NoSQL world this is called as a change feed, with which like whenever there is an change or update happens over a table, so you will be getting notified, and

[9:49](https://www.youtube.com/watch?v=o6U_2vd967Y&t=589s) those changes could be propagated into different read models. So because in, in, in a real scenario, like you won't be able to rely entirely upon the event store for the query operation, for the read operation, what you would do is like in turn like you will be having different read models which are optimized for the read operations.

[10:09](https://www.youtube.com/watch?v=o6U_2vd967Y&t=609s) So what we really had is like we had multiple read models, so one for timelines, one for customer information, and one for the fraud indi-- uh, indicators, that is PU.

[10:20](https://www.youtube.com/watch?v=o6U_2vd967Y&t=620s) So these are the different, uh, read model layer, layers that we had within our transaction context. And essentially like you can't, um, you can't, you can't say other teams to follow the same patterns because event sourcing is not the one that, uh, other teams are also following.

[10:36](https://www.youtube.com/watch?v=o6U_2vd967Y&t=636s) So what we did is like we also had this asynchronous way of communication by, uh, emitting those events into the message broker and those, uh, those events in turn will be processed by a worker process and then it will be reaching out to our projection layer.

[10:51](https://www.youtube.com/watch?v=o6U_2vd967Y&t=651s) So the idea is like we need to gather all the datas from all these different contexts and to have or build a semantic layer, or you could call it as a materialized view, which you could further use w-within your agentic AI flow.

[11:10](https://www.youtube.com/watch?v=o6U_2vd967Y&t=670s) So this is how the high level flow looks like. Like we have all these different contexts, and you could either use a CDC mechanism or a message broker to propagate those events into your projection layer.

[11:22](https://www.youtube.com/watch?v=o6U_2vd967Y&t=682s) And essentially like you will be having this intermediate layer like which is an worker process. You need to massage your message events and then process it and then store them in the materialized view.

[11:34](https://www.youtube.com/watch?v=o6U_2vd967Y&t=694s) So this, this is the entire high level picture of how you could gather those datas and form a materialized view.

[11:41](https://www.youtube.com/watch?v=o6U_2vd967Y&t=701s) Now coming to the agents. So, so we all know like agents are comprised of these three main components, the language models, the tools, and the memories, right? So this language model, it, it is not necessary to be a la-large language model.

[11:55](https://www.youtube.com/watch?v=o6U_2vd967Y&t=715s) It could be S-SLM, it could be an open source model. And the tools are by which like you could interact with the external APIs or the methods, methods that you define in-inside your, uh, application layer.

[12:07](https://www.youtube.com/watch?v=o6U_2vd967Y&t=727s) And you also need to have a memory layer. For this particular use case, like we are using an in-, um, short memory because, uh, you, you can't really, um, rely on the long-term memory because you need to, um, adhere to the, uh, SLA that you, uh, provided to the customers because For, for the transaction, uh, to be

[12:27](https://www.youtube.com/watch?v=o6U_2vd967Y&t=747s) processed, like, it should be sub five hundred milliseconds. And y- y- we are currently using in-memory for this. And essentially, like, what happens is, like, whenever there is an query comes into our language model, so it has this reasoning capability, the thinking capability with which, like, it tries to decompose the task into multiple chunks.

[12:46](https://www.youtube.com/watch?v=o6U_2vd967Y&t=766s) And each of these tasks in turn will, uh, go into the language model, do cert- certain processing with the help of the tools, and it will see, like, if the end goal is reached.

[12:57](https://www.youtube.com/watch?v=o6U_2vd967Y&t=777s) And if it is not reached, like, it will try to go on in this loop. So this is what essentially happens inside the, uh, agentic framework.

[13:06](https://www.youtube.com/watch?v=o6U_2vd967Y&t=786s) But you should really know, like, when to stop this loop, uh, because, uh, th- this difference, uh, this, this, this might be varying, this might be differing for different use cases.

[13:17](https://www.youtube.com/watch?v=o6U_2vd967Y&t=797s) For, for our use case, like, we do have a metrics w- beyond which, like, if we go, like, we, we could break out of this loop, and this could be varying for different use cases.

[13:26](https://www.youtube.com/watch?v=o6U_2vd967Y&t=806s) So you should be really careful on avoiding this infinite loop. And now coming back to our, uh, existing architecture. So what we did is, like, earlier, like, we learned about the transaction aggregate.

[13:40](https://www.youtube.com/watch?v=o6U_2vd967Y&t=820s) So now we are emitting some events that gets translated into an integration event, which gets passed on to the message broker, and then it, it is handled under the orchestration layer.

[13:52](https://www.youtube.com/watch?v=o6U_2vd967Y&t=832s) So under this orchestration layer, like, we have different sub-orchestrator. So we segregated the tier one. Earlier, like, we just had the tier one. Now we have this tier one layer, which is handling the, um, rule-based engine or the ML-based engine.

[14:07](https://www.youtube.com/watch?v=o6U_2vd967Y&t=847s) And we also have now the tier two layer, which is gonna be agentic AI processing. So for this agentic AI processing, like, we used fan-out pattern. So we kind of used multiple agents within this layer, and we are trying to use a fan-out pattern.

[14:22](https://www.youtube.com/watch?v=o6U_2vd967Y&t=862s) Like, uh, once the, uh, event has been reached out to the a, uh, tier two layer, we will be fanning out this, uh, event to two different agents. One is the risk analyzer agent, the other one is the behavior analyzer agent.

[14:38](https://www.youtube.com/watch?v=o6U_2vd967Y&t=878s) And once these agents, like, come to an conclusion based on the different tools that it has, it will finally send the response to the verdict, and this verdict could be a metric, it could be just an if condition inside your application layer, or it could be an- another agent.

[14:56](https://www.youtube.com/watch?v=o6U_2vd967Y&t=896s) Because what we've seen is, like, if we are using just the metrics, it is again going back to the same criteria, like, where we had this rule-based, um, mechanism.

[15:06](https://www.youtube.com/watch?v=o6U_2vd967Y&t=906s) Uh, so there are many false positive cases that we are, uh, that we faced. So, so we, we in turn, like, we are trying to use a third agent in this verdict layer which analyzes both the agents' responses and come to a conclusion, which is then gonna be emitted as an event back to this message broker.

[15:25](https://www.youtube.com/watch?v=o6U_2vd967Y&t=925s) So this is how our saga flow continues, and it gets into the payment context, and then the payments are approved, and then it is going back to the transaction context.

[15:35](https://www.youtube.com/watch?v=o6U_2vd967Y&t=935s) This entire loop is being done within our orchestration layer.

[15:41](https://www.youtube.com/watch?v=o6U_2vd967Y&t=941s) And this, this is what I was talking about two agents that we had in this tier two. So one is the risk analysis agent. Like, what are the tools that we have in this, um, agent is that, like, we do have this, uh, kind of, uh, storing the fraud histories inside the semantic layer that we earlier see,

[15:59](https://www.youtube.com/watch?v=o6U_2vd967Y&t=959s) and we are currently having a tool for that. Like, um, it will just get those details from these projections layer. And we also have a device trust layer. Like, all the device information will get stored into this semantic layer, and it will just get those chunks alone.

[16:16](https://www.youtube.com/watch?v=o6U_2vd967Y&t=976s) And we also had, um, business rules trying to migrate some of the rules that we had in the rule-based engine over these tools, and these are really specific to our business use case, so we are trying to move those into these tools.

[16:30](https://www.youtube.com/watch?v=o6U_2vd967Y&t=990s) And we also have a be- behavior analysis tool. So, so there, like, we are analyzing the transaction patterns with two different plugins that we have. So based on these two different agents, the responses, like, we get to a final consensus, and then that will be published as an event, which will be captured by the message broker.

[16:50](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1010s) And this will be listened or, uh, this will be subscribed by all the different contexts which are interested in those events.

[16:58](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1018s) Now, as, as, as we seen earlier, like, how does these g- um, agents gather context? So

[17:06](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1026s) from the projection layer. So these orchestration layer is gonna consume these i- um, datas from the projection layers, and how it is gonna do is by the help of tools that it already has.

[17:18](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1038s) So the transaction context, it is gonna denormalize some of the counts, averages, average amounts that we had. The recent transactions all gets into this, um, semantic layer. And the device context is gonna send all the details about the device trust score, location histories, and all other, um, related information alo- um, about the locations, IP addresses to this

[17:42](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1062s) semantic layer. And the account context is gonna send the statuses of the accounts, the KYC status, account age, um, whether the customer has been, uh, with us for the past few years.

[17:54](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1074s) Uh, so based on that, like, uh, it will try to validate the, uh, leg- um, uh, the, the customer based on those informations. And there is also the payment context from this, like, we get to know about the recent, uh, payments that we, um, gathered over these contexts into the semantic layer.

[18:14](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1094s) And, and as I, as I said earlier, so these tools get, uh, access to these projection layer, and which in turn will be used by these agents to come to an conclusion.

[18:26](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1106s) And this is the high level, um, a-architecture that we had. So it could be any event source that you could use, and basically, like you could have a relational database or NoSQL database.

[18:38](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1118s) In turn, like you, you need to just create the semantic layer for you to, uh, provide enough context to these AI agents. And we do have this agentic layer in the orchestration, so we have this verdict tool, and then the short-term memory.

[18:52](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1132s) And based on that, like whatever the result that we get, gets on passed to the saga orchestration layer.

[19:00](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1140s) So we-- I, I, I have prepared a POC, uh, so based on the synthetic data. So I will just show you like how this works, uh, in, in, in...

[19:11](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1151s) Let me run this one. So these are the different contexts that we have seen earlier, so the transaction context, accounts, and device context. So from these, like we will get into the projections layer, and we will be having a CDC mechanism with which like you will be able to progress-- propagate those events back

[19:36](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1176s) to your semantic layer, which will get in turn used by these AI agents.

[19:44](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1184s) So here you could see, so there are multiple simulation events that we are pr, um, simul-simulating into the-- our systems. And you could see bunch of events are currently populating.

[19:56](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1196s) So these, um, events are propagating through different layers, the transaction layer, accounts, and then payments context.

[20:05](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1205s) And finally, like we also have this, uh, AI agent layer, like which, which is gonna try with the tier one processing, uh, the ML processing.

[20:24](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1224s) Let me see. I think it is just the database which is in the serverless mode. Um, I think it is coming up slowly.

[20:40](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1240s) So but, but yeah. The idea is like you will be able to see like two different agents coming up with two different, uh, conclusions, and you'll be having a third agent which will take the final decision.

[20:51](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1251s) Uh, that will be in turn emitted as an event back to your message broker. And this saga flow will be continuing as for, uh, like how you design your business architecture.

[21:04](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1264s) I'm going back to my presentation. Yeah, that's it. Uh, if you have any questions, like you can reach out to me, uh, offline, or you can reach out to me on LinkedIn.

[21:16](https://www.youtube.com/watch?v=o6U_2vd967Y&t=1276s) Thank you. [clapping] [upbeat music]
