Actions¶
An Action is a named, schema-described unit of
work whose typed ports are nodes. Actions compose and stream.
Action¶
Bind local work with
bind_handler and start it with
run. Input and output ports are live
AsyncNode objects throughout the run;
wait is the terminal status boundary.
Inside a handler, make_nested on
Action preserves parent context and
call
dispatches the child. Bind a Session first with
bind_session to make that dispatch
remote, and use cancel when the caller no
longer needs the result.
a11.actions.action.Action
¶
Action(schema: ActionSchema, action_id: str = '', handler: Any | None = None, *, node_map: NodeMap | None = None, stream: WireStream | None = None, session: Session | None = None, registry: ActionRegistry | None = None, max_concurrent_nested_actions: SupportsInt | SupportsIndex = 64)
A runnable unit of work with typed input/output ports and headers.
Create an action from a schema and optional bindings.
done
property
¶
An asyncio.Event-shaped view of completion (await
action.done.wait()).
settings
property
writable
¶
settings: ActionSettings
The action's live ActionSettings (field writes propagate back).
make_node_id
staticmethod
¶
Build the node id for a named port of the given action.
run_in_background
staticmethod
¶
bind_handler
¶
bind_handler(handler: Any) -> Action
Bind the action's handler and return the action.
bind_node_map
¶
Bind the action's node map and return the action.
bind_registry
¶
bind_registry(registry: ActionRegistry | None) -> Action
Bind the action's registry and return the action.
bind_session
¶
Bind the action's session and return the action.
bind_stream
¶
bind_stream(stream: WireStream) -> Action
Bind the action's wire stream and return the action.
bind_streams_on_inputs_by_default
¶
bind_streams_on_inputs_by_default(bind: bool) -> Action
Set default stream binding for inputs and return the action.
bind_streams_on_outputs_by_default
¶
bind_streams_on_outputs_by_default(bind: bool) -> Action
Set default stream binding for outputs and return the action.
call
¶
Dispatch the action remotely and return a future of the action.
Examples:
Call a child action and consume its result:
clear_inputs_after_run
¶
clear_inputs_after_run(clear: bool = True) -> Action
Set whether inputs are cleared after run and return the action.
clear_outputs_after_run
¶
clear_outputs_after_run(clear: bool = True) -> Action
Set whether outputs are cleared after run and return the action.
contains_port
¶
Return True when the action has a port with the given name.
forward_header
¶
forward_header(target: Action, name: str) -> None
Copy a single header from this action to a target action.
forward_headers_with_prefix
¶
forward_headers_with_prefix(target: Action, prefix: str = 'x-a11-') -> None
Copy all headers with the given prefix to a target action.
get_action_message
¶
get_action_message() -> ActionMessage
Return the action's wire message representation.
get_dispatch_status
¶
Return the action's dispatch status, or None when not dispatched.
get_header
¶
Return header name (None if absent); decode UTF-8 to
str.
get_input
¶
get_input(name: str, bind_stream: bool | None = None) -> AsyncNode
Return the input port node with the given name.
get_output
¶
get_output(name: str, bind_stream: bool | None = None) -> AsyncNode
Return the output port node with the given name.
has_been_called
¶
Return True when the action has been dispatched remotely.
has_header
¶
Return True when the action has a header with the given name.
map_ports_from_message
¶
map_ports_from_message(message: ActionMessage) -> Action
Map the action's ports from a wire message and return the action.
set_header
¶
set_header(name: str, value: Any) -> Action
Set a header from a str or bytes value and return the action.
set_on_cancelled
¶
Register a synchronous callback invoked when the action is cancelled.
set_schema
¶
set_schema(schema: ActionSchema) -> Action
Set the action's schema and return the action.
set_span_attribute
¶
Set an attribute on the action's span; no-op when untraced.
set_span_input
¶
Record this action span's input (Langfuse observation input).
set_span_output
¶
Record this action span's output (Langfuse observation output).
set_span_status
¶
Set the span status explicitly ('ok', 'error' or 'unset').
wait
¶
Return a future that resolves when the action completes.
wait_for_dispatch
¶
Return a future that resolves when the action has been dispatched.
ActionRegistry¶
register publishes an async
handler under a schema name;
make_action then creates a
correctly configured action without repeating the schema.
a11.actions.registry.ActionRegistry
¶
Registry mapping action names to their schemas and handlers.
Create an empty action registry.
copy
¶
copy(clear_autofills: bool = True) -> ActionRegistry
Return a copy of the registry, optionally clearing autofills.
get_handler
¶
Return the Python handler registered under the given action name.
get_schema
¶
get_schema(action_name: str) -> ActionSchema
Return the schema registered under the given action name.
is_registered
¶
Return True when an action with the given name is registered.
list_registered_actions
¶
Return the names of all registered actions.
make_action
¶
make_action(action_name: str, action_id: str = '', node_map: NodeMap | None = None, stream: WireStream | None = None, session: Session | None = None) -> Action
make_action_message
¶
make_action_message(action_name: str, action_id: str = '') -> ActionMessage
Create a wire action message for a registered action name.
register
¶
register(action_name: str, schema: ActionSchema, handler: Any | None = None) -> None
register_sync
¶
register_sync(action_name: str, schema: ActionSchema, handler: Any) -> None
Register an action with a schema and a synchronous handler.
unregister
¶
Remove the action with the given name from the registry.
Schemas¶
a11.actions.action.ActionSchema
¶
ActionSchema(name: str, description: str = '', inputs: Any = {}, outputs: Any = {}, headers: Any = {}, output_to_json_field: Mapping[str, str] = {})
Schema describing an action's ports, headers and output mappings.
Create a validated action schema.
headers
property
writable
¶
Mapping of header names to their header schemas.
inputs
property
writable
¶
Mapping of input port names to their port schemas.
output_to_json_field
property
writable
¶
Mapping of output port names to JSON field names.
outputs
property
writable
¶
Mapping of output port names to their port schemas.
map_output_to_json
¶
Map an output port to a JSON field in the action's response.
a11.actions.action.ActionPortSchema
¶
ActionPortSchema(name: str, type: str, description: str = '', required: bool = False, unary: bool = False, autofills: Any | None = None, typeinfo: Any | None = None)
Schema describing a single input or output port of an action.
Create a validated port schema.
autofills
property
writable
¶
Node fragments used to autofill the port, or None entries.
a11.actions.action.ActionHeaderSchema
¶
Schema describing a single header of an action.
Create a validated header schema.
a11.actions.action.ActionSettings
¶
ActionSettings(bind_streams_on_inputs_by_default: bool | None = None, bind_streams_on_outputs_by_default: bool | None = None, clear_inputs_after_run: bool = False, clear_outputs_after_run: bool = False)
Runtime settings controlling an action's stream binding and cleanup.
Create action settings.
Header helpers¶
a11.actions.action.DefaultHeaders
¶
Bases: StrEnum
Well-known action metadata understood by A11 integrations.
Headers describe one call and normally flow into nested actions. Use these names instead of ad-hoc equivalents so deadlines, tool policy, user logs, and tracing remain connected across agent boundaries.