---
title: "Building Event-Driven Agents Guides"
source: https://docs.autohand.ai/guides/automation/building-event-driven-agents
---

# Building Event-Driven Agents

Event-driven agents run in response to external signals instead of user prompts. This guide shows how to connect webhooks, queues, and file system events to Autohand Code.

## Choose an event source

-   **Webhooks** from GitHub, GitLab, Linear, or your own services.
-   **Message queues** such as Cloudflare Queues, AWS SQS, or RabbitMQ.
-   **File system watchers** for local automation.
-   **Scheduled triggers** for recurring checks.

## Route events to Autohand

Use a small worker to validate the event, extract identifiers, and call the Autohand SDK or CLI. Keep the router stateless and fast. Hand all reasoning to the agent.

## Pass context in the prompt

Include all relevant context in the prompt so the agent does not need to search. Pass identifiers, URLs, and prior state. Keep the prompt focused on the task.

## Handle results and failures

-   Write agent output to durable storage or a queue.
-   Post results back to the source system, such as a PR comment or ticket note.
-   Retry transient failures with exponential backoff.
-   Alert operators when the agent cannot complete a task.

## Example: auto-review pull requests

A GitHub webhook calls a Cloudflare Worker on every opened pull request. The worker runs an Autohand agent with the PR context and posts the review as a comment.

## Best practices

-   Validate webhook signatures before running the agent.
-   Run agents in isolated environments for untrusted input.
-   Limit the agent's permissions in CI and production.
-   Log session IDs so you can trace every event end to end.