# Event-Driven Agent

> Trigger the agent on external events (webhooks, message queues, file changes) instead of user requests or schedules.

- **Category**: Agentic AI
- **Subcategory**: Planning & Control Flow
- **Canonical URL**: https://designpattern.fyi/patterns/event_driven_agent/

---

## Description
**Intent**: Trigger the agent on external events (webhooks, message queues, file changes) instead of user requests or schedules.
**Context**: A team operates an agent whose job is to react to things happening in the wider system — a pull request opened on a repository, a customer message arriving in a queue, a monitoring alert firing, a file appearing in a watched folder. The work should happen when the event occurs, not when a human remembers to ask and not on a fixed schedule.
**Solution**: - Subscribe to the event source (webhook endpoint, message queue consumer, file watcher). - On each event: validate the payload, deduplicate (check for already-processed event IDs), and invoke the agent with the event payload as input. - Apply rate limiting to prevent burst overload. - Ensure idempotency so that duplicate deliveries produce the same outcome. - Acknowledge the event source only after successful agent processing.


## Use Cases
- An external event source (webhook, queue, file watcher) exists and pulling on a schedule wastes effort.
- Events can be validated, deduplicated, and processed idempotently.
- Acknowledgement after successful processing is supported by the event source.





## Trade-offs


### Advantages

- Timely action without polling cost.

- Composes with downstream automations naturally.




### Considerations & Drawbacks

- Event-source failures stop the agent silently.

- Idempotency is its own engineering investment.







---
**Reference**: [Original Source](https://www.agentpatternscatalog.org/patterns/event-driven-agent/)

