❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️
❄️

Triggers β€” Overview

Triggers β€” Overview

πŸš€ Triggers Overview

Triggers are how your agent or workflow starts. In .NET + Semantic Kernel (SK), a trigger receives an event (HTTP call, webhook, schedule, file change, log entry), prepares context, and invokes SK functions/plugins.

Trigger types at a glance

TriggerBest forTypical hostingNotes
πŸ”Ή HTTP RequestInteractive APIs/UX, synchronous responsesASP.NET Core on Kestrel/IIS, containerLow latency; add auth, rate limits, retries to downstream calls.
πŸ”Ή WebhookEvent-driven integrations from SaaSASP.NET Core, Functions, containerVerify signatures; idempotency; queue buffering for spikes.
πŸ”Ή Timer (Schedule)Periodic jobs, batch processingWorker Service, Functions, Linux cron, containerHandle drift/overlap; use distributed locks if multi-instance.
πŸ”Ή File System WatcherETL on new/changed filesWorker Service, container with mounted volumeDebounce/coalesce; fallback to directory scans for reliability.
πŸ”Ή Windows Event LogOps/Compliance, endpoint signalsWindows Service (Worker Service)Use EventLog/EventLogWatcher; plan service recovery/backoff.

Hosting options

  • πŸ–₯️ Standalone executable (Console/Worker Service)
    • Great for timers, FS watchers, and event log subscribers.
    • Use BackgroundService + DI; add graceful shutdown and health checks.
  • 🧩 Windows Service
    • Long-running, auto-start, restart-on-failure; ideal for FS watcher and event log.
    • Use the Worker Service template; configure recovery in Service Control Manager.
  • 🌐 ASP.NET Core (Kestrel/IIS)
    • Best for HTTP and webhooks. Hosts minimal APIs, controllers, and health endpoints.
    • Works on Windows/Linux; put behind a reverse proxy or use IIS in Windows.
  • πŸ“¦ Container (Docker/Kubernetes)
    • Portable across environments; good for any trigger type.
    • Add liveness/readiness probes; handle SIGTERM for graceful shutdown.
  • 🐧 Linux cron / systemd timer
    • Simple periodic execution for batch jobs.
    • Prefer a single-entry console app; log to stdout/stderr with structured logs.

Based on your hosting choice, any trigger pattern is possible. Choose for your ops model: deployability, observability, HA, and cost.

Design guidelines

  • DI lifetimes: prefer singleton for factories/clients, scoped for per-operation context, transient for stateless helpers. Create scopes inside background workers.
  • Resiliency: use IHttpClientFactory + Polly (timeouts, retries, circuit breaker). Add dead-letter queues for webhook handling.
  • Idempotency: dedupe webhook deliveries; use idempotency keys and persistent state.
  • Backpressure: debounce FS events; queue work and process with concurrency limits.
  • Scheduling: avoid overlap (use distributed mutex), track last-success timestamp for catch-up.
  • Observability: structured logs, OpenTelemetry tracing/metrics, health endpoints.
  • Security: input validation, signature verification, least-privilege tokens, secret rotation.

What’s next

Deep dives for each trigger with patterns, code, and trade-offs: