Class InProcessRuntime
- Inheritance
-
In
Process Runtime
- Implements
- Inherited Members
- Extension Methods
Constructors
InProcessRuntime()
Properties
DeliverToSelf
Property Value
Methods
AddSubscriptionAsync(ISubscriptionDefinition)
Adds a new subscription for the runtime to handle when processing published messages.
Parameters
subscription
ISubscriptionDefinition The subscription to add.
Returns
- Value
Task A task representing the asynchronous operation.
GetAgentAsync(AgentId, bool)
Retrieves an agent by its unique identifier.
Parameters
Returns
GetAgentAsync(AgentType, string, bool)
Retrieves an agent by its type.
public ValueTask<AgentId> GetAgentAsync(AgentType agentType, string key = "default", bool lazy = true)
Parameters
agentType
AgentType The type of the agent.
key
stringAn optional key to specify variations of the agent. Defaults to "default".
lazy
boolIf
true
, the agent is fetched lazily.
Returns
GetAgentAsync(string, string, bool)
Retrieves an agent by its string representation.
Parameters
agent
stringThe string representation of the agent.
key
stringAn optional key to specify variations of the agent. Defaults to "default".
lazy
boolIf
true
, the agent is fetched lazily.
Returns
GetAgentMetadataAsync(AgentId)
Retrieves metadata for an agent.
Parameters
agentId
AgentId The ID of the agent.
Returns
- Value
Task <AgentMetadata > A task representing the asynchronous operation, returning the agent's metadata.
LoadAgentStateAsync(AgentId, JsonElement)
Loads the saved state into an agent.
Parameters
agentId
AgentId The ID of the agent whose state is being restored.
state
JsonElement The state dictionary to restore.
Returns
- Value
Task A task representing the asynchronous operation.
LoadStateAsync(JsonElement)
Loads a previously saved state into the object.
Parameters
state
JsonElement A dictionary representing the saved state. The structure of the state is implementation-defined but must be JSON serializable.
Returns
- Value
Task A task representing the asynchronous operation.
ProcessNextMessageAsync(CancellationToken)
Parameters
cancellation
CancellationToken
Returns
PublishMessageAsync(object, TopicId, AgentId?, string?, CancellationToken)
Publishes a message to all agents subscribed to the given topic. No responses are expected from publishing.
public ValueTask PublishMessageAsync(object message, TopicId topic, AgentId? sender = null, string? messageId = null, CancellationToken cancellation = default)
Parameters
message
objectThe message to publish.
topic
TopicId The topic to publish the message to.
sender
AgentId ?The agent sending the message. Defaults to
null
.messageId
stringA unique message ID. If
null
, a new one will be generated.cancellation
CancellationToken
Returns
- Value
Task A task representing the asynchronous operation.
Exceptions
- Undeliverable
Exception Thrown if the message cannot be delivered.
RegisterAgentFactoryAsync(AgentType, Func<AgentId, IAgentRuntime, ValueTask<IHostableAgent>>)
Registers an agent factory with the runtime, associating it with a specific agent type. The type must be unique.
public ValueTask<AgentType> RegisterAgentFactoryAsync(AgentType type, Func<AgentId, IAgentRuntime, ValueTask<IHostableAgent>> factoryFunc)
Parameters
type
AgentType The agent type to associate with the factory.
factoryFunc
Func<AgentId , IAgentRuntime , ValueTask <IHostableAgent >>A function that asynchronously creates the agent instance.
Returns
- Value
Task <AgentType > A task representing the asynchronous operation, returning the registered Agent
Type .
RegisterAgentFactoryAsync<TAgent>(AgentType, Func<AgentId, IAgentRuntime, ValueTask<TAgent>>)
public ValueTask<AgentType> RegisterAgentFactoryAsync<TAgent>(AgentType type, Func<AgentId, IAgentRuntime, ValueTask<TAgent>> factoryFunc) where TAgent : IHostableAgent
Parameters
type
AgentType factoryFunc
Func<AgentId , IAgentRuntime , ValueTask <TAgent>>
Returns
Type Parameters
TAgent
RemoveSubscriptionAsync(string)
Removes a subscription from the runtime.
Parameters
subscriptionId
stringThe unique identifier of the subscription to remove.
Returns
- Value
Task A task representing the asynchronous operation.
Exceptions
- Key
Not Found Exception Thrown if the subscription does not exist.
RunUntilIdleAsync()
Returns
SaveAgentStateAsync(AgentId)
Saves the state of an agent. The result must be JSON serializable.
Parameters
agentId
AgentId The ID of the agent whose state is being saved.
Returns
- Value
Task <JsonElement > A task representing the asynchronous operation, returning a dictionary of the saved state.
SaveStateAsync()
Saves the current state of the object.
Returns
- Value
Task <JsonElement > A task representing the asynchronous operation, returning a dictionary containing the saved state. The structure of the state is implementation-defined but must be JSON serializable.
SendMessageAsync(object, AgentId, AgentId?, string?, CancellationToken)
Sends a message to an agent and gets a response. This method should be used to communicate directly with an agent.
public ValueTask<object?> SendMessageAsync(object message, AgentId recepient, AgentId? sender = null, string? messageId = null, CancellationToken cancellationToken = default)
Parameters
message
objectThe message to send.
recepient
AgentId The agent to send the message to.
sender
AgentId ?The agent sending the message. Should be
null
if sent from an external source.messageId
stringA unique identifier for the message. If
null
, a new ID will be generated.cancellationToken
CancellationToken A token to cancel the operation if needed.
Returns
- Value
Task <object> A task representing the asynchronous operation, returning the response from the agent.
Exceptions
- Cant
Handle Exception Thrown if the recipient cannot handle the message.
- Undeliverable
Exception Thrown if the message cannot be delivered.
StartAsync(CancellationToken)
Parameters
token
CancellationToken
Returns
StopAsync(CancellationToken)
Parameters
token
CancellationToken
Returns
TryGetAgentProxyAsync(AgentId)
Attempts to retrieve an Agent
Parameters
agentId
AgentId The ID of the agent.
Returns
- Value
Task <AgentProxy > A task representing the asynchronous operation, returning an Agent
Proxy if successful.