Module 9 Wrap-up: Engineering for Real-Time
Hands-on: Build an event-driven agent pipeline that detects toxicity and triggers a response.
Module 9 Wrap-up: The Async Advantage
You have learned that not all agents need complex graphs. Sometimes, a series of Event Listeners is more powerful and faster. Now, we are going to build a Reactive Pipeline.
Hands-on Exercise: The Social Media Monitor
The Goal: Build a system that "Listens" for new comments.
- If a comment is Positive, trigger a "Like" response.
- If a comment is Negative/Toxic, trigger a "Moderation Alert" and log it to a database.
1. The Architecture (Decoupled)
graph LR
Trigger[Input: New Comment] --> Bus(Event Bus)
Bus --> A1[Agent: Sentiment Analyzer]
A1 -->|Event: Sentiment_Found| Bus
Bus --> A2[Agent: Responder]
Bus --> A3[Agent: Slack Logger]
2. The Logic (Conceptual Python)
import asyncio
# A mock Event Bus
queue = asyncio.Queue()
async def listener():
while True:
event = await queue.get()
print(f"--- Event Detected: {event['type']} ---")
if event['type'] == "new_comment":
# Start Sentiment Task
asyncio.create_task(sentiment_agent(event['payload']))
if event['type'] == "sentiment_ready":
# Decide next action
if event['payload']['score'] < 0.3:
asyncio.create_task(moderation_agent(event['payload']))
else:
asyncio.create_task(auto_reply_agent(event['payload']))
# Each Agent is an async function that just publishes a new event
async def sentiment_agent(text):
# Call LLM...
print("Agent: Analyzing sentiment...")
await asyncio.sleep(1) # Simulate delay
await queue.put({"type": "sentiment_ready", "payload": {"text": text, "score": 0.1}})
Module 9 Summary
- Event-Driven Agents react to external signals rather than internal loops.
- Stateless Strands are the easiest architecture to scale across multiple servers.
- Decoupling allows you to add or remove agents without breaking the system.
- Async/Streaming is the key to creating AI experiences that feel "Instant."
Coming Up Next...
In Module 10, we explore the ADK (Agent Development Kit). We will look at how enterprise companies manage agent lifecycles, global policies, and security guardrails across thousands of agents.
Module 9 Checklist
- I can describe the difference between a Loop and an Event.
- I understand the pros and cons of Stateless vs. Stateful agents.
- I can write a basic
asyncioparallel task. - I identified a "High-Volume" task in my project suitable for Strands.
- I understand how streaming reduces the "Time to First Token" (TTFT).