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

Merged
merged 197 commits into from
Oct 28, 2024
Merged
Changes from 1 commit
Commits
Show all changes
197 commits
Select commit Hold shift + click to select a range
1d60d2b
update as_studio
pan-x-c Jul 30, 2024
7f4e920
add environment
pan-x-c Jul 30, 2024
d049bbb
add env
pan-x-c Jul 31, 2024
08bca3f
refactor env and add test
pan-x-c Aug 2, 2024
320ee62
add basic environment
pan-x-c Aug 2, 2024
be8a93e
update map environment
pan-x-c Aug 5, 2024
ee41cf3
fix pre-commit
pan-x-c Aug 5, 2024
13ec5b5
fix missing file
pan-x-c Aug 5, 2024
0995de4
fix missing file
pan-x-c Aug 5, 2024
484902f
add create env
pan-x-c Aug 5, 2024
088949c
merge main
pan-x-c Aug 5, 2024
c87ef56
rename attr
pan-x-c Aug 5, 2024
fe186ec
fix distance
pan-x-c Aug 6, 2024
3063356
add chatroom
pan-x-c Aug 6, 2024
bb23293
merge main
pan-x-c Aug 6, 2024
0aa9794
add chat room
pan-x-c Aug 6, 2024
9ce81bd
add chat room
pan-x-c Aug 6, 2024
79f5fb9
update chatroom
pan-x-c Aug 7, 2024
f77b273
remove environment module
pan-x-c Aug 7, 2024
cdffe6a
add rpc object
pan-x-c Aug 7, 2024
14c7e7b
rerwrite rpc agent with rpc object
pan-x-c Aug 7, 2024
c4e4e97
Merge branch 'main' into feature/pxc/env
pan-x-c Aug 7, 2024
0eb7140
support custom func
pan-x-c Aug 8, 2024
344f1b1
rename to env
pan-x-c Aug 8, 2024
5781fa0
merge rpc server launcher func into rpc object
pan-x-c Aug 8, 2024
449eb06
update serialize and deserialize
pan-x-c Aug 8, 2024
acbfbb0
pass all test
pan-x-c Aug 8, 2024
65895bd
add env test
pan-x-c Aug 8, 2024
4f4d14e
add missing file
pan-x-c Aug 8, 2024
2386bb8
move environments to examples
pan-x-c Aug 9, 2024
9ff9234
support custom async func
pan-x-c Aug 9, 2024
7dc2980
rename test
pan-x-c Aug 9, 2024
1b5bde9
add two third game
pan-x-c Aug 9, 2024
633c001
add configs
pan-x-c Aug 9, 2024
69dfd50
add two third game
pan-x-c Aug 9, 2024
0eb5983
fix guess two third example
Aug 13, 2024
7e89051
add large scale simulation example
Aug 13, 2024
21377d0
add large scale simulation example
Aug 13, 2024
0572991
add large scale simulation readme
Aug 13, 2024
4548a98
fix bug of group env
Aug 13, 2024
5709f8d
fix readme
Aug 13, 2024
3e7d87f
add a simple auction simulation example for environment
PatrickG1014 Aug 13, 2024
18481dd
Merge branch 'main' into feature/pxc/env
pan-x-c Aug 14, 2024
7b6e161
update @event_func
pan-x-c Aug 14, 2024
028a3a9
refactor: update auction simulation bid logic
PatrickG1014 Aug 14, 2024
c1777f5
Merge remote-tracking branch 'p.agentscope/feature/pxc/env' into add_…
PatrickG1014 Aug 14, 2024
ef40672
update event_func usage in auction simulation example
PatrickG1014 Aug 14, 2024
a94e92f
rpcenv support eventlistener
pan-x-c Aug 15, 2024
30a069a
fix dependency
pan-x-c Aug 15, 2024
f46f8c1
Merge remote-tracking branch 'p.agentscope/feature/pxc/env' into add_…
PatrickG1014 Aug 15, 2024
95f896a
rpcenv auction simulation example
PatrickG1014 Aug 15, 2024
77c07e4
remove base64 encode/decode
pan-x-c Aug 15, 2024
ff53531
Hot fix for MonitorManager
chenyushuo Aug 15, 2024
ddf008e
Add chatroom_example.py
chenyushuo Aug 19, 2024
9f01d59
move AgentWithChatRoom to chatroom.py
chenyushuo Aug 19, 2024
bcc1ed7
add argparse
chenyushuo Aug 19, 2024
357ffbf
bug fix in chatroom example
chenyushuo Aug 19, 2024
dd4bab1
fix cross reference
pan-x-c Aug 19, 2024
41ee7e0
Merge branch 'feature/pxc/env' of https://github.com/pan-x-c/AgentSco…
chenyushuo Aug 19, 2024
bdfd999
fix cross reference
pan-x-c Aug 19, 2024
12dbe7f
Merge branch 'feature/pxc/env' of https://github.com/pan-x-c/AgentSco…
chenyushuo Aug 19, 2024
824cacf
fix cross reference
pan-x-c Aug 20, 2024
660a5b8
bug fix in chatroom example
chenyushuo Aug 20, 2024
647edd6
Merge branch 'feature/pxc/env' of https://github.com/pan-x-c/AgentSco…
chenyushuo Aug 20, 2024
753af8e
add listener for Mentioned
chenyushuo Aug 20, 2024
57cb1b1
fix serialize
pan-x-c Aug 20, 2024
dc70ca9
add studio support
chenyushuo Aug 20, 2024
e71e403
refactor placeholder
pan-x-c Aug 20, 2024
ecfb142
refactor placeholder
pan-x-c Aug 20, 2024
0c75456
Merge branch 'feature/pxc/env' of https://github.com/pan-x-c/AgentSco…
chenyushuo Aug 20, 2024
afb1bb9
speedup create agent
pan-x-c Aug 20, 2024
f7aedc4
Merge remote-tracking branch 'p.agentscope/feature/pxc/env' into add_…
PatrickG1014 Aug 20, 2024
017987b
fix create agent test
pan-x-c Aug 20, 2024
01a1ff2
add distributed auction simulation example
PatrickG1014 Aug 20, 2024
42eded5
fix linux test
Aug 20, 2024
1b8fe84
add chatroom_with_assistant_example.py
chenyushuo Aug 21, 2024
d87b4fe
Merge branch 'feature/pxc/env' of https://github.com/pan-x-c/AgentSco…
chenyushuo Aug 21, 2024
c7b8a06
add timeout to ChatRoomAgentWithAssistant
chenyushuo Aug 22, 2024
2ca23f3
replace asyncio with threading
chenyushuo Aug 22, 2024
72ca22f
add README.md for chatroom
chenyushuo Aug 22, 2024
e4e95c4
update README.md for chatroom
chenyushuo Aug 22, 2024
455330d
add redis result pool
pan-x-c Aug 26, 2024
1ca8668
reuse grpc channel
pan-x-c Aug 26, 2024
c40d74b
fix dependency
pan-x-c Aug 26, 2024
182a0ca
update redis
pan-x-c Aug 27, 2024
8abc671
add todo
pan-x-c Aug 27, 2024
7590d34
Merge branch 'main' into feature/pxc/redis
pan-x-c Aug 28, 2024
e132805
merge main
pan-x-c Aug 28, 2024
84b9286
merge main
pan-x-c Aug 28, 2024
9f13ed6
merge main
pan-x-c Aug 29, 2024
7c94944
test redis instance exists
pan-x-c Aug 29, 2024
50c4576
test redis instance exists
pan-x-c Aug 29, 2024
05213ca
add todo
pan-x-c Aug 29, 2024
f450e86
remove rpc_agent and rpc_env
pan-x-c Aug 29, 2024
ae39d56
finish async
pan-x-c Aug 29, 2024
67dcd4b
add async pool test
pan-x-c Aug 29, 2024
0347e09
add async pool test
pan-x-c Aug 29, 2024
66bd2e8
Merge branch 'main' into feature/pxc/env
pan-x-c Aug 29, 2024
9942c35
fix test
pan-x-c Aug 29, 2024
0fd1a7f
support set agent id
pan-x-c Aug 29, 2024
92791dd
update doc
pan-x-c Aug 30, 2024
d105b04
add sync_func
pan-x-c Aug 30, 2024
a972b23
remove set start method
pan-x-c Aug 30, 2024
43ef94f
update tutorial
pan-x-c Aug 30, 2024
6592014
fix vllm script
pan-x-c Aug 30, 2024
67abf3c
finish zh tutorial
pan-x-c Sep 2, 2024
3194420
finish english tutorial
pan-x-c Sep 2, 2024
2e5db8d
fix linux test
pan-x-c Sep 2, 2024
c4195e7
fix large scale simulation example
pan-x-c Sep 2, 2024
cd2f70c
Merge branch 'feature/pxc/env' of https://github.com/pan-x-c/AgentSco…
chenyushuo Sep 2, 2024
e2e7999
fix grpc fork comp
pan-x-c Sep 2, 2024
6d520c2
Merge branch 'feature/pxc/env' of https://github.com/pan-x-c/AgentSco…
chenyushuo Sep 3, 2024
673f1b6
Merge branch 'main' into feature/pxc/env
pan-x-c Sep 3, 2024
2d0dbab
Merge branch 'feature/pxc/env' of github.com:pan-x-c/AgentScope into …
pan-x-c Sep 3, 2024
145c4ba
rename rpc agent client to rpc client
pan-x-c Sep 3, 2024
b796d90
Add RpcService
chenyushuo Sep 3, 2024
2ef1c89
Add RpcService
chenyushuo Sep 3, 2024
693b516
Add RpcService
chenyushuo Sep 3, 2024
0a2fe7e
Add example for parallel service
chenyushuo Sep 4, 2024
f1e027f
Add example for parallel service
chenyushuo Sep 4, 2024
3ae2aef
Merge branch 'feature/pxc/env' of https://github.com/pan-x-c/AgentSco…
chenyushuo Sep 5, 2024
9808caf
fix in parallel service
chenyushuo Sep 5, 2024
5d3bd26
fix bug alloc server
pan-x-c Sep 5, 2024
5255915
Merge branch 'feature/pxc/env' of https://github.com/pan-x-c/AgentSco…
chenyushuo Sep 5, 2024
6e4531f
fix bug alloc server
pan-x-c Sep 5, 2024
bf9c7bb
Merge branch 'feature/pxc/env' of https://github.com/pan-x-c/AgentSco…
chenyushuo Sep 5, 2024
4d09382
fix bug alloc server
pan-x-c Sep 5, 2024
2d096cb
Merge branch 'feature/pxc/env' of https://github.com/pan-x-c/AgentSco…
chenyushuo Sep 5, 2024
99bac7f
fix in parallel service
chenyushuo Sep 6, 2024
9cd5800
fix in parallel service
chenyushuo Sep 6, 2024
2c8675e
Update _client.py
chenyushuo Sep 6, 2024
7dc164c
code format
chenyushuo Sep 6, 2024
bee2d1f
bug fix
chenyushuo Sep 6, 2024
f0845bb
Merge pull request #8 from chenyushuo/environment
pan-x-c Sep 6, 2024
f4f67ee
merge main
pan-x-c Sep 9, 2024
b10f426
enhance error reporting
pan-x-c Sep 9, 2024
ae2ae9a
fix redis pool
pan-x-c Sep 9, 2024
acd4b77
fix set attr
pan-x-c Sep 9, 2024
8c1a668
fix redis pool
pan-x-c Sep 9, 2024
2ae6cdb
add fix
pan-x-c Sep 10, 2024
3ee5876
call in thread use pool
pan-x-c Sep 10, 2024
d9698dd
fix async test
pan-x-c Sep 12, 2024
c39e9c9
fix linux test
pan-x-c Sep 12, 2024
7a3f946
fix linux test
pan-x-c Sep 12, 2024
c54c9f1
fix pre-commit
pan-x-c Sep 12, 2024
0f98548
use timeout for update placeh
pan-x-c Sep 13, 2024
a8f4c83
server support set capacity
pan-x-c Sep 13, 2024
0b773ed
limit the capcity of sub-process mode
pan-x-c Sep 13, 2024
d52629d
update tutorial
pan-x-c Sep 13, 2024
9b9ace7
opt error report
pan-x-c Sep 13, 2024
f1838a5
fix update resp not exist
pan-x-c Sep 18, 2024
728b8bb
Merge remote-tracking branch 'p.agentscope/feature/pxc/env' into add_…
PatrickG1014 Sep 27, 2024
a1cf0ee
update env auction example
PatrickG1014 Sep 27, 2024
5b9e1a4
update experiment
pan-x-c Oct 8, 2024
bc9a0d1
add retry strategy
pan-x-c Oct 8, 2024
ea6ac25
add rpc agent test with retry strategy
pan-x-c Oct 8, 2024
7d90257
add rpc agent test with retry strategy
pan-x-c Oct 8, 2024
7e404f1
Merge branch 'main' into feature/pxc/env
pan-x-c Oct 8, 2024
987c19a
update doc
pan-x-c Oct 8, 2024
05d85af
fix test
pan-x-c Oct 8, 2024
60d0717
fix retry
pan-x-c Oct 8, 2024
089e695
fix retries
pan-x-c Oct 8, 2024
f5f3002
Merge pull request #7 from PatrickG1014/add_simple_env_example
pan-x-c Oct 8, 2024
e9c1856
simplify auction example
pan-x-c Oct 8, 2024
5d939fc
update tutorial
pan-x-c Oct 11, 2024
dc93bfc
update as_server command
pan-x-c Oct 11, 2024
d86d67c
update tutorial
pan-x-c Oct 11, 2024
2f0851f
update chatroom
pan-x-c Oct 11, 2024
fd41285
update participant
pan-x-c Oct 14, 2024
7620fbf
fix comments
pan-x-c Oct 14, 2024
39c5738
refactor chatroom
pan-x-c Oct 14, 2024
07d6c7f
refactor chatroom
pan-x-c Oct 14, 2024
4509ff4
Merge branch 'feature/pxc/chatroom_eh' into feature/pxc/env
pan-x-c Oct 14, 2024
df680e8
fix precommit
pan-x-c Oct 14, 2024
ca1085a
fix chatroom bug
pan-x-c Oct 14, 2024
5b36a3a
fix cls reference bug
pan-x-c Oct 14, 2024
e6f7dc3
fix cls info
pan-x-c Oct 15, 2024
6bf0fb5
fix chatroom example
pan-x-c Oct 16, 2024
d9f8143
fix
pan-x-c Oct 16, 2024
eb2bfc7
add persona config
pan-x-c Oct 16, 2024
a2f467c
opt retry info
pan-x-c Oct 18, 2024
d29a4ac
quick fix on chatroom
chenyushuo Oct 22, 2024
3a805e9
fix comments
pan-x-c Oct 23, 2024
e2fda5d
fix comments
pan-x-c Oct 23, 2024
c9a07ce
fix comments
pan-x-c Oct 23, 2024
f7b84a3
Merge branch 'main' into feature/pxc/env
pan-x-c Oct 23, 2024
fc98f32
add notes
pan-x-c Oct 23, 2024
a50e58c
fix in chatroom
chenyushuo Oct 23, 2024
4eb9940
fix in chatroom
chenyushuo Oct 23, 2024
7d59469
fix in chatroom
chenyushuo Oct 23, 2024
c6684b1
bug fix in leave chatroom
chenyushuo Oct 23, 2024
dfa5606
bug fix in intro
chenyushuo Oct 23, 2024
84c44de
precommit fix
chenyushuo Oct 23, 2024
b11fa41
Merge pull request #10 from chenyushuo/new_env
pan-x-c Oct 23, 2024
872ffb6
update docs
pan-x-c Oct 23, 2024
d1ae655
update paper info
pan-x-c Oct 28, 2024
72aaa72
simplify env structure
pan-x-c Oct 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix linux test
pan-x-c committed Sep 12, 2024
commit c39e9c9e5270049ef7b28b49f7de1857fdd696ed
6 changes: 1 addition & 5 deletions src/agentscope/rpc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# -*- coding: utf-8 -*-
"""Import all rpc related modules in the package."""
from .rpc_client import (
RpcClient,
call_func_in_thread,
)
from .rpc_client import RpcClient
from .rpc_meta import async_func, sync_func, RpcMeta
from .rpc_config import DistConf
from .rpc_async import AsyncResult
@@ -18,5 +15,4 @@
"sync_func",
"AsyncResult",
"DistConf",
"call_func_in_thread",
]
16 changes: 2 additions & 14 deletions src/agentscope/rpc/rpc_client.py
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@

import json
import os
from typing import Optional, Sequence, Union, Generator, Callable, Any
from concurrent.futures import Future, ThreadPoolExecutor
from typing import Optional, Sequence, Union, Generator, Any
from concurrent.futures import ThreadPoolExecutor
from loguru import logger

from ..message import Msg
@@ -327,18 +327,6 @@ def __reduce__(self) -> tuple:
)


def call_func_in_thread(func: Callable) -> Future:
"""Call a function in a sub-thread.

Args:
func (`Callable`): The function to be called in sub-thread.

Returns:
`Future`: A stub to get the response.
"""
return RpcClient._EXECUTOR.submit(func) # pylint: disable=W0212


class RpcAgentClient(RpcClient):
"""`RpcAgentClient` has renamed to `RpcClient`.
This class is kept for backward compatibility, please use `RpcClient`
51 changes: 36 additions & 15 deletions src/agentscope/rpc/rpc_object.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
"""A proxy object which represent a object located in a rpc server."""
from typing import Any, Callable
from functools import partial
from abc import ABC
from inspect import getmembers, isfunction
from types import FunctionType
from concurrent.futures import ThreadPoolExecutor
import threading

try:
import cloudpickle as pickle
@@ -13,7 +14,7 @@

pickle = ImportErrorReporter(e, "distribute")

from .rpc_client import RpcClient, call_func_in_thread
from .rpc_client import RpcClient
from .rpc_async import AsyncResult
from ..exception import AgentCreationError, AgentServerNotAliveError

@@ -27,6 +28,28 @@ def get_public_methods(cls: type) -> list[str]:
]


class _RpcThreadPool:
"""Executor for rpc object tasks."""

_executor = None
_lock = threading.Lock()

def __init__(self, max_workers: int = 32) -> None:
if _RpcThreadPool._executor is None:
with _RpcThreadPool._lock:
if _RpcThreadPool._executor is None:
_RpcThreadPool._executor = ThreadPoolExecutor(
max_workers=max_workers,
)

@classmethod
def submit(cls, fn: Callable, *args: Any, **kwargs: Any) -> Any:
"""Submit a task to the executor."""
if cls._executor is None:
cls()
return cls._executor.submit(fn, *args, **kwargs)


class RpcObject(ABC):
"""A proxy object which represent an object located in a rpc server."""

@@ -65,6 +88,7 @@ def __init__(
self._oid = oid
self._cls = cls
self.connect_existing = connect_existing
self.executor = ThreadPoolExecutor(max_workers=1)

from ..studio._client import _studio_client

@@ -108,15 +132,14 @@ def __init__(

def create(self, configs: dict) -> None:
"""create the object on the rpc server."""
self._creating_stub = call_func_in_thread(
partial(
self.client.create_agent,
configs,
self._oid,
),
self._creating_stub = _RpcThreadPool.submit(
self.client.create_agent,
configs,
self._oid,
)

def __call__(self, *args: Any, **kwargs: Any) -> Any:
self._check_created()
if "__call__" in self._cls._async_func:
return self._async_func("__call__")(*args, **kwargs)
else:
@@ -159,7 +182,6 @@ def _check_created(self) -> None:

def _call_func(self, func_name: str, args: dict) -> Any:
"""Call a function in rpc server."""
self._check_created()
return pickle.loads(
self.client.call_agent_func(
agent_id=self._oid,
@@ -173,12 +195,10 @@ def async_wrapper(*args, **kwargs) -> Any: # type: ignore[no-untyped-def]
return AsyncResult(
host=self.host,
port=self.port,
stub=call_func_in_thread(
partial(
self._call_func,
func_name=name,
args={"args": args, "kwargs": kwargs},
),
stub=_RpcThreadPool.submit(
self._call_func,
func_name=name,
args={"args": args, "kwargs": kwargs},
),
)

@@ -194,6 +214,7 @@ def sync_wrapper(*args, **kwargs) -> Any: # type: ignore[no-untyped-def]
return sync_wrapper

def __getattr__(self, name: str) -> Callable:
self._check_created()
if name in self._cls._async_func:
# for async functions
return self._async_func(name)
21 changes: 10 additions & 11 deletions tests/async_result_pool_test.py
Original file line number Diff line number Diff line change
@@ -2,12 +2,11 @@
"""Test the async result pool."""
import unittest
import time
import functools
import pickle

from loguru import logger

from agentscope.rpc import call_func_in_thread
from agentscope.rpc.rpc_object import _RpcThreadPool
from agentscope.server.async_result_pool import (
AsyncResultPool,
get_pool,
@@ -38,18 +37,18 @@ def _test_result_pool(self, pool: AsyncResultPool) -> None:
for target_value in range(10):
oid = pool.prepare()
get_stubs.append(
call_func_in_thread(
functools.partial(test_get_func, oid=oid, pool=pool),
_RpcThreadPool.submit(
test_get_func,
oid=oid,
pool=pool,
),
)
set_stubs.append(
call_func_in_thread(
functools.partial(
test_set_func,
oid=oid,
value=target_value,
pool=pool,
),
_RpcThreadPool.submit(
test_set_func,
oid=oid,
value=target_value,
pool=pool,
),
)
et = time.time()