Class ConsoleConnector
Implements the IMessageConnector for console-based communication. This interface allows the agent to send and receive messages through the system console. Messages are displayed in the format [Sender] Content, and user input is captured when Enter is pressed.
Implements
Inherited Members
Namespace: VulcanAI.Connectors
Assembly: VulcanAI.dll
Syntax
public class ConsoleConnector : IMessageConnector
Remarks
The ConsoleInterface provides a simple way to interact with the agent through the command line. It runs a background task to continuously read user input and raises events when messages are received. All operations are asynchronous and include proper logging for debugging and monitoring.
Constructors
| Edit this page View SourceConsoleConnector(ILogger<ConsoleConnector>)
Initializes a new instance of the ConsoleConnector class.
Declaration
public ConsoleConnector(ILogger<ConsoleConnector> logger)
Parameters
Type | Name | Description |
---|---|---|
ILogger<ConsoleConnector> | logger | The logger instance for recording diagnostic information. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the logger parameter is null. |
Methods
| Edit this page View SourceSendMessageAsync(string)
Declaration
public Task SendMessageAsync(string content)
Parameters
Type | Name | Description |
---|---|---|
string | content |
Returns
Type | Description |
---|---|
Task |
SendMessageAsync(Message)
Sends a message to the console output.
Declaration
public Task SendMessageAsync(Message message)
Parameters
Type | Name | Description |
---|---|---|
Message | message | The message to send. |
Returns
Type | Description |
---|---|
Task | A task representing the asynchronous operation. |
Remarks
Messages are displayed in the format [Sender] Content. This method is thread-safe and can be called from any thread.
StartAsync()
Starts the console interface and begins listening for user input.
Declaration
public Task StartAsync()
Returns
Type | Description |
---|---|
Task | A task representing the asynchronous operation. |
Remarks
This method starts a background task that continuously reads input from the console. If the interface is already running, this method returns immediately.
StopAsync()
Stops the console interface and stops listening for user input.
Declaration
public Task StopAsync()
Returns
Type | Description |
---|---|
Task | A task representing the asynchronous operation. |
Remarks
This method stops the background input reading task and waits for it to complete. If the interface is not running, this method returns immediately.
Events
| Edit this page View SourceOnMessageReceived
Occurs when a message is received from the console input.
Declaration
public event EventHandler<Message>? OnMessageReceived
Event Type
Type | Description |
---|---|
EventHandler<Message> |
Remarks
This event is raised whenever the user types a message and presses Enter. The message sender is set to "User" and the channel is set to "Console".