Skip to content

Event sources define external triggers that can start agent tasks or workflows. They allow agents to respond to file changes, webhooks, scheduled events, and connection events.

Overview

AgentPool supports multiple event source types that enable reactive agent workflows:

  • File Watch: Trigger on file system changes
  • Webhook: HTTP endpoint for external triggers
  • Email: Email-based triggers
  • Time: Scheduled/periodic execution
  • Connection: Trigger on agent connection events

Event sources are typically used with task configurations to create event-driven agent systems.

Configuration Reference

Event Sources

File watching

File watch trigger.

File watching (YAML)
- type: file
  paths:  # Paths or patterns to watch for changes.
  - ./src
  - ./docs
  extensions: null  # File extensions to monitor (e.g. ['.py', '.md']).
  ignore_paths: null  # Paths or patterns to ignore.
  recursive: true  # Whether to watch subdirectories.
  debounce: 1600  # Minimum time (ms) between trigger events.
  name: file_watcher  # Unique identifier for this event source.
  enabled: true  # Whether this event source is active.
  template: '  # Jinja2 template for formatting events.

    {%- if include_timestamp %}at {{ timestamp }}{% endif %}

    Event from {{ source }}:

    {%- if include_metadata %}

    Metadata:

    {% for key, value in metadata.items() %}

    {{ key }}: {{ value }}

    {% endfor %}

    {% endif %}

    {{ content }}

    '
  include_metadata: true  # Control metadata visibility in template.
  include_timestamp: true  # Control timestamp visibility in template.
  session: target  # Which session the trigger's events run in (see TriggerSessionPolicy).

Webhook

Webhook trigger.

Webhook (YAML)
- type: webhook
  port: 8080  # Port to listen on.
  path: /webhook  # URL path to handle requests.
  secret: '!ENV ENV_VAR_NAME'  # Optional secret for request validation.
  name: file_watcher  # Unique identifier for this event source.
  enabled: true  # Whether this event source is active.
  template: '  # Jinja2 template for formatting events.

    {%- if include_timestamp %}at {{ timestamp }}{% endif %}

    Event from {{ source }}:

    {%- if include_metadata %}

    Metadata:

    {% for key, value in metadata.items() %}

    {{ key }}: {{ value }}

    {% endfor %}

    {% endif %}

    {{ content }}

    '
  include_metadata: true  # Control metadata visibility in template.
  include_timestamp: true  # Control timestamp visibility in template.
  session: target  # Which session the trigger's events run in (see TriggerSessionPolicy).

Email

Email trigger.

Email (YAML)
- type: email
  host: imap.gmail.com  # IMAP server hostname
  port: 993  # Server port (defaults to 993 for IMAP SSL)
  username: user@gmail.com  # Email account username/address
  password: '!ENV ENV_VAR_NAME'  # Account password or app-specific password
  folder: INBOX  # Folder/mailbox to monitor
  ssl: true  # Whether to use SSL/TLS connection
  check_interval: 60  # Seconds between inbox checks
  mark_seen: true  # Whether to mark processed emails as seen
  filters: {}  # Email filtering criteria
  max_size: null  # Maximum email size in bytes
  name: file_watcher  # Unique identifier for this event source.
  enabled: true  # Whether this event source is active.
  template: '  # Jinja2 template for formatting events.

    {%- if include_timestamp %}at {{ timestamp }}{% endif %}

    Event from {{ source }}:

    {%- if include_metadata %}

    Metadata:

    {% for key, value in metadata.items() %}

    {{ key }}: {{ value }}

    {% endfor %}

    {% endif %}

    {{ content }}

    '
  include_metadata: true  # Control metadata visibility in template.
  include_timestamp: true  # Control timestamp visibility in template.
  session: target  # Which session the trigger's events run in (see TriggerSessionPolicy).

Time event

Scheduled (cron) trigger.

Time event (YAML)
- type: time
  schedule: 0 9 * * 1-5  # Cron expression for scheduling (e.g. '0 9 * * 1-5' for weekdays at 9am)
  prompt: Daily status check  # Prompt to send to the agent when the schedule triggers.
  timezone: null  # Timezone for schedule (defaults to system timezone)
  skip_missed: false  # Whether to skip executions missed while agent was inactive
  name: file_watcher  # Unique identifier for this event source.
  enabled: true  # Whether this event source is active.
  template: '  # Jinja2 template for formatting events.

    {%- if include_timestamp %}at {{ timestamp }}{% endif %}

    Event from {{ source }}:

    {%- if include_metadata %}

    Metadata:

    {% for key, value in metadata.items() %}

    {{ key }}: {{ value }}

    {% endfor %}

    {% endif %}

    {{ content }}

    '
  include_metadata: true  # Control metadata visibility in template.
  include_timestamp: true  # Control timestamp visibility in template.
  session: target  # Which session the trigger's events run in (see TriggerSessionPolicy).

Event source

Trigger config specifically for connection events.

Event source (YAML)
- type: connection
  source: null  # Connection source name.
  target: null  # Connection to trigger.
  event: message_received  # Event type to trigger on.
  condition: null  # Condition-based filter for the event.
  name: file_watcher  # Unique identifier for this event source.
  enabled: true  # Whether this event source is active.
  template: '  # Jinja2 template for formatting events.

    {%- if include_timestamp %}at {{ timestamp }}{% endif %}

    Event from {{ source }}:

    {%- if include_metadata %}

    Metadata:

    {% for key, value in metadata.items() %}

    {{ key }}: {{ value }}

    {% endfor %}

    {% endif %}

    {{ content }}

    '
  include_metadata: true  # Control metadata visibility in template.
  include_timestamp: true  # Control timestamp visibility in template.
  session: target  # Which session the trigger's events run in (see TriggerSessionPolicy).

Event source

Trigger on events an MCP server publishes (MCP Events extension, SEP-3415).

The server must be one of the node's or the pool's MCP servers, with events: true. Experimental, as the extension is.

Event source (YAML)
- type: mcp_event
  server: github  # Name of the MCP server (its name, else its client ID).
  event: incident.triggered  # Event type to subscribe to, as the server lists it.
  arguments: {}  # Subscription arguments, matching the event type's input schema.
  delivery: auto  # auto uses push when the server offers it, else poll.
  prompt: null  # Jinja2 template for the prompt, with event (name, data, event_id,
  resume: true  # Keep the position in the event stream, so a restart delivers what came in meanwhile.
  min_poll_interval: 1.0  # Shortest wait between polls in seconds (poll delivery), whatever the server suggests.
  name: file_watcher  # Unique identifier for this event source.
  enabled: true  # Whether this event source is active.
  template: '  # Jinja2 template for formatting events.

    {%- if include_timestamp %}at {{ timestamp }}{% endif %}

    Event from {{ source }}:

    {%- if include_metadata %}

    Metadata:

    {% for key, value in metadata.items() %}

    {{ key }}: {{ value }}

    {% endfor %}

    {% endif %}

    {{ content }}

    '
  include_metadata: true  # Control metadata visibility in template.
  include_timestamp: true  # Control timestamp visibility in template.
  session: target  # Which session the trigger's events run in (see TriggerSessionPolicy).

Connection Event Conditions

Connection events can be filtered using conditions:

Content Condition

Simple content matching for connection events.

Content Condition (YAML)
1
2
3
4
5
- type: content
  words:  # List of words to match.
  - error
  - warning
  mode: any  # Matching mode.

Jinja2 Condition

Flexible Jinja2 condition for connection events.

Jinja2 Condition (YAML)
- type: jinja2
  template: '{{ event.message.content | length > 100 }}'  # Jinja2-Template (needs to return a "boolean" string).

Usage with Tasks

Event sources are configured with tasks to create reactive workflows:

tasks:
  monitor_logs:
    agent: log_analyzer
    event_source:
      type: file_watch
      paths: ["logs/*.log"]
      recursive: false
    parameters:
      analysis_level: "detailed"

  scheduled_backup:
    agent: backup_agent
    event_source:
      type: time
      schedule: "0 2 * * *"  # 2 AM daily

Best Practices

File Watching

  • Use specific glob patterns to minimize events
  • Set appropriate ignore_patterns to exclude temporary files
  • Consider recursive: false for better performance if subdirectories aren't needed

Webhooks

  • Always use authentication for production webhooks
  • Validate webhook payloads in your agent logic
  • Use environment variables for sensitive tokens

Email Events

  • Use dedicated email accounts for automation
  • Configure appropriate filters to avoid processing spam
  • Consider rate limiting for high-volume scenarios

Time Events

  • Use cron syntax for recurring schedules
  • Test schedules with online cron expression validators
  • Consider timezone implications for scheduled tasks

Connection Events

  • Use specific source/target filters to reduce noise
  • Combine with conditions for fine-grained control
  • Monitor event frequency to avoid performance issues

Configuration Notes

  • Event sources can be shared across multiple tasks
  • File watch and webhook events require the system to be running
  • Email events poll at configurable intervals
  • Connection events are processed in real-time
  • Time events use system timezone unless specified
  • All event sources support async operation