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

Rebuild AgentScope Studio #238

Merged
merged 92 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
51ab7a8
Split the rpc_agent module into multiple submodules
pan-x-c May 10, 2024
dbf5b18
rename RpcAgentServerLauncher to AgentServerLauncher
pan-x-c May 10, 2024
7997f7a
add as_server into setup and support graceful shutdown
pan-x-c May 10, 2024
a92eac2
add server_id
pan-x-c May 10, 2024
9163241
update tutorial for agent server
pan-x-c May 10, 2024
31228b6
update tutorial for agent server
pan-x-c May 10, 2024
23a8f5f
update tutorial for agent server
pan-x-c May 10, 2024
918c750
fix windows add_signal_handler
pan-x-c May 10, 2024
8f3eaa2
rename agentserverlauncher
pan-x-c May 10, 2024
49c5dcf
add model_config_path and update tutorial
pan-x-c May 10, 2024
b635e35
update tutorial
pan-x-c May 13, 2024
939615f
merge conflict
pan-x-c May 15, 2024
c96156d
fix pre-commit
pan-x-c May 15, 2024
bf86cc5
fix comments
pan-x-c May 16, 2024
c9eaf2d
fix comments
pan-x-c May 17, 2024
6ba2d82
Merge branch 'main' into feature/pxc/app_server_id
pan-x-c May 17, 2024
0c1fbc1
add websocket for message handling
pan-x-c May 17, 2024
7215974
init agentscope studio plus
pan-x-c May 20, 2024
8ac0595
Merge branch 'main' into feature/pxc/refactor_studio
pan-x-c May 20, 2024
e06a0ec
add api for get messages and runs
pan-x-c May 21, 2024
271c8e4
update api of get messages and runs
pan-x-c May 21, 2024
b02c7b2
add more fields into message
pan-x-c May 21, 2024
8f708a8
1. Remove the previous version of WebUI and Studio; 2. Add new framew…
DavdGao May 21, 2024
f776641
reformat
DavdGao May 21, 2024
5464994
rename old studio to gradio
pan-x-c May 22, 2024
6982c89
add api to get available run_id
pan-x-c May 22, 2024
88aa820
1. Rename market to gallery; 2. Add main and base color; 3. Add disco…
DavdGao May 22, 2024
294bffe
update apis
pan-x-c May 22, 2024
14cdf3a
update client
pan-x-c May 22, 2024
d653415
1. add new font; 2. adjust speaker icon; 3. adjust runs tables; 4. ad…
DavdGao May 22, 2024
f92105a
studio dialogue finish
pan-x-c May 22, 2024
77d387e
Merge branch 'feature/pxc/refactor_studio' into refactor_studio
pan-x-c May 23, 2024
65df19c
Merge pull request #2 from DavdGao/refactor_studio
pan-x-c May 23, 2024
0fe4d80
finish dashboard dialogue page
pan-x-c May 23, 2024
e0ac80a
add socketio js
pan-x-c May 23, 2024
316d680
fix comments
pan-x-c May 23, 2024
b3ac0e2
fix setup
pan-x-c May 23, 2024
e3ba12e
register server
pan-x-c May 23, 2024
2607dbb
studio support subprocess mode rpc agent
pan-x-c May 23, 2024
7328b50
fix comments
pan-x-c May 23, 2024
e9da463
provide run detail page url when starting app
pan-x-c May 23, 2024
c20a00e
WIP
DavdGao May 27, 2024
5bf59f0
finish adding workstation in a single html
DavdGao May 27, 2024
b50c33d
fix
DavdGao May 27, 2024
16300c6
push
DavdGao May 27, 2024
60eea62
Merge branch 'my_refactor_studio' into feature/pxc/refactor_studio
DavdGao May 27, 2024
58b91eb
merge main
pan-x-c May 28, 2024
4b89ffd
render dialogue content as markdown
pan-x-c May 28, 2024
7dbe29b
fix pre-comment
pan-x-c May 28, 2024
f4253be
add check before export and run
qbc2016 May 29, 2024
e2cc4b2
refine input
qbc2016 May 29, 2024
f40a90b
remove output number checking
qbc2016 May 31, 2024
f98f9e4
[WIP]
DavdGao May 31, 2024
b35c084
[WIP]
DavdGao Jun 3, 2024
bc000bd
[WIP]
DavdGao Jun 4, 2024
6cf08d6
finish debugging dashboard
DavdGao Jun 5, 2024
aa6d5b9
bug fix
DavdGao Jun 5, 2024
e41a701
Support pointer in guidance
DavdGao Jun 5, 2024
35a3c0c
merge and fix conflicts
qbc2016 Jun 5, 2024
1955c9d
change id to class
qbc2016 Jun 5, 2024
7c61eb3
fix pre-commit and add psutil
qbc2016 Jun 6, 2024
3ba8269
add studio_requires
qbc2016 Jun 6, 2024
b81b935
Merge pull request #4 from qbc2016/dev_input_refine
pan-x-c Jun 6, 2024
65a39e0
fix rpc agent
pan-x-c Jun 6, 2024
4a46c89
fix conflict
pan-x-c Jun 6, 2024
d96bbdf
fix double chat
pan-x-c Jun 6, 2024
875f515
render chat history with highlight
pan-x-c Jun 6, 2024
ee369d3
fix link display in dashboard
pan-x-c Jun 6, 2024
125448a
fix workstation button and comming soon message
pan-x-c Jun 6, 2024
c39bf2f
fix run_id link
pan-x-c Jun 7, 2024
fc3ab23
change run_dir to abs_path
pan-x-c Jun 7, 2024
10dfae5
hide agent btn in dialogue page
pan-x-c Jun 7, 2024
7a7ecea
jump to dashboard main
pan-x-c Jun 7, 2024
5cac2b2
fix code display
pan-x-c Jun 7, 2024
bdf907d
fix bold and italic in markdown
pan-x-c Jun 7, 2024
a9f5749
fix api invocation display
pan-x-c Jun 7, 2024
ad80d2c
set default sorter for api invocation
pan-x-c Jun 7, 2024
3514c9a
Fix bug in missing value warning; Add default handler for roles;
DavdGao Jun 7, 2024
aa134ce
remove katex
pan-x-c Jun 7, 2024
7559d62
fix details btn
pan-x-c Jun 7, 2024
3916aa7
Rename functions into private ones
DavdGao Jun 7, 2024
39f2195
fix url type
pan-x-c Jun 7, 2024
3d2b184
Merge pull request #5 from DavdGao/feature/pxc/refactor_studio_dawei
pan-x-c Jun 7, 2024
2c7a89f
[WIP]
DavdGao Jun 8, 2024
7fdb552
Remove language switch functionality; Press send button to enable mes…
DavdGao Jun 8, 2024
e95550f
Fix the ImportError for studio client
DavdGao Jun 8, 2024
8220f73
Move studio from agentscope/web/studio into agentscope/studio
DavdGao Jun 8, 2024
f254138
Change the entry point of AgentScope Studio
DavdGao Jun 8, 2024
e34bfc4
Fix error in import _studio_client; Clean unnecessary logging in js a…
DavdGao Jun 9, 2024
9833c26
Remove unnecessary change; fix bug in conversation example.
DavdGao Jun 9, 2024
65c729e
Modify the cache dir
DavdGao Jun 9, 2024
439d411
fix typos
pan-x-c Jun 9, 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
23 changes: 23 additions & 0 deletions src/agentscope/_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from .models import read_model_configs
from .constants import _DEFAULT_DIR
from .constants import _DEFAULT_LOG_LEVEL
from .web.client import HttpClient

# init setting
_INIT_SETTINGS = {}
Expand All @@ -30,6 +31,7 @@ def init(
logger_level: LOG_LEVEL = _DEFAULT_LOG_LEVEL,
runtime_id: Optional[str] = None,
agent_configs: Optional[Union[str, list, dict]] = None,
studio_url: Optional[str] = None,
) -> Sequence[AgentBase]:
"""A unified entry to initialize the package, including model configs,
runtime names, saving directories and logging settings.
Expand Down Expand Up @@ -65,6 +67,8 @@ def init(
which can be loaded by json.loads(). One agent config should
cover the required arguments to initialize a specific agent
object, otherwise the default values will be used.
studio_url (`Optional[str]`, defaults to `None`):
The url of the studio.
"""
init_process(
model_configs=model_configs,
Expand All @@ -76,6 +80,7 @@ def init(
save_log=save_log,
use_monitor=use_monitor,
logger_level=logger_level,
studio_url=studio_url,
)

# save init settings for subprocess
Expand Down Expand Up @@ -128,6 +133,7 @@ def init_process(
save_log: bool = False,
use_monitor: bool = True,
logger_level: LOG_LEVEL = _DEFAULT_LOG_LEVEL,
studio_url: Optional[str] = None,
) -> None:
"""An entry to initialize the package in a process.

Expand Down Expand Up @@ -157,10 +163,16 @@ def init_process(
# Init the runtime
if project is not None:
_runtime.project = project
else:
project = _runtime.project
if name is not None:
_runtime.name = name
else:
name = _runtime.name
if runtime_id is not None:
_runtime.runtime_id = runtime_id
else:
runtime_id = _runtime.runtime_id

# Init logger
dir_log = str(file_manager.dir_log) if save_log else None
Expand All @@ -178,3 +190,14 @@ def init_process(
db_path=file_manager.path_db,
impl_type="sqlite" if use_monitor else "dummy",
)
if studio_url is not None:
client = HttpClient(
studio_url=studio_url,
run_id=_runtime.runtime_id,
)
client.register_run(
project=project,
name=name,
run_dir=file_manager.dir,
)
_runtime.studio_client = client
4 changes: 4 additions & 0 deletions src/agentscope/_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from agentscope.utils.tools import _get_timestamp
from agentscope.utils.tools import _generate_random_code
from agentscope.web.client import HttpClient

_RUNTIME_ID_FORMAT = "run_%Y%m%d-%H%M%S_{}"
_RUNTIME_TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M:%S"
Expand All @@ -24,6 +25,9 @@ class _Runtime:
"""The id for runtime, which is used to identify the this runtime and
name the saving directory."""

studio_client: HttpClient = None
"""The client of AgentScope Studio."""

_timestamp: datetime = datetime.now()
"""The timestamp of when the runtime is initialized."""

Expand Down
14 changes: 14 additions & 0 deletions src/agentscope/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from agentscope.agents.operator import Operator
from agentscope.models import load_model_by_config_name
from agentscope.memory import TemporaryMemory
from agentscope._runtime import _runtime


class _AgentMeta(ABCMeta):
Expand Down Expand Up @@ -305,6 +306,19 @@ def speak(
) -> None:
"""Speak out the content generated by the agent."""
logger.chat(content)
if _runtime.studio_client is not None:
if isinstance(content, dict):
_runtime.studio_client.send_message(
name=content.get("name", ""),
content=content.get("content", ""),
url=content.get("url", ""),
)
else:
_runtime.studio_client.send_message(
name="",
content=str(content),
url="",
)

def observe(self, x: Union[dict, Sequence[dict]]) -> None:
"""Observe the input, store it in memory without response to it.
Expand Down
56 changes: 32 additions & 24 deletions src/agentscope/agents/user_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from loguru import logger

from agentscope.agents import AgentBase
from agentscope._runtime import _runtime
from agentscope.message import Msg
from agentscope.web.studio.utils import user_input

Expand All @@ -29,6 +30,14 @@ def __init__(self, name: str = "User", require_url: bool = False) -> None:

self.name = name
self.require_url = require_url
if _runtime.studio_client is not None:
self.input_client = (
_runtime.studio_client.generate_user_input_client(
self.agent_id,
)
)
else:
self.input_client = None

def reply(
self,
Expand Down Expand Up @@ -67,23 +76,29 @@ def reply(

# TODO: To avoid order confusion, because `input` print much quicker
# than logger.chat
time.sleep(0.5)
content = user_input(timeout=timeout)

kwargs = {}
if required_keys is not None:
if isinstance(required_keys, str):
required_keys = [required_keys]

for key in required_keys:
kwargs[key] = input(f"{key}: ")

# Input url of file, image, video, audio or website
url = None
if self.require_url:
url = input("URL (or Enter to skip): ")
if url == "":
url = None
if self.input_client:
logger.info(
f"Waiting for input from {self.input_client.studio_url}...",
)
raw_input = self.input_client.get_user_input()
content = raw_input["content"]
else:
time.sleep(0.5)
content = user_input(timeout=timeout)
kwargs = {}
if required_keys is not None:
if isinstance(required_keys, str):
required_keys = [required_keys]

for key in required_keys:
kwargs[key] = input(f"{key}: ")

# Input url of file, image, video, audio or website
url = None
if self.require_url:
url = input("URL (or Enter to skip): ")
if url == "":
url = None

# Add additional keys
msg = Msg(
Expand All @@ -101,10 +116,3 @@ def reply(
self.memory.add(msg)

return msg

def speak(
pan-x-c marked this conversation as resolved.
Show resolved Hide resolved
self,
content: Union[str, dict],
) -> None:
"""Speak the content to the audience."""
logger.chat(content, disable_studio=True)
Loading