featherweight.observers¶
observers ¶
Observers: what the runner tells the outside world, as it happens. featherweight stores nothing from them.
An observer overrides the hooks it cares about; every hook does nothing by default. The runner calls them inline, with a
timeout, and ignores their errors: an observer never changes or fails a run. The records carry metadata always, and content
(inputs, outputs, messages, error text) only for an observer whose capture_content is true.
JobStart ¶
Bases: _Record
A job begins to run (in your process or on a worker).
JobSubmitted ¶
Bases: _Record
A client submitted a job. An observer may return the carrier that travels in the message.
AttemptStart ¶
Bases: _Record
One attempt of an agent begins: one per row of attempts.
RunReused ¶
Bases: _Record
A step of a resumed job was answered from the result store: it is not an attempt, and has no model calls.
Scope ¶
What job() and attempt() yield: the observer's handle on the work that runs inside it. finish(end) is called with the
outcome (a JobEnd or an AttemptEnd) before the scope is left.
Observer ¶
Bases: ABC
Hears what the runner does. Override the hooks you want; each does nothing by default.
job and attempt wrap the work (so an observer can make its span the current one while it runs); the model-call and
tool-call hooks are events, because they come from a callback in another task. Check an implementation with
featherweight.testing.check_observer.
submitted
async
¶
submitted(job: JobSubmitted) -> Mapping[str, str] | None
A job was submitted. Return the carrier (for example the W3C trace context) that should travel in the message.
Entered ¶
Entered(
observers: Observers,
entered: list[
tuple[
Observer,
AbstractAsyncContextManager[Scope],
Scope | None,
]
],
)
The scopes of every observer, entered for one job or one attempt. leave(end) finishes and leaves them, once.
Observers ¶
Observers(
observers: Sequence[Observer] = (), timeout: float = 1.0
)
The observers of a runner: calls each inline, with a timeout, and ignores what they raise.
view ¶
view(observer: Observer, record: R) -> R
The record as this observer may see it: content is dropped for one that did not ask.
safely
async
¶
safely(
call: Callable[[], Awaitable[T]],
hook: str,
observer: Observer | None = None,
) -> T | None
Make the call and await it with the timeout; what it raises, in either step, is logged and ignored (a cancellation is not).
enter
async
¶
enter(hook: str, start: _Record) -> Entered
Enter observer.job(start) or observer.attempt(start) of every observer.
submitted
async
¶
submitted(record: JobSubmitted) -> dict[str, str]
The carriers that the observers return for a submitted job, merged.
callbacks ¶
callbacks(
attempt_id: str, provider: str, model: str
) -> list[BaseCallbackHandler]
The LangChain callback handler for one attempt, or none when there is no observer.