-
Notifications
You must be signed in to change notification settings - Fork 343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add environment modules #378
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Move the environment modules into examples like what rag and react did before, and we should consider to merge it into the library when it's ready.
- Will it enter an infinite loop? For example, agentA and agentB subscribe to the locations of each other and trigger each other, leading to an endless actions cycle.
agentA move ==> agentB listen ==> agent B move ==> agentA listen ==> agentB move ....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Please refer to inline comments
To be discussed
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of my concerns in this PR:
- The planned deprecation of placeholder may be too extensive. Consider this alternative: create a Mixin class that blocks certain remote function calls (e.g., a configurable reply). This way, the message class (and the env modules) can inherit from it, maintaining the functionality of placeholders without causing confusion in return types from an agent (
AsyncResult
orMsg
).
class RemoteMixin:
_enable: bool = False
__remote_attrs__ = []
def __getattr__(self, name):
if _enable and name in self.__remote_attrs__:
# ...
else:
super().__getattr__(name)
class Msg(RemoteMixin):
__remote_attrs__ = ['reply', 'observe', 'xxx']
"""Functions/attrs need to be executed/obtained from remote."""
# ...
-
If feasible, try not to use metaclasses for functionality implementation. They can be challenging for developers to understand.
-
I believe the agent should be the framework's core. Thus, the design of the environment module should align with the agent's settings, not vice versa. For instance, the agent's identity should be independent of the environment and distribution modules.
Quick fix on chatroom
Description
Add Environment Modules (
Env
and its sub-classes)Env
is a key concept of AgentScope, representing global data shared among agents.Each env has name and value, and multiple envs can be organized into a tree structure, where each env can have multiple children envs and one parent env.
Different implementations of envs may have different event functions, which are marked by
@event_func
.Users can bind
EventListener
to specific event functions, and the listener will be activated when the event function is called.Similar to
AgentBase
sub-classes,Env
sub-classes also support theto_dist
call, and the parameter is the same asAgentBase
.Decouple distribution-related functions from other AgentScope modules
Move
to_dist
intoRpcMeta
RpcMeta
is a meta-class that integrates allto_dist
related methods/parameters.Now,
to_dist
function/parameter can be used directly if the class is a subclass ofRpcMeta
.The original
to_dist
and_AgentMeta
is removed.Extend
RpcAgent
intoRpcObject
RpcObject
is an enhanced version ofRpcAgent
, and can be used to represent any object (unlikeRpcAgent
which can only representAgent
)Users can call any public methods or get any attributes on the
RpcObject
, and theRpcObject
will forward the request to the real object running in the RPC server.The original
RpcAgent
is removed.Add
@async_func
andAsyncResult
to replace thereply
andPlaceholder
Because the
RpcObject
supports calling any public methods and returns any results, the oldPlaceholder
cannot cover this complex scenario. Therefore,@async_func
andAsyncResult
are added.Functions decorated with
@async_func
will automatically returnAsyncResult
objects in distributed mode.The usage of
AsyncResult
is the same asPlaceholder
, which is instantiated only when its internal objects are accessed.AsyncResult
can be used to represent any type of data, not justMsg
.The original
PlaceholderMessage
is removed.Through the above modification, the
agent
andmessage
modules are decoupled from the distributed mode.Note that the user interface of the distributed mode is unchanged, all modifications above are completely hidden from the user, and all previous distributed examples can be run without any modification.
Add Guess Two Third of the Average Game example
The code of "Very Large-Scale Multi-Agent Simulation in AgentScope" is released under
examples/paper_large_scale_simulation
Checklist
Please check the following items before code is ready to be reviewed.