Skip to content
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

Open
wants to merge 181 commits into
base: main
Choose a base branch
from
Open

Conversation

pan-x-c
Copy link
Collaborator

@pan-x-c pan-x-c commented Aug 2, 2024

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 the to_dist call, and the parameter is the same as AgentBase.

Decouple distribution-related functions from other AgentScope modules

Move to_dist into RpcMeta

RpcMeta is a meta-class that integrates all to_dist related methods/parameters.
Now, to_dist function/parameter can be used directly if the class is a subclass of RpcMeta.
The original to_dist and _AgentMeta is removed.

Extend RpcAgent into RpcObject

RpcObject is an enhanced version of RpcAgent, and can be used to represent any object (unlike RpcAgent which can only represent Agent)
Users can call any public methods or get any attributes on the RpcObject, and the RpcObject will forward the request to the real object running in the RPC server.
The original RpcAgent is removed.

Add @async_func and AsyncResult to replace the reply and Placeholder

Because the RpcObject supports calling any public methods and returns any results, the old Placeholder cannot cover this complex scenario. Therefore, @async_func and AsyncResult are added.

Functions decorated with @async_func will automatically return AsyncResult objects in distributed mode.
The usage of AsyncResult is the same as Placeholder, which is instantiated only when its internal objects are accessed.
AsyncResult can be used to represent any type of data, not just Msg.
The original PlaceholderMessage is removed.

Through the above modification, the agent and message 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.

  • Code has passed all tests
  • Docstrings have been added/updated in Google Style
  • Documentation has been updated
  • Code is ready for review

@pan-x-c pan-x-c added the feature label Aug 2, 2024
Copy link
Collaborator

@DavdGao DavdGao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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.
  2. 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 ....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants