Agent
A message-based agent for subscribing to events and handling messages with user-defined functions.
Source code in eggai/agent.py
__init__(name, transport=None)
Initializes the Agent instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the agent (used as an identifier). |
required |
transport
|
Optional[Transport]
|
A concrete transport instance (e.g., KafkaTransport, InMemoryTransport). If None, defaults to InMemoryTransport. |
None
|
Source code in eggai/agent.py
start()
async
Starts the agent by connecting the transport and subscribing to all registered channels.
If no transport is provided, a default transport is used. Also registers a stop hook if not already registered.
Source code in eggai/agent.py
stop()
async
subscribe(channel=None, **kwargs)
Decorator for adding a subscription.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
channel
|
Optional[Channel]
|
The channel to subscribe to. If None, defaults to "eggai.channel". |
None
|
Returns:
Name | Type | Description |
---|---|---|
Callable |
A decorator that registers the given handler for the subscription. |