85742ab165
CPU Test / Lint - next (push) Waiting to run
Dashboard / Chromatic (push) Waiting to run
CPU Test / Lint - fast (push) Waiting to run
CPU Test / Build documentation (push) Waiting to run
CPU Test / Test (Store, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (Utilities, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (Weave, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (AgentOps, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (LLM proxy, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (Others, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (Store, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (Utilities, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (Weave, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (AgentOps, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (LLM proxy, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (Others, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (Store, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (Utilities, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (Weave, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (AgentOps, latest, Python 3.13) (push) Waiting to run
CPU Test / Test (LLM proxy, latest, Python 3.13) (push) Waiting to run
CPU Test / Test (Others, latest, Python 3.13) (push) Waiting to run
CPU Test / Test (Store, latest, Python 3.13) (push) Waiting to run
CPU Test / Lint - slow (push) Waiting to run
CPU Test / Lint - JavaScript (push) Waiting to run
CPU Test / Test (AgentOps, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (LLM proxy, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (Others, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (Utilities, latest, Python 3.13) (push) Waiting to run
CPU Test / Test (Weave, latest, Python 3.13) (push) Waiting to run
CPU Test / Test (JavaScript) (push) Waiting to run
Deploy Documentation / deploy (push) Has been cancelled
65 lines
2.4 KiB
Python
65 lines
2.4 KiB
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from typing import Protocol
|
|
|
|
from agentlightning.store.base import LightningStore
|
|
|
|
from .events import ExecutionEvent
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class AlgorithmBundle(Protocol):
|
|
"""Callable bundle produced by [`Trainer`][agentlightning.Trainer].
|
|
|
|
Execution strategies treat the returned coroutine as opaque, only providing
|
|
the shared store instance and cooperative stop event. Bundles typically
|
|
encapsulate algorithm setup plus adapter and LLM proxy, etc.
|
|
"""
|
|
|
|
async def __call__(self, store: LightningStore, event: ExecutionEvent) -> None:
|
|
"""Execute algorithm logic using ``store`` until completion or stop."""
|
|
|
|
|
|
class RunnerBundle(Protocol):
|
|
"""Callable bundle wrapping runner setup and the worker loop, as opposed to the
|
|
[`AlgorithmBundle`][agentlightning.AlgorithmBundle]."""
|
|
|
|
async def __call__(self, store: LightningStore, worker_id: int, event: ExecutionEvent) -> None:
|
|
"""Execute runner logic for ``worker_id`` using ``store`` and ``event``."""
|
|
|
|
|
|
class ExecutionStrategy:
|
|
"""Coordinate algorithm and runner bundles within a single process abstraction.
|
|
|
|
Strategies decide how many worker bundles to launch, whether to communicate
|
|
through shared memory or an HTTP boundary, and how to react to shutdown
|
|
signals. They intentionally avoid inspecting the bundle internals; instead,
|
|
each bundle remains responsible for its own scheduling semantics.
|
|
|
|
!!! note
|
|
Implementations must honor the [execute()][agentlightning.ExecutionStrategy.execute]
|
|
contract by propagating `KeyboardInterrupt` and ensuring resources are
|
|
released when an error occurs on either side of the algorithm/runner
|
|
pair.
|
|
"""
|
|
|
|
def execute(self, algorithm: AlgorithmBundle, runner: RunnerBundle, store: LightningStore) -> None:
|
|
"""Run the provided bundles using the configured orchestration model.
|
|
|
|
Args:
|
|
algorithm: Callable bundle responsible for algorithm execution.
|
|
runner: Callable bundle for runner workers.
|
|
store: Concrete [`LightningStore`][agentlightning.LightningStore]
|
|
shared across bundles.
|
|
|
|
Raises:
|
|
NotImplementedError: Subclasses must provide the orchestration
|
|
implementation.
|
|
"""
|
|
|
|
raise NotImplementedError()
|