|
A11 (C++ runtime)
Native C++ implementation of the A11 action and streaming runtime
|
A11's unit of work: a schema-described, asynchronously run operation. More...
#include <cpp/a11/actions/action.h>
Public Member Functions | |
| std::string | GetId () const |
| Returns this action's instance id. | |
| absl::Status | SetId (std::string action_id) |
| Sets this action's instance id. | |
| ActionSchema | GetSchema () const |
| Returns this action's schema. | |
| absl::Status | SetSchema (ActionSchema schema) |
| Replaces this action's schema (validated). | |
| absl::Status | BindHandler (ActionHandler handler) |
| Binds the handler invoked when the action runs. | |
| ActionHandler | GetHandler () const |
| Returns the currently bound handler. | |
| bool | HasHandler () const |
| Whether a handler is bound. | |
| ActionSettings | GetSettings () const |
| Returns the action's current settings. | |
| absl::Status | SetSettings (ActionSettings settings) |
| Replaces the action's settings. | |
| absl::Status | BindStreamsOnInputsByDefault (bool bind) |
| Sets whether input port streams are bound by default. | |
| absl::Status | BindStreamsOnOutputsByDefault (bool bind) |
| Sets whether output port streams are bound by default. | |
| absl::Status | ClearInputsAfterRun (bool clear=true) |
| Sets whether inputs are released after each run. | |
| absl::Status | ClearOutputsAfterRun (bool clear=true) |
| Sets whether outputs are released after each run. | |
| absl::Status | BindNodeMap (std::shared_ptr< nodes::NodeMap > node_map) |
| Binds the node map that backs this action's ports. | |
| std::shared_ptr< nodes::NodeMap > | GetNodeMap () const |
| Returns the bound node map. | |
| absl::Status | BindStream (std::shared_ptr< net::WireStream > stream) |
| Binds the wire stream used to dispatch the action remotely. | |
| std::shared_ptr< net::WireStream > | GetStream () const |
| Returns the bound wire stream. | |
| absl::Status | BindRegistry (std::shared_ptr< ActionRegistry > registry) |
| Binds the registry used to resolve nested actions by name. | |
| std::shared_ptr< ActionRegistry > | GetRegistry () const |
| Returns the bound registry. | |
| absl::Status | BindSession (std::shared_ptr< service::Session > session) |
| Binds the owning session. | |
| std::shared_ptr< service::Session > | GetSession () const |
| Returns the owning session, if any. | |
| absl::StatusOr< std::shared_ptr< nodes::AsyncNode > > | GetNode (std::string node_id) |
Returns the port node with raw id node_id. | |
| absl::StatusOr< std::shared_ptr< nodes::AsyncNode > > | GetInput (std::string name, std::optional< bool > bind_stream=std::nullopt) |
Returns the input port node named name. | |
| absl::StatusOr< std::shared_ptr< nodes::AsyncNode > > | GetOutput (std::string name, std::optional< bool > bind_stream=std::nullopt) |
Returns the output port node named name. | |
| absl::StatusOr< std::shared_ptr< nodes::AsyncNode > > | GetPort (std::string name) |
Returns the input or output port node named name. | |
| bool | ContainsPort (std::string_view name) const |
Whether the schema declares a port named name. | |
| data::ActionMessage | GetActionMessage () const |
| Returns the wire a11::data::ActionMessage describing this action. | |
| absl::Status | MapPortsFromMessage (const data::ActionMessage &message) |
Binds this action's ports to the nodes named in message. | |
| data::ByteMap | Headers () const |
| Returns a copy of all headers. | |
| absl::StatusOr< std::optional< data::Bytes > > | GetHeader (std::string_view name) const |
Returns header name, or nullopt when absent. | |
| bool | HasHeader (std::string_view name) const |
Whether header name is set. | |
| absl::Status | SetHeader (std::string name, data::Bytes value) |
Sets header name to value. | |
| absl::Status | RemoveHeader (std::string_view name) |
Removes header name. | |
| absl::Status | ForwardHeader (const std::shared_ptr< Action > &target, std::string_view name) const |
Copies header name from this action onto target. | |
| absl::Status | ForwardHeadersWithPrefix (const std::shared_ptr< Action > &target, std::string_view prefix=kActionHeaderPrefix) const |
Copies all headers starting with prefix onto target. | |
| absl::StatusOr< std::shared_ptr< Action > > | MakeNested (const ActionSchema &schema, bool propagate_io=true, bool forward_headers=true) |
| Creates a nested action from a schema, parented to this action. | |
| absl::StatusOr< std::shared_ptr< Action > > | MakeNested (std::string_view action_name, bool propagate_io=true, bool forward_headers=true) |
| Creates a nested action by name from the bound registry. | |
| absl::StatusOr< std::shared_ptr< Action > > | Run () |
| Runs the action's handler locally. | |
| a11::Future< std::shared_ptr< Action > > | Call (data::ByteMap wire_headers={}) |
| Dispatches the action to a peer over the bound wire stream. | |
| a11::Future< absl::Status > | WaitForDispatch (absl::Duration timeout=absl::InfiniteDuration()) |
| Awaits acceptance of a remote dispatch. | |
| a11::Future< std::shared_ptr< Action > > | Wait (absl::Duration timeout=absl::InfiniteDuration()) |
| Awaits completion of the action. | |
| absl::Status | Cancel () |
| Requests cancellation of the action (local or remote). | |
| absl::Status | SetOnCancelled (OnActionCancelled callback) |
| Registers a callback invoked when the action is cancelled. | |
| std::string | TraceId () const |
| This action's trace id as lowercase hex. | |
| std::string | SpanId () const |
| This action's span id as lowercase hex, or empty when untraced. | |
| void | SetSpanAttribute (std::string_view key, std::string_view value) |
| Sets a string attribute on this action's span. | |
| void | SetSpanAttribute (std::string_view key, std::int64_t value) |
| Sets an integer attribute on this action's span. | |
| void | SetSpanAttribute (std::string_view key, bool value) |
| Sets a boolean attribute on this action's span. | |
| void | SetSpanAttribute (std::string_view key, double value) |
| Sets a floating-point attribute on this action's span. | |
| void | SetSpanName (std::string_view name) |
| Overrides the display name of this action's span. | |
| void | SetSpanStatus (obs::SpanStatus status, std::string_view description={}) |
| Sets the span status explicitly. | |
| bool | IsDone () const |
| Whether the action has finished (successfully or not). | |
| bool | HasBeenRun () const |
| Whether the action has been started with Run. | |
| bool | HasBeenCalled () const |
| Whether the action has been dispatched with Call. | |
| bool | Cancelled () const |
| Whether cancellation has been requested/applied. | |
| absl::Status | GetStatus () const |
| The action's completion status (OK while still running). | |
| std::optional< absl::Status > | GetDispatchStatus () const |
| The remote dispatch status, or nullopt when not (yet) dispatched. | |
Static Public Member Functions | |
| static absl::StatusOr< std::shared_ptr< Action > > | Create (ActionSchema schema, std::string action_id={}, ActionHandler handler={}, std::shared_ptr< nodes::NodeMap > node_map=nullptr, std::shared_ptr< net::WireStream > stream=nullptr, std::shared_ptr< service::Session > session=nullptr, std::shared_ptr< ActionRegistry > registry=nullptr, size_t max_concurrent_nested_actions=kDefaultMaxConcurrentNestedActions) |
| Creates an action. | |
| static absl::StatusOr< std::string > | MakeNodeId (std::string_view action_id, std::string_view node_name) |
Derives the node id for port node_name of action action_id. | |
Friends | |
| class | ActionRegistry |
| class | service::Session |
A11's unit of work: a schema-described, asynchronously run operation.
An action pairs an a11::actions::ActionSchema with a handler and a set of typed input/output ports (each an a11::nodes::AsyncNode). Running the action invokes its handler, which reads from the inputs and streams into the outputs. The same action can either run locally (Run) or be dispatched to a peer over a bound a11::net::WireStream (Call). Actions are always held by std::shared_ptr and compose recursively via MakeNested.
| absl::Status a11::actions::Action::BindHandler | ( | ActionHandler | handler | ) |
Binds the handler invoked when the action runs.
| absl::Status a11::actions::Action::BindNodeMap | ( | std::shared_ptr< nodes::NodeMap > | node_map | ) |
Binds the node map that backs this action's ports.
| absl::Status a11::actions::Action::BindRegistry | ( | std::shared_ptr< ActionRegistry > | registry | ) |
Binds the registry used to resolve nested actions by name.
| absl::Status a11::actions::Action::BindSession | ( | std::shared_ptr< service::Session > | session | ) |
Binds the owning session.
| absl::Status a11::actions::Action::BindStream | ( | std::shared_ptr< net::WireStream > | stream | ) |
Binds the wire stream used to dispatch the action remotely.
| absl::Status a11::actions::Action::BindStreamsOnInputsByDefault | ( | bool | bind | ) |
Sets whether input port streams are bound by default.
| absl::Status a11::actions::Action::BindStreamsOnOutputsByDefault | ( | bool | bind | ) |
Sets whether output port streams are bound by default.
| a11::Future< std::shared_ptr< Action > > a11::actions::Action::Call | ( | data::ByteMap | wire_headers = {} | ) |
Dispatches the action to a peer over the bound wire stream.
| wire_headers | Extra headers to send with the dispatch. |
| absl::Status a11::actions::Action::Cancel | ( | ) |
Requests cancellation of the action (local or remote).
| bool a11::actions::Action::Cancelled | ( | ) | const |
Whether cancellation has been requested/applied.
Sets whether inputs are released after each run.
Sets whether outputs are released after each run.
| bool a11::actions::Action::ContainsPort | ( | std::string_view | name | ) | const |
Whether the schema declares a port named name.
|
static |
Creates an action.
| schema | Schema describing ports, headers and outputs. |
| action_id | Instance id; generated when empty. |
| handler | Handler run by Run/Call; may be bound later. |
| node_map | Node map backing the action's ports. |
| stream | Optional wire stream enabling remote Call. |
| session | Optional owning session. |
| registry | Optional registry used to resolve nested actions. |
| max_concurrent_nested_actions | Cap on concurrent nested actions. |
| absl::Status a11::actions::Action::ForwardHeader | ( | const std::shared_ptr< Action > & | target, |
| std::string_view | name | ||
| ) | const |
Copies header name from this action onto target.
| absl::Status a11::actions::Action::ForwardHeadersWithPrefix | ( | const std::shared_ptr< Action > & | target, |
| std::string_view | prefix = kActionHeaderPrefix |
||
| ) | const |
Copies all headers starting with prefix onto target.
| data::ActionMessage a11::actions::Action::GetActionMessage | ( | ) | const |
Returns the wire a11::data::ActionMessage describing this action.
| std::optional< absl::Status > a11::actions::Action::GetDispatchStatus | ( | ) | const |
The remote dispatch status, or nullopt when not (yet) dispatched.
| ActionHandler a11::actions::Action::GetHandler | ( | ) | const |
Returns the currently bound handler.
| absl::StatusOr< std::optional< data::Bytes > > a11::actions::Action::GetHeader | ( | std::string_view | name | ) | const |
Returns header name, or nullopt when absent.
| std::string a11::actions::Action::GetId | ( | ) | const |
Returns this action's instance id.
| absl::StatusOr< std::shared_ptr< nodes::AsyncNode > > a11::actions::Action::GetInput | ( | std::string | name, |
| std::optional< bool > | bind_stream = std::nullopt |
||
| ) |
Returns the input port node named name.
| name | Input port name from the schema. |
| bind_stream | Override for whether the node's stream is bound. |
name is not an input. | absl::StatusOr< std::shared_ptr< nodes::AsyncNode > > a11::actions::Action::GetNode | ( | std::string | node_id | ) |
Returns the port node with raw id node_id.
| std::shared_ptr< nodes::NodeMap > a11::actions::Action::GetNodeMap | ( | ) | const |
Returns the bound node map.
| absl::StatusOr< std::shared_ptr< nodes::AsyncNode > > a11::actions::Action::GetOutput | ( | std::string | name, |
| std::optional< bool > | bind_stream = std::nullopt |
||
| ) |
Returns the output port node named name.
| name | Output port name from the schema. |
| bind_stream | Override for whether the node's stream is bound. |
name is not an output. | absl::StatusOr< std::shared_ptr< nodes::AsyncNode > > a11::actions::Action::GetPort | ( | std::string | name | ) |
Returns the input or output port node named name.
| std::shared_ptr< ActionRegistry > a11::actions::Action::GetRegistry | ( | ) | const |
Returns the bound registry.
| ActionSchema a11::actions::Action::GetSchema | ( | ) | const |
Returns this action's schema.
| std::shared_ptr< service::Session > a11::actions::Action::GetSession | ( | ) | const |
Returns the owning session, if any.
| ActionSettings a11::actions::Action::GetSettings | ( | ) | const |
Returns the action's current settings.
| absl::Status a11::actions::Action::GetStatus | ( | ) | const |
The action's completion status (OK while still running).
| std::shared_ptr< net::WireStream > a11::actions::Action::GetStream | ( | ) | const |
Returns the bound wire stream.
| bool a11::actions::Action::HasBeenCalled | ( | ) | const |
Whether the action has been dispatched with Call.
| bool a11::actions::Action::HasBeenRun | ( | ) | const |
Whether the action has been started with Run.
| bool a11::actions::Action::HasHandler | ( | ) | const |
Whether a handler is bound.
| bool a11::actions::Action::HasHeader | ( | std::string_view | name | ) | const |
Whether header name is set.
| data::ByteMap a11::actions::Action::Headers | ( | ) | const |
Returns a copy of all headers.
| bool a11::actions::Action::IsDone | ( | ) | const |
Whether the action has finished (successfully or not).
| absl::StatusOr< std::shared_ptr< Action > > a11::actions::Action::MakeNested | ( | const ActionSchema & | schema, |
| bool | propagate_io = true, |
||
| bool | forward_headers = true |
||
| ) |
Creates a nested action from a schema, parented to this action.
The child always receives a new action id and therefore new derived port ids. With propagate_io it shares this action's NodeMap, stream, and Session; it does not copy this action's port mappings. Registry and nested concurrency context are inherited in either mode.
| schema | Schema for the nested action. |
| propagate_io | Share this action's NodeMap, stream, and Session. |
| forward_headers | Copy this action's framework headers to the child. |
| absl::StatusOr< std::shared_ptr< Action > > a11::actions::Action::MakeNested | ( | std::string_view | action_name, |
| bool | propagate_io = true, |
||
| bool | forward_headers = true |
||
| ) |
Creates a nested action by name from the bound registry.
The child has its own id and port ids. With propagate_io it shares this action's NodeMap, stream, and Session, but not its port mappings.
| action_name | Registered action to instantiate. |
| propagate_io | Share this action's NodeMap, stream, and Session. |
| forward_headers | Copy this action's framework headers to the child. |
action_name is unknown.
|
static |
Derives the node id for port node_name of action action_id.
| absl::Status a11::actions::Action::MapPortsFromMessage | ( | const data::ActionMessage & | message | ) |
Binds this action's ports to the nodes named in message.
| absl::Status a11::actions::Action::RemoveHeader | ( | std::string_view | name | ) |
Removes header name.
| absl::StatusOr< std::shared_ptr< Action > > a11::actions::Action::Run | ( | ) |
Runs the action's handler locally.
Starts the handler and returns the action immediately; use Wait or the completion status to observe the outcome. (The Python binding also exposes this as run_in_background.)
| absl::Status a11::actions::Action::SetHeader | ( | std::string | name, |
| data::Bytes | value | ||
| ) |
Sets header name to value.
| absl::Status a11::actions::Action::SetId | ( | std::string | action_id | ) |
Sets this action's instance id.
| absl::Status a11::actions::Action::SetOnCancelled | ( | OnActionCancelled | callback | ) |
Registers a callback invoked when the action is cancelled.
| absl::Status a11::actions::Action::SetSchema | ( | ActionSchema | schema | ) |
Replaces this action's schema (validated).
| absl::Status a11::actions::Action::SetSettings | ( | ActionSettings | settings | ) |
Replaces the action's settings.
Sets a boolean attribute on this action's span.
Sets a floating-point attribute on this action's span.
| void a11::actions::Action::SetSpanAttribute | ( | std::string_view | key, |
| std::int64_t | value | ||
| ) |
Sets an integer attribute on this action's span.
| void a11::actions::Action::SetSpanAttribute | ( | std::string_view | key, |
| std::string_view | value | ||
| ) |
Sets a string attribute on this action's span.
No-op when the action is not traced. Intended to be called from the handler while the span is active (e.g. langfuse.observation.input / .output).
| void a11::actions::Action::SetSpanName | ( | std::string_view | name | ) |
Overrides the display name of this action's span.
| void a11::actions::Action::SetSpanStatus | ( | obs::SpanStatus | status, |
| std::string_view | description = {} |
||
| ) |
Sets the span status explicitly.
Suppresses the automatic status the framework would otherwise record from the action's completion status.
| std::string a11::actions::Action::SpanId | ( | ) | const |
This action's span id as lowercase hex, or empty when untraced.
| std::string a11::actions::Action::TraceId | ( | ) | const |
This action's trace id as lowercase hex.
Empty when the action is not traced (no OTel context / tracing not configured). Valid once the action has started and until it finishes.
| a11::Future< std::shared_ptr< Action > > a11::actions::Action::Wait | ( | absl::Duration | timeout = absl::InfiniteDuration() | ) |
Awaits completion of the action.
| timeout | Maximum time to wait. |
| a11::Future< absl::Status > a11::actions::Action::WaitForDispatch | ( | absl::Duration | timeout = absl::InfiniteDuration() | ) |
Awaits acceptance of a remote dispatch.
| timeout | Maximum time to wait. |
|
friend |
|
friend |