---
title: prefactor_core.operations module
editUrl: true
head: []
template: doc
sidebar:
  hidden: false
  attrs: {}
pagefind: true
draft: false
---

# prefactor_core.operations module

Operation types for prefactor-core.

Operations represent discrete units of work that can be queued and processed
asynchronously. Each operation type maps to a specific API action.

### *class* prefactor_core.operations.Operation(type: ~prefactor_core.operations.OperationType, payload: dict[str, ~typing.Any], timestamp: ~datetime.datetime, idempotency_key: str | None = None, metadata: dict[str, ~typing.Any] = <factory>)

Bases: `object`

A single operation to be queued and processed.

Operations are immutable and contain all data needed for execution.
They are created synchronously and processed asynchronously by workers.

#### type

The type of operation to perform.

* **Type:**
  [prefactor_core.operations.OperationType](#prefactor_core.operations.OperationType)

#### payload

Dictionary containing operation-specific data.

* **Type:**
  dict[str, Any]

#### timestamp

When the operation was created.

* **Type:**
  datetime.datetime

#### idempotency_key

Optional key for idempotent operations.

* **Type:**
  str | None

#### metadata

Optional additional metadata.

* **Type:**
  dict[str, Any]

### Example

from datetime import datetime, timezone

operation = Operation(
: type=OperationType.CREATE_SPAN,
  payload={
  <br/>
  > “instance_id”: “inst-123”,
  > “schema_name”: “agent:llm”,
  > “span_id”: “span-456”
  <br/>
  },
  timestamp=datetime.now(timezone.utc),
  idempotency_key=”span-456”

)

#### idempotency_key *: str | None* *= None*

#### metadata *: dict[str, Any]*

#### payload *: dict[str, Any]*

#### timestamp *: datetime*

#### type *: [OperationType](#prefactor_core.operations.OperationType)*

### *class* prefactor_core.operations.OperationType(\*values)

Bases: `Enum`

Types of operations that can be performed.

Each operation type corresponds to a specific API endpoint action.

#### CREATE_SPAN *= 4*

#### FINISH_AGENT_INSTANCE *= 3*

#### FINISH_SPAN *= 5*

#### REGISTER_AGENT_INSTANCE *= 1*

#### START_AGENT_INSTANCE *= 2*