TurnExecutorProtocol
Defined in the protocols module.AI Agent Contract for where a session’s agent turn executes (Issue #4011). The gateway calls :meth:
place to obtain a :class:TurnPlacement for a
session, then :meth:execute_turn to run the turn on that placement, and
:meth:teardown to reclaim a placement’s worker. The default
:class:InProcessTurnExecutor runs the turn on the current event loop,
reproducing today’s behaviour exactly; an isolated executor (subprocess /
container / remote, in the wrapper) runs it on its own worker so a wedged,
runaway, or crashed turn is contained to its session.
Contract:
- :meth:
placereturns the placement that ownssession_id’s turns. Implementations may cache a placement per session and bump itsepochwhen the backing worker is replaced. - :meth:
execute_turnrunsturn(anasyncno-arg callable the gateway already built for this turn) onplacementand returns its result. The in-process default awaitsturndirectly on the current loop. An isolated executor does not ship this live callable (and its captured loop/agent state) across a process boundary — the worker owns the session (via :meth:place) and rebuilds/dispatches the turn from serialisable inputs on its own side;turnthen acts as the gateway-side await point for that worker’s result.cancel_tokencarries the per-turn interrupt so the existing cancellation seam is preserved.limitsoptionally bounds the worker’s CPU/memory/wall time (honoured by isolated executors; ignored in-process). It raises :class:WorkerWedgedErrorif the placement’s worker can no longer make progress. - :meth:
teardownreclaimsplacement’s worker (kills the subprocess/container/remote worker, or is a no-op in-process), scoped to the owning session only.
Methods
place()
Return the placement that owns
session_id’s turns.execute_turn()
Run
turn on placement and return its result.teardown()
Reclaim
placement’s worker (scoped to its session).Source
View on GitHub
praisonaiagents/gateway/protocols.py at line 5672
