Closed pan-x-c closed 1 week ago
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.py
and 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
async_func/sync_func
may be confused with async
in Python asyncio
. unblocking_func / blocking_func
may be a better name.agent_id
is renamed to oid
(a short version of object_id), which may cause misunderstandings and incompatibility with legacy code. However, here we really need an id
field for all objects, not just agents.
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 bindEventListener
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 originalto_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 theRpcObject
, and theRpcObject
will forward the request to the real object running in the RPC server. The originalRpcAgent
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 ofAsyncResult
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 originalPlaceholderMessage
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.