Namespace Prefrontal
Classes
- Agent
An agent manages a collection of Modules that work together to achieve a goal.
Getting Started
- To create an agent, simply instantiate it with the new operator.
- Add modules to the agent by chaining AddModule<T>() method calls.
- Finally call Initialize() or InitializeAsync() to initialize all modules and start the agent.
- When the agent is no longer needed, call Dispose() to dispose of it.
The Agent Lifecycle
Agent.State Available Actions Uninitialized - Modules can be added.
- Modules can be removed.
- Modules can send and receive signals.
- Signal processing order can be changed.
Initializing - Modules can be added (new modules are initialized immediately).
- Modules cannot be removed.
- Modules can send and receive signals.
- Signal processing order can be changed.
Initialized - Modules can be added (new modules are initialized immediately).
- Modules can be removed.
- Modules can send and receive signals.
- Signal processing order can be changed.
Disposing - Modules cannot be added.
- Modules cannot be removed.
- Modules can send and receive signals.
- Signal processing order can be changed.
Disposed - Modules cannot be added.
- Modules cannot be removed.
- Modules cannot send nor receive signals.
- Signal processing order cannot be changed.
ServiceProvider Disposal
If you need to dispose of the ServiceProvider when the agent is disposed (e.g. if the ServiceProvider was specifically created for that agent), simply add ServiceProviderDisposesWithAgentModule to the agent.
- Module
A base class for all modules that can be added to an Agent.
Refer to Agent's Lifecycle for information on what can and cannot be done in each of the agent's lifecycle stages.
Each module's constructor can have injectable dependencies in its parameters which are injected by the agent using its ServiceProvider. The module's constructor can also take the agent itself as a parameter and even other modules that it requires.
- Modules can be added to an agent by calling AddModule<T>().
- Modules can be removed from an agent by calling RemoveModule<T>().
- Call Initialize() or InitializeAsync() to initialize the agent and all of its modules.
- Modules can send signals to other modules on the same agent by calling SendSignal<TSignal>(TSignal) or SendSignalAsync<TSignal>(TSignal). These signals can be of any type, but it's best to create your own signal types.
- Signals can also return a response that the sender can receive by calling SendSignal<TSignal, TResponse>(TSignal, bool) or SendSignalAsync<TSignal, TResponse>(TSignal). Signal processors and senders are not matched by the response type, only by the signal type. This means that if the response type of a signal processor does not match the expected response type of the sender, the response will be empty.
- Modules can implement IDisposable if they need to clean up resources when they are removed from the agent. Modules can also block the agent from removing them by throwing an InvalidOperationException in their Dispose() method. However, doing so when the agent itself is being disposed of has no effect.
- Modules can log messages using the Debug property.
Enums
- AgentState
The current state of the agent. Agents start in the Uninitialized state. Calling Initialize()/InitializeAsync() sets the state to Initializing while modules are being initialized and to Initialized when they are done. Calling Dispose() sets the state to Disposing while modules are being disposed of and to Disposed when done.
- RunningModuleExceptionPolicy
Defines what happens when an exception occurs in a module's RunAsync() method.