This part of the documentation is for experimental features. The APIs and functionalities are subject to frequent change.
The Agent API implemented here conflicts with stable Agent API in Sotopia.
Agent is a concept in Sotopia to represent decision-making entities that can interact with each other in a social environment. Agents can be human participants, AI models, or other entities.
No matter which type of agent, they have the same interface to interact with the environment:
the input and output are of derived types of aact.messages.DataModel
.
Creating your own agents
To create your own agents, you need to subclass the BaseAgent
class
and implement the asynchronous aact
method.
The aact
method takes an Observation
object as input and returns an AgentAction
object as output. Here is an example of a simple agent that always says "Hello, world!":
from aact import NodeFactory
from aact.messages import Text
from sotopia.experimental import BaseAgent
@NodeFactory.register("simple_echo_agent") # Register the agent so that it can be used in the dataflow
class SimpleEchoAgent(BaseAgent[Text, Text]):
def __init__(self, input_channel: str, output_channel: str, redis_url: str) -> None:
super().__init__( # call the constructor of the base class
input_channel_types=[(input_channel, Text)],
output_channel_types=[(output_channel, Text)],
)
async def aact(self, observation: Text) -> Text: # major agent reactive function
return Text(text=f"Hello, {observation.text}!")
Let me break this down for you:
NodeFactory
is a decorator that registers the agent so that it can be used in the dataflow. Dataflow is a concept inaact
that defines hownodes
are interacting with each other.channel
is a concept inredis
pubsub andaact
. A node can send messages to many channels, and receive messages many channels as well. To subclassBaseAgent
, you will need to feed two lists of channel-message type pairs toinput_channel_types
andoutput_channel_types
respectively.- Inherit the
BaseAgent
class and specify the input and output channel types in the constructor. - Implement the
aact
method that takes anObservation
object as input and returns anAgentAction
object as output. In this case, the agent always says "Hello, ..."
For a running example, try out examples/experimental/tick_and_echo_agents
.