> ## Documentation Index
> Fetch the complete documentation index at: https://docs-code.palyra.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Automation: Routines, Cron, and Objectives

<details>
  <summary>Relevant source files</summary>

  The following files were used as context for generating this wiki page:

  * crates/palyra-daemon/src/application/channel\_commands/mod.rs
  * crates/palyra-daemon/src/application/conversation\_bindings/mod.rs
  * crates/palyra-daemon/src/application/inbound\_coalescer/mod.rs
  * crates/palyra-daemon/src/application/outbound\_lifecycle/mod.rs
  * crates/palyra-daemon/src/application/tool\_runtime/routines.rs
  * crates/palyra-daemon/src/cron.rs
  * crates/palyra-daemon/src/objectives.rs
  * crates/palyra-daemon/src/routines.rs
  * crates/palyra-daemon/src/transport/http/handlers/admin/channels/connectors/discord.rs
  * crates/palyra-daemon/src/transport/http/handlers/admin/channels/message\_mutations.rs
  * crates/palyra-daemon/src/transport/http/handlers/admin/skills.rs
  * crates/palyra-daemon/src/transport/http/handlers/console/objectives.rs
  * crates/palyra-daemon/src/transport/http/handlers/console/routines.rs
  * crates/palyra-daemon/src/webhooks.rs
  * crates/palyra-daemon/tests/admin\_surface.rs
</details>

Palyra's automation layer provides a robust framework for unattended agent execution, scheduled maintenance, and long-lived goal tracking. It bridges the gap between reactive messaging and proactive system behavior through a unified scheduling and objective-management system.

## High-Level Automation Architecture

The automation layer is built on three pillars: the **Cron Scheduler**, **Routines**, and **Objectives**. These components interact to ensure that agents can fire based on time, events, or persistent goals while adhering to safety and approval constraints.

### Natural Language to Code Entity Space: Automation Dispatch

This diagram illustrates how a user's intent or a scheduled trigger flows from high-level concepts into the internal daemon machinery.

```mermaid theme={null}
graph TD
    subgraph "Natural Language Space"
        A["'Run every Friday at 5pm'"]
        B["'Monitor this file for changes'"]
        C["'Achieve this long-term goal'"]
    end

    subgraph "Code Entity Space"
        A -->|Parsed by| D["natural_language_schedule_preview"]
        D -->|Persisted in| E["CronJobRecord"]

        B -->|Defined in| F["RoutineTriggerKind::FileWatch"]
        F -->|Monitored by| G["evaluate_file_watch_change"]

        C -->|Managed by| H["ObjectiveRecord"]
        H -->|Drives| I["ObjectiveAutomationBinding"]

        E -->|Polled by| J["spawn_scheduler_loop"]
        G -->|Triggers| K["RoutineRegistry"]
        I -->|Triggers| K

        J -->|Dispatches| L["GatewayRuntimeState::dispatch_run"]
        K -->|Dispatches| L
    end
```

**Sources:** [crates/palyra-daemon/src/cron.rs#3-13](http://crates/palyra-daemon/src/cron.rs#3-13), [crates/palyra-daemon/src/routines.rs#94-103](http://crates/palyra-daemon/src/routines.rs#94-103), [crates/palyra-daemon/src/objectives.rs#3-7](http://crates/palyra-daemon/src/objectives.rs#3-7)

***

## Routines and Cron Scheduler

The `spawn_scheduler_loop` is the heart of Palyra's proactive execution. It handles time-based triggers defined via cron expressions or natural language phrases.

* **Deterministic Scheduling:** The scheduler uses stable hashes for jitter to prevent "thundering herd" issues across multiple instances [crates/palyra-daemon/src/cron.rs#10-13](http://crates/palyra-daemon/src/cron.rs#10-13).
* **Misfire & Concurrency:** Supports policies like `Skip`, `CatchUp`, and `QueueOne` to handle daemon downtime or overlapping runs [crates/palyra-daemon/src/cron.rs#58-66](http://crates/palyra-daemon/src/cron.rs#58-66).
* **Routine Integration:** Routines wrap cron jobs with additional metadata, including delivery targets (e.g., Slack/Discord) and quiet hour constraints [crates/palyra-daemon/src/routines.rs#45-50](http://crates/palyra-daemon/src/routines.rs#45-50).
* **Tool Interface:** The `palyra.routines.control` and `palyra.routines.query` tools allow agents to self-manage their own automations [crates/palyra-daemon/src/application/tool\_runtime/routines.rs#3-10](http://crates/palyra-daemon/src/application/tool_runtime/routines.rs#3-10).

For details on scheduling logic, jitter, and routine synchronization, see **[Routines and Cron Scheduler](/automation_routines_cron_and_objectives/routines_and_cron_scheduler)**.

***

## Objectives, Webhooks, and Event Triggers

Objectives represent long-lived goals that may span multiple sessions and weeks. They provide a structured way to track progress and manage budgets for autonomous agents.

* **Goal Tracking:** The `ObjectiveRecord` tracks the `ObjectiveState` (Active, Paused, etc.) and maintains a history of attempts and approaches [crates/palyra-daemon/src/objectives.rs#3-7](http://crates/palyra-daemon/src/objectives.rs#3-7).
* **Budgets & Guardrails:** Objectives can enforce `max_runs` or `max_tokens` to prevent runaway costs during autonomous operation [crates/palyra-daemon/src/objectives.rs#142-152](http://crates/palyra-daemon/src/objectives.rs#142-152).
* **Webhook Ingestion:** The `WebhookRegistry` allows external systems to trigger Palyra routines via HMAC-SHA256 signed payloads [crates/palyra-daemon/src/webhooks.rs#3-9](http://crates/palyra-daemon/src/webhooks.rs#3-9).
* **Workspace Projection:** Objectives can project their status directly into workspace documents using "managed blocks" [crates/palyra-daemon/src/transport/http/handlers/console/objectives.rs#2-11](http://crates/palyra-daemon/src/transport/http/handlers/console/objectives.rs#2-11).

### Code Entity Mapping: Objective Lifecycle

The relationship between objective goals and their underlying automation components.

| Code Entity           | Purpose                                                        | File Reference                                                                                                                                                |
| :-------------------- | :------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `ObjectiveRecord`     | The primary document for goal state and history.               | [crates/palyra-daemon/src/objectives.rs#3-7](http://crates/palyra-daemon/src/objectives.rs#3-7)                                                               |
| `ObjectiveBudget`     | Enforces token and run limits on autonomous agents.            | [crates/palyra-daemon/src/objectives.rs#145-152](http://crates/palyra-daemon/src/objectives.rs#145-152)                                                       |
| `ObjectiveJudgeInput` | Data structure used by LLM judges to evaluate goal completion. | [crates/palyra-daemon/src/transport/http/handlers/console/objectives.rs#31](http://crates/palyra-daemon/src/transport/http/handlers/console/objectives.rs#31) |
| `WebhookRegistry`     | Manages external triggers and signature verification.          | [crates/palyra-daemon/src/webhooks.rs#194-196](http://crates/palyra-daemon/src/webhooks.rs#194-196)                                                           |

For details on the objective judge, planning regressions, and webhook replay protection, see **[Objectives, Webhooks, and Event Triggers](/automation_routines_cron_and_objectives/objectives_webhooks_and_event_triggers)**.

***

## Summary of Key Automation Components

| Component            | Responsibility                                                    | Primary Logic                                                    |
| :------------------- | :---------------------------------------------------------------- | :--------------------------------------------------------------- |
| **Cron Loop**        | Minute-by-minute tick evaluation and misfire recovery.            | `spawn_scheduler_loop` [src/cron.rs]()                           |
| **Routine Registry** | Mapping triggers to specific agent prompts and delivery channels. | `RoutineRegistry` [src/routines.rs]()                            |
| **Objective Store**  | Long-term goal persistence and budget enforcement.                | `ObjectiveRecord` [src/objectives.rs]()                          |
| **Webhook Handler**  | Secure ingestion of external events via `palyra-safety`.          | `WebhookRegistry` [src/webhooks.rs]()                            |
| **Coalescer**        | Debouncing rapid-fire events into single agent turns.             | `InboundCoalescer` [src/application/inbound\_coalescer/mod.rs]() |

**Sources:** [crates/palyra-daemon/src/cron.rs#3-8](http://crates/palyra-daemon/src/cron.rs#3-8), [crates/palyra-daemon/src/routines.rs#3-7](http://crates/palyra-daemon/src/routines.rs#3-7), [crates/palyra-daemon/src/objectives.rs#3-7](http://crates/palyra-daemon/src/objectives.rs#3-7), [crates/palyra-daemon/src/webhooks.rs#3-9](http://crates/palyra-daemon/src/webhooks.rs#3-9), [crates/palyra-daemon/src/application/inbound\_coalescer/mod.rs#1-8](http://crates/palyra-daemon/src/application/inbound_coalescer/mod.rs#1-8)

## Child Pages

* [Routines and Cron Scheduler](/automation_routines_cron_and_objectives/routines_and_cron_scheduler)
* [Objectives, Webhooks, and Event Triggers](/automation_routines_cron_and_objectives/objectives_webhooks_and_event_triggers)
