A11 (C++ runtime)
Native C++ implementation of the A11 action and streaming runtime
Loading...
Searching...
No Matches
a11::actions::Action Class Reference

A11's unit of work: a schema-described, asynchronously run operation. More...

#include <cpp/a11/actions/action.h>

Inheritance diagram for a11::actions::Action:
[legend]

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::NodeMapGetNodeMap () 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::WireStreamGetStream () 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< ActionRegistryGetRegistry () const
 Returns the bound registry.
 
absl::Status BindSession (std::shared_ptr< service::Session > session)
 Binds the owning session.
 
std::shared_ptr< service::SessionGetSession () 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
 

Detailed Description

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.

Member Function Documentation

◆ BindHandler()

absl::Status a11::actions::Action::BindHandler ( ActionHandler  handler)

Binds the handler invoked when the action runs.

◆ BindNodeMap()

absl::Status a11::actions::Action::BindNodeMap ( std::shared_ptr< nodes::NodeMap node_map)

Binds the node map that backs this action's ports.

◆ BindRegistry()

absl::Status a11::actions::Action::BindRegistry ( std::shared_ptr< ActionRegistry registry)

Binds the registry used to resolve nested actions by name.

◆ BindSession()

absl::Status a11::actions::Action::BindSession ( std::shared_ptr< service::Session session)

Binds the owning session.

◆ BindStream()

absl::Status a11::actions::Action::BindStream ( std::shared_ptr< net::WireStream stream)

Binds the wire stream used to dispatch the action remotely.

◆ BindStreamsOnInputsByDefault()

absl::Status a11::actions::Action::BindStreamsOnInputsByDefault ( bool  bind)

Sets whether input port streams are bound by default.

◆ BindStreamsOnOutputsByDefault()

absl::Status a11::actions::Action::BindStreamsOnOutputsByDefault ( bool  bind)

Sets whether output port streams are bound by default.

◆ Call()

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.

Parameters
wire_headersExtra headers to send with the dispatch.
Returns
An awaitable resolving to this action once dispatch is accepted.

◆ Cancel()

absl::Status a11::actions::Action::Cancel ( )

Requests cancellation of the action (local or remote).

◆ Cancelled()

bool a11::actions::Action::Cancelled ( ) const

Whether cancellation has been requested/applied.

◆ ClearInputsAfterRun()

absl::Status a11::actions::Action::ClearInputsAfterRun ( bool  clear = true)

Sets whether inputs are released after each run.

◆ ClearOutputsAfterRun()

absl::Status a11::actions::Action::ClearOutputsAfterRun ( bool  clear = true)

Sets whether outputs are released after each run.

◆ ContainsPort()

bool a11::actions::Action::ContainsPort ( std::string_view  name) const

Whether the schema declares a port named name.

◆ Create()

absl::StatusOr< std::shared_ptr< Action > > a11::actions::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 
)
static

Creates an action.

Parameters
schemaSchema describing ports, headers and outputs.
action_idInstance id; generated when empty.
handlerHandler run by Run/Call; may be bound later.
node_mapNode map backing the action's ports.
streamOptional wire stream enabling remote Call.
sessionOptional owning session.
registryOptional registry used to resolve nested actions.
max_concurrent_nested_actionsCap on concurrent nested actions.
Returns
The new action, or an error when the schema is invalid.

◆ ForwardHeader()

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.

◆ ForwardHeadersWithPrefix()

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.

◆ GetActionMessage()

data::ActionMessage a11::actions::Action::GetActionMessage ( ) const

Returns the wire a11::data::ActionMessage describing this action.

◆ GetDispatchStatus()

std::optional< absl::Status > a11::actions::Action::GetDispatchStatus ( ) const

The remote dispatch status, or nullopt when not (yet) dispatched.

◆ GetHandler()

ActionHandler a11::actions::Action::GetHandler ( ) const

Returns the currently bound handler.

◆ GetHeader()

absl::StatusOr< std::optional< data::Bytes > > a11::actions::Action::GetHeader ( std::string_view  name) const

Returns header name, or nullopt when absent.

◆ GetId()

std::string a11::actions::Action::GetId ( ) const

Returns this action's instance id.

◆ GetInput()

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.

Parameters
nameInput port name from the schema.
bind_streamOverride for whether the node's stream is bound.
Returns
The port's node, or an error when name is not an input.

◆ GetNode()

absl::StatusOr< std::shared_ptr< nodes::AsyncNode > > a11::actions::Action::GetNode ( std::string  node_id)

Returns the port node with raw id node_id.

◆ GetNodeMap()

std::shared_ptr< nodes::NodeMap > a11::actions::Action::GetNodeMap ( ) const

Returns the bound node map.

◆ GetOutput()

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.

Parameters
nameOutput port name from the schema.
bind_streamOverride for whether the node's stream is bound.
Returns
The port's node, or an error when name is not an output.

◆ GetPort()

absl::StatusOr< std::shared_ptr< nodes::AsyncNode > > a11::actions::Action::GetPort ( std::string  name)

Returns the input or output port node named name.

◆ GetRegistry()

std::shared_ptr< ActionRegistry > a11::actions::Action::GetRegistry ( ) const

Returns the bound registry.

◆ GetSchema()

ActionSchema a11::actions::Action::GetSchema ( ) const

Returns this action's schema.

◆ GetSession()

std::shared_ptr< service::Session > a11::actions::Action::GetSession ( ) const

Returns the owning session, if any.

◆ GetSettings()

ActionSettings a11::actions::Action::GetSettings ( ) const

Returns the action's current settings.

◆ GetStatus()

absl::Status a11::actions::Action::GetStatus ( ) const

The action's completion status (OK while still running).

◆ GetStream()

std::shared_ptr< net::WireStream > a11::actions::Action::GetStream ( ) const

Returns the bound wire stream.

◆ HasBeenCalled()

bool a11::actions::Action::HasBeenCalled ( ) const

Whether the action has been dispatched with Call.

◆ HasBeenRun()

bool a11::actions::Action::HasBeenRun ( ) const

Whether the action has been started with Run.

◆ HasHandler()

bool a11::actions::Action::HasHandler ( ) const

Whether a handler is bound.

◆ HasHeader()

bool a11::actions::Action::HasHeader ( std::string_view  name) const

Whether header name is set.

◆ Headers()

data::ByteMap a11::actions::Action::Headers ( ) const

Returns a copy of all headers.

◆ IsDone()

bool a11::actions::Action::IsDone ( ) const

Whether the action has finished (successfully or not).

◆ MakeNested() [1/2]

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.

Parameters
schemaSchema for the nested action.
propagate_ioShare this action's NodeMap, stream, and Session.
forward_headersCopy this action's framework headers to the child.
Returns
The nested action.

◆ MakeNested() [2/2]

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.

Parameters
action_nameRegistered action to instantiate.
propagate_ioShare this action's NodeMap, stream, and Session.
forward_headersCopy this action's framework headers to the child.
Returns
The nested action, or NotFound when action_name is unknown.

◆ MakeNodeId()

absl::StatusOr< std::string > a11::actions::Action::MakeNodeId ( std::string_view  action_id,
std::string_view  node_name 
)
static

Derives the node id for port node_name of action action_id.

◆ MapPortsFromMessage()

absl::Status a11::actions::Action::MapPortsFromMessage ( const data::ActionMessage message)

Binds this action's ports to the nodes named in message.

◆ RemoveHeader()

absl::Status a11::actions::Action::RemoveHeader ( std::string_view  name)

Removes header name.

◆ Run()

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.)

Returns
This action, or an error when it cannot be started.

◆ SetHeader()

absl::Status a11::actions::Action::SetHeader ( std::string  name,
data::Bytes  value 
)

Sets header name to value.

◆ SetId()

absl::Status a11::actions::Action::SetId ( std::string  action_id)

Sets this action's instance id.

◆ SetOnCancelled()

absl::Status a11::actions::Action::SetOnCancelled ( OnActionCancelled  callback)

Registers a callback invoked when the action is cancelled.

◆ SetSchema()

absl::Status a11::actions::Action::SetSchema ( ActionSchema  schema)

Replaces this action's schema (validated).

◆ SetSettings()

absl::Status a11::actions::Action::SetSettings ( ActionSettings  settings)

Replaces the action's settings.

◆ SetSpanAttribute() [1/4]

void a11::actions::Action::SetSpanAttribute ( std::string_view  key,
bool  value 
)

Sets a boolean attribute on this action's span.

◆ SetSpanAttribute() [2/4]

void a11::actions::Action::SetSpanAttribute ( std::string_view  key,
double  value 
)

Sets a floating-point attribute on this action's span.

◆ SetSpanAttribute() [3/4]

void a11::actions::Action::SetSpanAttribute ( std::string_view  key,
std::int64_t  value 
)

Sets an integer attribute on this action's span.

◆ SetSpanAttribute() [4/4]

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).

◆ SetSpanName()

void a11::actions::Action::SetSpanName ( std::string_view  name)

Overrides the display name of this action's span.

◆ SetSpanStatus()

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.

◆ SpanId()

std::string a11::actions::Action::SpanId ( ) const

This action's span id as lowercase hex, or empty when untraced.

◆ TraceId()

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.

◆ Wait()

a11::Future< std::shared_ptr< Action > > a11::actions::Action::Wait ( absl::Duration  timeout = absl::InfiniteDuration())

Awaits completion of the action.

Parameters
timeoutMaximum time to wait.
Returns
An awaitable resolving to this action when it finishes (or fails with the action's error status).

◆ WaitForDispatch()

a11::Future< absl::Status > a11::actions::Action::WaitForDispatch ( absl::Duration  timeout = absl::InfiniteDuration())

Awaits acceptance of a remote dispatch.

Parameters
timeoutMaximum time to wait.
Returns
An awaitable resolving to the dispatch status.

Friends And Related Symbol Documentation

◆ ActionRegistry

◆ service::Session


The documentation for this class was generated from the following files: