|
18 | 18 | Span, |
19 | 19 | TaskInput, |
20 | 20 | Worker, |
| 21 | + WorkerStatus, |
21 | 22 | ) |
22 | 23 |
|
23 | 24 |
|
@@ -292,30 +293,77 @@ async def add_otel_span( |
292 | 293 | raise NotImplementedError() |
293 | 294 |
|
294 | 295 | async def query_rollouts( |
295 | | - self, *, status: Optional[Sequence[RolloutStatus]] = None, rollout_ids: Optional[Sequence[str]] = None |
296 | | - ) -> List[Rollout]: |
| 296 | + self, |
| 297 | + *, |
| 298 | + status_in: Optional[Sequence[RolloutStatus]] = None, |
| 299 | + rollout_id_in: Optional[Sequence[str]] = None, |
| 300 | + rollout_id_contains: Optional[str] = None, |
| 301 | + filter_logic: Literal["and", "or"] = "and", |
| 302 | + sort_by: Optional[str] = None, |
| 303 | + sort_order: Literal["asc", "desc"] = "asc", |
| 304 | + limit: int = -1, |
| 305 | + offset: int = 0, |
| 306 | + # Deprecated fields |
| 307 | + status: Optional[Sequence[RolloutStatus]] = None, |
| 308 | + rollout_ids: Optional[Sequence[str]] = None, |
| 309 | + ) -> Sequence[Rollout]: |
297 | 310 | """Retrieve rollouts filtered by status and/or explicit identifiers. |
298 | 311 |
|
| 312 | + This interface supports structured filtering, sorting, and pagination so |
| 313 | + callers can build simple dashboards without copying data out of the |
| 314 | + store. The legacy parameters `status` and `rollout_ids` remain valid and |
| 315 | + are treated as aliases for `status_in` and `rollout_id_in` |
| 316 | + respectively—when both the new and deprecated parameters are supplied |
| 317 | + the new parameters take precedence. |
| 318 | +
|
299 | 319 | Args: |
300 | | - status: Optional whitelist of [`RolloutStatus`][agentlightning.RolloutStatus] values. |
301 | | - rollout_ids: Optional whitelist of rollout identifiers to include. |
| 320 | + status_in: Optional whitelist of [`RolloutStatus`][agentlightning.RolloutStatus] values. |
| 321 | + rollout_id_in: Optional whitelist of rollout identifiers to include. |
| 322 | + rollout_id_contains: Optional substring match for rollout identifiers. |
| 323 | + filter_logic: Logical operator to combine filters. |
| 324 | + sort_by: Optional field to sort by. Must reference a numeric or string |
| 325 | + field on [`Rollout`][agentlightning.Rollout]. |
| 326 | + sort_order: Direction to sort when `sort_by` is provided. |
| 327 | + limit: Maximum number of rows to return. Use `-1` for "no limit". |
| 328 | + offset: Number of rows to skip before returning results. |
| 329 | + status: Deprecated field. Use `status_in` instead. |
| 330 | + rollout_ids: Deprecated field. Use `rollout_id_in` instead. |
302 | 331 |
|
303 | 332 | Returns: |
304 | | - A list of matching rollouts. Ordering is backend-defined but must be deterministic. |
| 333 | + A sequence of matching rollouts (or [`AttemptedRollout`][agentlightning.AttemptedRollout] |
| 334 | + when attempts exist). Ordering is deterministic when `sort_by` is set. |
| 335 | + The return value is not guaranteed to be a list. |
305 | 336 |
|
306 | 337 | Raises: |
307 | 338 | NotImplementedError: Subclasses must implement the query. |
308 | 339 | """ |
309 | 340 | raise NotImplementedError() |
310 | 341 |
|
311 | | - async def query_attempts(self, rollout_id: str) -> List[Attempt]: |
| 342 | + async def query_attempts( |
| 343 | + self, |
| 344 | + rollout_id: str, |
| 345 | + *, |
| 346 | + sort_by: Optional[str] = "sequence_id", |
| 347 | + sort_order: Literal["asc", "desc"] = "asc", |
| 348 | + limit: int = -1, |
| 349 | + offset: int = 0, |
| 350 | + ) -> Sequence[Attempt]: |
312 | 351 | """Return every attempt ever created for `rollout_id` in ascending sequence order. |
313 | 352 |
|
| 353 | + The parameters allow callers to re-order or paginate the attempts so that |
| 354 | + large retry histories can be streamed lazily. |
| 355 | +
|
314 | 356 | Args: |
315 | 357 | rollout_id: Identifier of the rollout being inspected. |
| 358 | + sort_by: Field to sort by. Must be a numeric or string field of |
| 359 | + [`Attempt`][agentlightning.Attempt]. Defaults to `sequence_id` (oldest first). |
| 360 | + sort_order: Order to sort by. |
| 361 | + limit: Limit on the number of results. `-1` for unlimited. |
| 362 | + offset: Offset into the results. |
316 | 363 |
|
317 | 364 | Returns: |
318 | | - Attempts sorted by `sequence_id` (oldest first). Returns an empty list when none exist. |
| 365 | + Sequence of Attempts. Returns an empty sequence when none exist. |
| 366 | + The return value is not guaranteed to be a list. |
319 | 367 |
|
320 | 368 | Raises: |
321 | 369 | NotImplementedError: Subclasses must implement the query. |
@@ -352,11 +400,35 @@ async def get_latest_attempt(self, rollout_id: str) -> Optional[Attempt]: |
352 | 400 | """ |
353 | 401 | raise NotImplementedError() |
354 | 402 |
|
355 | | - async def query_resources(self) -> List[ResourcesUpdate]: |
| 403 | + async def query_resources( |
| 404 | + self, |
| 405 | + *, |
| 406 | + resources_id: Optional[str] = None, |
| 407 | + resources_id_contains: Optional[str] = None, |
| 408 | + # Filter logic is not supported here because I can't see why it's needed. |
| 409 | + sort_by: Optional[str] = None, |
| 410 | + sort_order: Literal["asc", "desc"] = "asc", |
| 411 | + limit: int = -1, |
| 412 | + offset: int = 0, |
| 413 | + ) -> Sequence[ResourcesUpdate]: |
356 | 414 | """List every stored resource snapshot in insertion order. |
357 | 415 |
|
| 416 | + Supports lightweight filtering, sorting, and pagination for embedding in |
| 417 | + dashboards. |
| 418 | +
|
| 419 | + Args: |
| 420 | + resources_id: Optional identifier of the resources to include. |
| 421 | + resources_id_contains: Optional substring match for resources identifiers. |
| 422 | + sort_by: Optional field to sort by (must be numeric or string on |
| 423 | + [`ResourcesUpdate`][agentlightning.ResourcesUpdate]). |
| 424 | + sort_order: Order to sort by. |
| 425 | + limit: Limit on the number of results. `-1` for unlimited. |
| 426 | + offset: Offset into the results. |
| 427 | +
|
358 | 428 | Returns: |
359 | | - A chronological list of [`ResourcesUpdate`][agentlightning.ResourcesUpdate] objects. |
| 429 | + [`ResourcesUpdate`][agentlightning.ResourcesUpdate] objects. |
| 430 | + By default, resources are sorted in a deterministic but undefined order. |
| 431 | + The return value is not guaranteed to be a list. |
360 | 432 |
|
361 | 433 | Raises: |
362 | 434 | NotImplementedError: Subclasses must implement retrieval. |
@@ -439,19 +511,61 @@ async def wait_for_rollouts(self, *, rollout_ids: List[str], timeout: Optional[f |
439 | 511 | """ |
440 | 512 | raise NotImplementedError() |
441 | 513 |
|
442 | | - async def query_spans(self, rollout_id: str, attempt_id: str | Literal["latest"] | None = None) -> List[Span]: |
| 514 | + async def query_spans( |
| 515 | + self, |
| 516 | + rollout_id: str, |
| 517 | + attempt_id: str | Literal["latest"] | None = None, |
| 518 | + *, |
| 519 | + # Filtering |
| 520 | + trace_id: Optional[str] = None, |
| 521 | + trace_id_contains: Optional[str] = None, |
| 522 | + span_id: Optional[str] = None, |
| 523 | + span_id_contains: Optional[str] = None, |
| 524 | + parent_id: Optional[str] = None, |
| 525 | + parent_id_contains: Optional[str] = None, |
| 526 | + name: Optional[str] = None, |
| 527 | + name_contains: Optional[str] = None, |
| 528 | + filter_logic: Literal["and", "or"] = "and", |
| 529 | + # Pagination |
| 530 | + limit: int = -1, |
| 531 | + offset: int = 0, |
| 532 | + # Sorting |
| 533 | + sort_by: Optional[str] = "sequence_id", |
| 534 | + sort_order: Literal["asc", "desc"] = "asc", |
| 535 | + ) -> Sequence[Span]: |
443 | 536 | """Return the stored spans for a rollout, optionally scoped to one attempt. |
444 | 537 |
|
445 | | - Spans must be returned in ascending `sequence_id` order. Implementations may raise |
446 | | - a `RuntimeError` when spans were evicted or expired. |
| 538 | + Supports a handful of filters that cover the most common debugging |
| 539 | + scenarios (matching `trace_id`/`span_id`/`parent_id` or substring |
| 540 | + matches on the span name). `attempt_id="latest"` acts as a convenience |
| 541 | + that resolves the most recent attempt before evaluating filters. When |
| 542 | + `attempt_id=None`, spans across every attempt are eligible. By default |
| 543 | + results are sorted by `sequence_id` (oldest first). Implementations may |
| 544 | + raise a `RuntimeError` when spans were evicted or expired. |
447 | 545 |
|
448 | 546 | Args: |
449 | 547 | rollout_id: Identifier of the rollout being inspected. |
450 | 548 | attempt_id: Attempt identifier to filter by. Pass `"latest"` to retrieve only the |
451 | 549 | most recent attempt, or `None` to return all spans across attempts. |
| 550 | + trace_id: Optional trace ID to filter by. |
| 551 | + trace_id_contains: Optional substring match for trace IDs. |
| 552 | + span_id: Optional span ID to filter by. |
| 553 | + span_id_contains: Optional substring match for span IDs. |
| 554 | + parent_id: Optional parent span ID to filter by. |
| 555 | + parent_id_contains: Optional substring match for parent span IDs. |
| 556 | + name: Optional span name to filter by. |
| 557 | + name_contains: Optional substring match for span names. |
| 558 | + filter_logic: Logical operator to combine the optional filters above. |
| 559 | + The `rollout_id` argument is always applied with AND semantics. |
| 560 | + limit: Limit on the number of results. `-1` for unlimited. |
| 561 | + offset: Offset into the results. |
| 562 | + sort_by: Field to sort by. Must be a numeric or string field of |
| 563 | + [`Span`][agentlightning.Span]. |
| 564 | + sort_order: Order to sort by. |
452 | 565 |
|
453 | 566 | Returns: |
454 | 567 | An ordered list of spans (possibly empty). |
| 568 | + The return value is not guaranteed to be a list. |
455 | 569 |
|
456 | 570 | Raises: |
457 | 571 | NotImplementedError: Subclasses must implement the query. |
@@ -578,11 +692,29 @@ async def update_attempt( |
578 | 692 |
|
579 | 693 | async def query_workers( |
580 | 694 | self, |
581 | | - ) -> List[Worker]: |
| 695 | + *, |
| 696 | + status_in: Optional[Sequence[WorkerStatus]] = None, |
| 697 | + worker_id_contains: Optional[str] = None, |
| 698 | + filter_logic: Literal["and", "or"] = "and", |
| 699 | + sort_by: Optional[str] = None, |
| 700 | + sort_order: Literal["asc", "desc"] = "asc", |
| 701 | + limit: int = -1, |
| 702 | + offset: int = 0, |
| 703 | + ) -> Sequence[Worker]: |
582 | 704 | """Query all workers in the system. |
583 | 705 |
|
| 706 | + Args: |
| 707 | + status_in: Optional whitelist of [`WorkerStatus`][agentlightning.WorkerStatus] values. |
| 708 | + worker_id_contains: Optional substring match for worker identifiers. |
| 709 | + filter_logic: Logical operator to combine the optional filters above. |
| 710 | + sort_by: Field to sort by. Must be a numeric or string field of [`Worker`][agentlightning.Worker]. |
| 711 | + sort_order: Order to sort by. |
| 712 | + limit: Limit on the number of results. `-1` for unlimited. |
| 713 | + offset: Offset into the results. |
| 714 | +
|
584 | 715 | Returns: |
585 | | - A list of all workers. |
| 716 | + Sequence of Workers. Returns an empty sequence when none exist. |
| 717 | + The return value is not guaranteed to be a list. |
586 | 718 | """ |
587 | 719 | raise NotImplementedError() |
588 | 720 |
|
|
0 commit comments