<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: member_7b664256</title>
    <description>The latest articles on DEV Community by member_7b664256 (@member_7b664256).</description>
    <link>https://dev.to/member_7b664256</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3227758%2F1cea2bd1-7530-4d1b-8485-bbe97ba77a93.png</url>
      <title>DEV Community: member_7b664256</title>
      <link>https://dev.to/member_7b664256</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/member_7b664256"/>
    <language>en</language>
    <item>
      <title>Kiro Agent Orchestration Patterns</title>
      <dc:creator>member_7b664256</dc:creator>
      <pubDate>Mon, 15 Sep 2025 16:43:14 +0000</pubDate>
      <link>https://dev.to/member_7b664256/asdfadsf-2cie</link>
      <guid>https://dev.to/member_7b664256/asdfadsf-2cie</guid>
      <description>&lt;h1&gt;
  
  
  Building Event-Driven Multi-Agent Systems (or: How I Built 4 Apps Instead of 1 for a Hackathon)
&lt;/h1&gt;

&lt;p&gt;So here's the thing - everyone builds one app for hackathons, right? I built four. Not because I'm trying to show off but because... well, actually maybe a little bit of showing off, but mostly because exploring Kiro meant building multiple things and I wanted to really push what's possible with event-driven architectures.&lt;/p&gt;

&lt;p&gt;You can't vibe code this kind of magic.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem with Traditional Multi-Agent Systems
&lt;/h2&gt;

&lt;p&gt;Look, I've been in the trenches. Seen teams of 10+ engineers with 10+ million in funding build these monolithic agent systems that basically... don't work. They couple everything together, agents stepping on each other's toes, no clear orchestration pattern. It's a mess. And then they wonder why their funded startup dies without finding product-market fit.&lt;/p&gt;

&lt;p&gt;The traditional approach? You've got your agents all talking directly to each other, sharing state, blocking on responses... it's basically spaghetti code but with AI. No wonder these systems fall apart under load.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enter Event-Driven Architecture (The Good Stuff)
&lt;/h2&gt;

&lt;p&gt;So for FinAgent2 (yeah, creative naming, I know), I went full event-driven with the Motia framework. This is where it gets interesting...&lt;/p&gt;

&lt;p&gt;Instead of agents calling each other directly, everything flows through events. Market data comes in? That's an event. User asks a question? Event. Agent finishes analysis? You guessed it - event.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// This is how we used to do it (gross)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;marketAgent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;analyze&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;enriched&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;sentimentAgent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enrich&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;final&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;portfolioAgent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;optimize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;enriched&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// vs event-driven (chef's kiss)&lt;/span&gt;
&lt;span class="nf"&gt;emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;market.data.received&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// agents just listen and react independently&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The beauty is each agent just listens for events it cares about. No direct dependencies. No blocking. Just pure, beautiful decoupling.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Multi-Agent Orchestra
&lt;/h2&gt;

&lt;p&gt;Here's where Mastra comes in - and honestly, this framework is underrated. While everyone's building custom agent orchestration (guilty as charged in FinAgent1), Mastra gives you this out of the box:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MarketAnalyst Agent&lt;/strong&gt;: Listens for market events, emits analysis events&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Risk Manager&lt;/strong&gt;: Subscribes to portfolio changes, publishes risk assessments&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sentiment Tracker&lt;/strong&gt;: Monitors news events, broadcasts sentiment scores&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Portfolio Optimizer&lt;/strong&gt;: Reacts to all the above, suggests rebalancing&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Research Agent&lt;/strong&gt;: Deep dives on demand, async results&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Options Strategist&lt;/strong&gt;: Complex derivatives stuff that honestly most users won't use but looks impressive in demos&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The kicker? Each agent has its own memory through Mem0 integration. So your sentiment agent remembers what it analyzed yesterday without polluting the portfolio agent's context. Clean separation of concerns.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Event-Driven Beats Microservices (Fight Me)
&lt;/h2&gt;

&lt;p&gt;OK so I also built a microservices version (FinAgent1) with 8+ containers because... well, because I could. But here's the dirty secret nobody talks about:&lt;/p&gt;

&lt;p&gt;Microservices are often overkill. There, I said it.&lt;/p&gt;

&lt;p&gt;The event-driven version with Motia? Two containers. TWO. vs eight. Same functionality, 75% less operational complexity. Azure bills are basically nothing comparatively.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Microservices approach (why did we do this to ourselves?)&lt;/span&gt;
&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;api-gateway&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;...&lt;/span&gt;
  &lt;span class="na"&gt;market-service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;...&lt;/span&gt;
  &lt;span class="na"&gt;sentiment-service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;...&lt;/span&gt;
  &lt;span class="na"&gt;portfolio-service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;...&lt;/span&gt;
  &lt;span class="na"&gt;research-service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;...&lt;/span&gt;
  &lt;span class="na"&gt;oracle-service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;...&lt;/span&gt;
  &lt;span class="c1"&gt;# ... and on and on&lt;/span&gt;

&lt;span class="c1"&gt;# Event-driven (this is the way)&lt;/span&gt;
&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;app&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;All agents in one process&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;Event bus handles orchestration&lt;/span&gt;
  &lt;span class="na"&gt;redis&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;Events, caching, pub/sub&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Real Implementation Details
&lt;/h2&gt;

&lt;p&gt;So Motia gives you these "steps" - think of them like workflow stages but async and event-triggered. Each step can spawn multiple agent actions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;analyzeTrade&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;step&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;trigger&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;trade.requested&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;agents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;marketAnalyst&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;riskManager&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sentimentTracker&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;aggregate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// combine all agent outputs&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;consensus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The agents don't know about each other. They just know about events. marketAnalyst sees "trade.requested" and starts analyzing. Risk manager does its thing. Sentiment tracker checks the vibes. All in parallel, all independent.&lt;/p&gt;

&lt;p&gt;And here's the thing that really makes this work - event replay. System crashes? Replay the events. Need to debug? Replay with logging. Want to backtest? Just replay historical events through the same system. It's basically event sourcing but without the enterprise Java nightmares.&lt;/p&gt;

&lt;h2&gt;
  
  
  Challenges (Because Nothing Ever Just Works)
&lt;/h2&gt;

&lt;p&gt;Azure App Service doesn't like WebSockets. Or rather, it does, but only sometimes, and never when you're demoing. So we built this hybrid streaming thing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Had to get creative here&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;isAzureBeingDifficult&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; 
  &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PollingFallback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/events&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;EventSource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/stream&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, Motia's documentation is... let's call it "emerging". Spent a lot of time reading source code. Actually contributed some fixes back because opensource karma and all that.&lt;/p&gt;

&lt;p&gt;Memory management with multiple agents gets weird. Each agent maintaining context means memory usage can spiral. Implemented aggressive cleanup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Learned this the hard way at 3am&lt;/span&gt;
&lt;span class="nf"&gt;afterEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;memoryUsage&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;threshold&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trimOldestEvents&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What Actually Shipped
&lt;/h2&gt;

&lt;p&gt;Both systems are live on Azure right now. The event-driven one is handling real market data from Alpaca, processing complex multi-agent workflows, and actually providing useful analysis. Response times under 200ms for most queries, scaling horizontally when needed.&lt;/p&gt;

&lt;p&gt;The UI doesn't look like every other Bootstrap financial app (you know the ones). TradingView charts for the professionals, clean interfaces that actually make sense. Though honestly, the second version lets users build their own UI entirely because... composability over features.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lessons Learned (The Real Ones)
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Event-driven &amp;gt; microservices for 90% of use cases&lt;/strong&gt; - Unless you're Netflix, you probably don't need 50 microservices&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Frameworks matter&lt;/strong&gt; - Motia and Mastra saved literally months of work. Don't rebuild what's been solved.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cloud credits drive architecture&lt;/strong&gt; - We're on Azure because they gave us thousands in credits. AWS gave us like $200. Architecture follows incentives.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Multi-agent orchestration is about coordination, not control&lt;/strong&gt; - Let agents be autonomous, coordinate through events, not commands&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Memory persistence is crucial&lt;/strong&gt; - Agents without memory are just stateless functions. Mem0 integration was a game-changer.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What's Next
&lt;/h2&gt;

&lt;p&gt;Honestly? Open-sourcing the whole thing. Too many closed-source "revolutionary" fintech platforms that die in obscurity. Let the community build on this.&lt;/p&gt;

&lt;p&gt;Want to add more event types - market crashes, regulatory changes, whale movements. The architecture supports it, just need to implement the handlers.&lt;/p&gt;

&lt;p&gt;Backtesting through event replay is basically already there, just needs a UI. Imagine replaying 2008 through your agent system... actually, that might be depressing.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Bottom Line
&lt;/h2&gt;

&lt;p&gt;Built four production apps for a hackathon because one felt boring. The event-driven multi-agent system with Motia/Mastra is legitimately better than what I've seen funded teams produce. It's running, it's scaling, and it actually works.&lt;/p&gt;

&lt;p&gt;The vibes? They're event-driven, asynchronously processed, and horizontally scalable.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;P.S. - If you're still building synchronous agent systems in 2025, we need to talk. Seriously.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;P.P.S. - Yes, I know microservices have their place. But that place is not your MVP.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>kiro</category>
    </item>
  </channel>
</rss>
