Skip to content

API Reference parrot.handlers.crew.saved_execution_service

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

parrot.handlers.crew.saved_execution_service

View source

SavedExecutionService — orchestration layer for execution history, replay, and scheduling (FEAT-307).

Framework-agnostic: does NOT import aiohttp or any HTTP concern. The HTTP handler (CrewExecutionHistoryHandler) is responsible for translating the exceptions raised here into HTTP responses.

Class CrewNotFoundError

The crew referenced by a saved execution no longer exists (or no bot_manager is configured to resolve it).

Alias ExecutionFilter

Re-exported from parrot.handlers.crew.models.ExecutionFilter.

Class ExecutionNotFoundError

The requested execution record doesn't exist (or isn't owned by the caller — ownership failures are indistinguishable from "not found" by design, to avoid leaking the existence of other tenants'/users' records).

Attribute METHOD_PARAM_MAP

Type: dict[str, str]

Class ReplayValidationError

The replay/schedule request fails validation for reasons other than "not found" (missing prompt, unsupported method, unknown method).

Alias ResultStorage

Re-exported from parrot.bots.flows.core.storage.backends.base.ResultStorage.

Class SavedExecutionError

Base exception for SavedExecutionService errors.

Subclasses ValueError for backward compatibility with existing except ValueError callers/tests, while giving the HTTP handler a typed hierarchy to map to status codes instead of fragile substring matching on the exception message.

Class SavedExecutionService

Orchestration layer for execution history, replay, and scheduling.

Thin coordination layer between the HTTP handler and the storage / bot-manager / scheduler-manager backends. Contains no HTTP-specific logic — callers (handlers) translate raised exceptions into responses.

Parameter Type Default Description
storage ResultStorage The ResultStorage backend to read/delete executions.
bot_manager Any None Object exposing async def get_crew(identifier, as_new=False, tenant=None) -> tuple[AgentCrew | None, CrewDefinition | None].
scheduler_manager Any None Object exposing AgentSchedulerManager .add_schedule().

Attributes:

Attribute Type Description
storage The ResultStorage backend used for read/delete.
bot_manager Resolves crews by name/id for replay (get_crew()).
scheduler_manager Creates APScheduler jobs for scheduling.

Method SavedExecutionService.list_executions

List saved executions for a tenant/user, with optional filters.

list_executions(tenant: str, user_id: str, filters: Optional[ExecutionFilter] = None, limit: int = 20, offset: int = 0) -> tuple[list[dict], int]

Parameter Type Default Description
tenant str Tenant identifier — always enforced as a storage filter.
user_id str User identifier — always enforced as a storage filter.
filters Optional[ExecutionFilter] None Optional additional filters (crew_name, method, date range).
limit int 20 Maximum number of items to return.
offset int 0 Number of items to skip (pagination).

Returns: tuple[list[dict], int] — A tuple of (items, total).

Method SavedExecutionService.get_execution

Retrieve a single saved execution by id.

get_execution(tenant: str, user_id: str, execution_id: str) -> Optional[dict]

Parameter Type Default Description
tenant str Tenant identifier.
user_id str User identifier.
execution_id str Storage-layer record id.

Returns: Optional[dict] — The execution document if found AND it belongs to the given tenant/user, None otherwise.

Method SavedExecutionService.replay_execution

Re-run a saved execution's prompt against the crew's current config.

replay_execution(tenant: str, user_id: str, execution_id: str) -> dict

Parameter Type Default Description
tenant str Tenant identifier.
user_id str User identifier.
execution_id str Storage-layer record id of the execution to replay.

Returns: dict — A job dict: {"job_id", "crew_name", "method", "status", "result"}.

Raises:

  • ExecutionNotFoundError — If the execution is not found (or not owned by tenant/user_id).
  • ReplayValidationError — If the original prompt is unavailable or the saved method cannot be replayed (see _UNSUPPORTED_REPLAY_METHODS).
  • CrewNotFoundError — If the crew no longer exists (or no bot_manager is configured).

Method SavedExecutionService.schedule_execution

Create a recurring/one-off schedule from a saved execution.

schedule_execution(tenant: str, user_id: str, execution_id: str, schedule_config: ScheduleRequest) -> dict

Parameter Type Default Description
tenant str Tenant identifier.
user_id str User identifier.
execution_id str Storage-layer record id of the execution to schedule.
schedule_config ScheduleRequest Schedule type + config + metadata.

Returns: dict — The created JobDefinition serialised with model_dump(mode="json").

Raises:

  • ExecutionNotFoundError — If the execution is not found (or not owned by tenant/user_id).
  • ReplayValidationError — If the original prompt is unavailable.
  • SchedulerUnavailableError — If no scheduler manager is configured.

Method SavedExecutionService.delete_execution

Delete a saved execution.

delete_execution(tenant: str, user_id: str, execution_id: str) -> bool

Parameter Type Default Description
tenant str Tenant identifier.
user_id str User identifier.
execution_id str Storage-layer record id.

Returns: bool — True if a record belonging to this tenant/user was deleted, False otherwise.

Alias ScheduleRequest

Re-exported from parrot.handlers.crew.models.ScheduleRequest.

Class SchedulerUnavailableError

No scheduler_manager is configured on the service.

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