academy.middleware¶
ActionHandler
module-attribute
¶
ActionHandler = Callable[[ActionCall], Awaitable[Any]]
Signature of the next handler passed to an action middleware.
ActionMiddleware
module-attribute
¶
ActionMiddleware = Callable[
[ActionCall, ActionHandler], Awaitable[Any]
]
Signature of an action middleware.
A middleware is an async callable invoked with the
ActionCall and the next handler in the
chain. A middleware may inspect or validate the call before awaiting the
next handler, transform or record the result after, short-circuit by
returning without awaiting the next handler, or deny the call by raising
an exception. Exceptions raised by middleware propagate exactly like
exceptions raised by the action itself (i.e., returned to a remote caller
as a UserErrorResponse).
ActionCall
dataclass
¶
ActionCall(
action: str,
agent_context: AgentContext[Any],
action_context: ActionContext,
args: tuple[Any, ...],
kwargs: dict[str, Any],
)
Description of one action invocation dispatched by a runtime.
Instances are passed to each
ActionMiddleware configured on
the RuntimeConfig.
Attributes:
-
action(str) –Name of the action being invoked.
-
agent_context(AgentContext[Any]) –Context of the agent executing the action (the agent ID is
agent_context.agent_id). -
action_context(ActionContext) –Context of this invocation (the requester is
action_context.source_idand the request message tag isaction_context.tag). -
args(tuple[Any, ...]) –Tuple of positional arguments.
-
kwargs(dict[str, Any]) –Dictionary of keyword arguments.