Add environment modules
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.
- [x] Code has passed all tests
- [x] Docstrings have been added/updated in Google Style
- [x] Documentation has been updated
- [x] Code is ready for review
Because the gRPC server relies on the RpcEnv,rpc_env.py and the modules it depends on can't be moved to examples, all other modules have been moved to examples/environments
Because the gRPC server relies on the
RpcEnv,rpc_env.pyand the modules it depends on can't be moved toexamples, all other modules have been moved toexamples/environments
The current implementation is too complex, and we didn't decide on the final implementation of this environment module.
However, in this PR, the env module is actually embedded in the main library. If we can decouple it from the main library, we should consider to create a branch to maintain the simulation related code.
To be discussed
- the name of distributed functions. In the current version,
async_func/sync_funcmay be confused withasyncin Pythonasyncio.unblocking_func / blocking_funcmay be a better name. - the old
agent_idis renamed tooid(a short version of object_id), which may cause misunderstandings and incompatibility with legacy code. However, here we really need anidfield for all objects, not just agents.