Skip to content

API Reference parrot.scheduler.inprocess

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.scheduler.inprocess

View source

InProcessScheduler — lightweight APScheduler wrapper for agent processes.

FEAT-453, Module 8 (Goal G6), Decision D1.

FEAT-203 deliberately moved task scheduling out of ai-parrot core into ai-parrot-server[scheduler] (parrot/scheduler/__init__.py is a lazy PEP 562 shim resolving AgentSchedulerManager and friends from that satellite). This module is a deliberate, partial reversal of that move by operator decision (spec §8): an agent process needs to schedule reminders (e.g. Spanish tax-calendar deadlines) without taking a dependency on the full server distribution.

This must never shadow the satellite. InProcessScheduler is a distinctly-named class living alongside (not instead of) parrot.scheduler's _SERVER_CLASSES delegation — AgentSchedulerManager, ScheduleType, schedule, schedule_daily_report and schedule_weekly_report all keep resolving through the existing __getattr__ in parrot/scheduler/__init__.py (this module does not touch that file at all).

Layering note: this is core (ai-parrot). ai-parrot-tools (which owns GoogleCalendarToolkit) depends on core, never the reverse — so :func:schedule_tax_reminder takes an already-constructed calendar-like object and only references its type under TYPE_CHECKING, never at runtime, to avoid a reverse/circular package dependency.

Alias HumanChannel

Re-exported from parrot.human.channels.base.HumanChannel.

Class InProcessScheduler

Lightweight APScheduler wrapper for agent processes that must schedule work WITHOUT deploying ai-parrot-server.

Deliberately does NOT shadow AgentSchedulerManager, which stays satellite-only.

Method InProcessScheduler.start

Start the underlying APScheduler event-loop integration.

Idempotent — calling twice is a no-op.

start() -> None

Method InProcessScheduler.stop

Stop the scheduler. Idempotent — calling twice is a no-op.

stop() -> None

Method InProcessScheduler.add_cron

Schedule callback on a 5-field cron expression.

add_cron(name: str, cron: str, callback: Callable[..., Any]) -> str

Parameter Type Default Description
name str Human-readable job name; also used as the APScheduler job id (re-registering the same name replaces the prior job).
cron str A 5-field cron expression: "minute hour day month day_of_week" (standard crontab order).
callback Callable[..., Any] Sync or async callable invoked on each trigger. APScheduler awaits coroutine functions natively.

Returns: str — The APScheduler job id (equal to name).

Raises:

  • ValueError — If cron does not have exactly 5 fields.

Class TaxDeadline

A single filing deadline to remind about.

Deliberately does not hardcode any real Spanish tax dates — FEAT-449 (legal-norms-graph-boe) is adjacent, not authoritative for filing deadlines (spec §7 Known Risks); callers supply deadlines from their own (AEAT-calendar-derived) source of truth.

Parameter Type Default Description
name str
due_date date
reminder_lead_days int 7

Fields:

Field Type Default Description
name str Human-readable deadline label (e.g. "Modelo 303 Q1").
due_date date The filing deadline date.
reminder_lead_days int 7 How many days before due_date to fire the reminder (default 7).

Attribute logger

Function notify_tax_deadline

Default :func:schedule_tax_reminder callback: notify channel that deadline is approaching.

A convenience default for callers that only need the notification half (calendar-event creation is left to the caller's own closure, composed alongside this if both are wanted, since this module cannot import GoogleCalendarToolkit — see the layering note above).

notify_tax_deadline(deadline: TaxDeadline, *, channel: Optional[HumanChannel] = None, recipient: str = _DEFAULT_RECIPIENT) -> None

Parameter Type Default Description
deadline TaxDeadline
channel Optional[HumanChannel] None
recipient str _DEFAULT_RECIPIENT

Function schedule_tax_reminder

Register a cron reminder for deadline.

Fires once a year on due_date - reminder_lead_days at 09:00, calling on_reminder — e.g. a closure that creates a Google Calendar event (:meth:~parrot_tools.google.calendar.GoogleCalendarToolkit.create_event) and/or notifies a :class:~parrot.human.channels.base.HumanChannel. This function takes a generic callback rather than importing a concrete calendar/toolkit type directly (layering: this module is core; GoogleCalendarToolkit lives in the ai-parrot-tools satellite, which depends on core, never the reverse).

schedule_tax_reminder(scheduler: InProcessScheduler, deadline: TaxDeadline, *, on_reminder: Callable[[TaxDeadline], Awaitable[None]]) -> str

Parameter Type Default Description
scheduler InProcessScheduler The :class:InProcessScheduler to register the job on.
deadline TaxDeadline The :class:TaxDeadline to remind about.
on_reminder Callable[[TaxDeadline], Awaitable[None]] Async callback invoked with deadline when the reminder fires.

Returns: str — The APScheduler job id.

Function sweep_checkpoint_retention

Archive (never silently delete) checkpoint files older than retention_days, alerting over channel when anything is archived.

Decision D3: a checkpoint is the record of what was already written to the accounting system. Deleting it early causes duplicate expense registration on the next resume — so aged-out checkpoints are moved to archive_dir (never removed), and the sweep always alerts so a human can confirm reconciliation before the archive is ever cleaned up manually.

sweep_checkpoint_retention(checkpoint_dir: Path, *, retention_days: int = 90, archive_dir: Optional[Path] = None, channel: Optional[HumanChannel] = None, recipient: str = _DEFAULT_RECIPIENT) -> List[Path]

Parameter Type Default Description
checkpoint_dir Path Directory containing *.json checkpoint/manifest files (see parrot_tools.business_automation.ingest).
retention_days int 90 Age threshold in days (default 90 — a quarterly cycle plus margin).
archive_dir Optional[Path] None Where to move aged-out files (default: checkpoint_dir / "archive").
channel Optional[HumanChannel] None Optional :class:HumanChannel to alert when files are archived.
recipient str _DEFAULT_RECIPIENT Notification recipient label.

Returns: List[Path] — The list of archived file paths (in their new, archived location). Empty if nothing was old enough to archive.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally