Spaces:
Paused
Paused
File size: 1,410 Bytes
fa8d021 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | from collections.abc import Awaitable, Callable
from contextvars import ContextVar
from dataclasses import dataclass, field
from typing import Generic, Literal, TypeVar
T = TypeVar("T")
# Context variable for tracking current iteration in tool execution loop
# This is used for telemetry to associate tool calls with their iteration
_current_iteration: ContextVar[int] = ContextVar("current_iteration", default=0)
def set_current_iteration(iteration: int) -> None:
"""Set the current iteration number for telemetry context."""
_current_iteration.set(iteration)
def get_current_iteration() -> int:
"""Get the current iteration number from telemetry context."""
return _current_iteration.get()
@dataclass
class GetOrCreateResult(Generic[T]):
"""Result of a get_or_create operation indicating whether the resource was created."""
resource: T
created: bool
on_commit: Callable[[], Awaitable[None]] | None = field(default=None, repr=False)
async def post_commit(self) -> None:
"""Run deferred cache operations after the transaction is committed."""
if self.on_commit is not None:
await self.on_commit()
TaskType = Literal[
"webhook", "summary", "representation", "dream", "deletion", "reconciler"
]
VectorSyncState = Literal["synced", "pending", "failed"]
DocumentLevel = Literal["explicit", "deductive", "inductive", "contradiction"]
|