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 all 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
4 changes: 3 additions & 1 deletion examples/distributed_debate/distributed_debate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

from user_proxy_agent import UserProxyAgent

from loguru import logger

import agentscope
from agentscope.agents import DialogAgent
from agentscope.msghub import msghub
from agentscope.server import RpcAgentServerLauncher
from agentscope.message import Msg
from agentscope.utils.logging_utils import logger


FIRST_ROUND = """
Welcome to the debate on whether Artificial General Intelligence (AGI) can be achieved using the GPT model framework. This debate will consist of three rounds. In each round, the affirmative side will present their argument first, followed by the negative side. After both sides have presented, the adjudicator will summarize the key points and analyze the strengths of the arguments.
Expand Down
9 changes: 8 additions & 1 deletion examples/distributed_search/searcher_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def reply(self, x: dict = None) -> dict:
),
)
query = self.model(prompt).text
self.speak(query)
results = self.search(
question=query,
num_results=self.result_num,
Expand All @@ -85,4 +84,12 @@ def reply(self, x: dict = None) -> dict:
for result in results
],
)
self.speak(
Msg(
name=self.name,
role="assistant",
content="Search results:\n"
f"{[result['link'] for result in results]}",
),
)
return msg
8 changes: 7 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
"black",
]

studio_requires = []

# released requires
minimal_requires = [
"docstring_parser",
Expand All @@ -66,6 +68,7 @@
"Flask==3.0.0",
"Flask-Cors==4.0.0",
"Flask-SocketIO==5.3.6",
"flask_sqlalchemy",
"flake8",
# TODO: move into other requires
"dashscope==1.14.1",
Expand All @@ -74,6 +77,7 @@
"google-generativeai>=0.4.0",
"zhipuai",
"litellm",
"psutil",
]

distribute_requires = minimal_requires + rpc_requires
Expand All @@ -87,6 +91,7 @@
+ doc_requires
+ test_requires
+ gradio_requires
+ studio_requires
)

with open("README.md", "r", encoding="UTF-8") as fh:
Expand Down Expand Up @@ -123,7 +128,8 @@
python_requires=">=3.9",
entry_points={
"console_scripts": [
"as_studio=agentscope.web.studio.studio:run_app",
"as_studio=agentscope.studio:init",
"as_gradio=agentscope.web.gradio.studio:run_app",
"as_workflow=agentscope.web.workstation.workflow:main",
"as_server=agentscope.server.launcher:as_server",
],
Expand Down
30 changes: 27 additions & 3 deletions src/agentscope/_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
from .agents import AgentBase
from ._runtime import _runtime
from .file_manager import file_manager
from .utils.logging_utils import LOG_LEVEL, setup_logger
from .logging import LOG_LEVEL, setup_logger
from .utils.monitor import MonitorFactory
from .models import read_model_configs
from .constants import _DEFAULT_DIR
from .constants import _DEFAULT_LOG_LEVEL
from .studio._client import _studio_client

# 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 agentscope studio.
"""
init_process(
model_configs=model_configs,
Expand All @@ -76,17 +80,19 @@ def init(
save_log=save_log,
use_monitor=use_monitor,
logger_level=logger_level,
studio_url=studio_url,
)

# save init settings for subprocess
_INIT_SETTINGS["model_configs"] = model_configs
_INIT_SETTINGS["project"] = project
_INIT_SETTINGS["name"] = name
_INIT_SETTINGS["project"] = _runtime.project
_INIT_SETTINGS["name"] = _runtime.name
_INIT_SETTINGS["runtime_id"] = _runtime.runtime_id
_INIT_SETTINGS["save_dir"] = save_dir
_INIT_SETTINGS["save_api_invoke"] = save_api_invoke
_INIT_SETTINGS["save_log"] = save_log
_INIT_SETTINGS["logger_level"] = logger_level
_INIT_SETTINGS["use_monitor"] = use_monitor

# Save code if needed
if save_code:
Expand Down Expand Up @@ -128,6 +134,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 All @@ -153,12 +160,16 @@ def init_process(
Whether to activate the monitor.
logger_level (`LOG_LEVEL`, defaults to `"INFO"`):
The logging level of logger.
studio_url (`Optional[str]`, defaults to `None`):
The url of the agentscope studio.
"""
# Init the runtime
if project is not None:
_runtime.project = project

if name is not None:
_runtime.name = name

if runtime_id is not None:
_runtime.runtime_id = runtime_id

Expand All @@ -178,3 +189,16 @@ def init_process(
db_path=file_manager.path_db,
impl_type="sqlite" if use_monitor else "dummy",
)

# Init studio client, which will push messages to web ui and fetch user
# inputs from web ui
if studio_url is not None:
_studio_client.initialize(_runtime.runtime_id, studio_url)
# Register in AgentScope Studio
_studio_client.register_running_instance(
project=_runtime.project,
name=_runtime.name,
timestamp=_runtime.timestamp,
run_dir=file_manager.dir_root,
pid=os.getpid(),
)
22 changes: 18 additions & 4 deletions src/agentscope/_runtime.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-
"""Manage the id for each runtime"""
import os
from datetime import datetime
from typing import Any

from agentscope.utils.tools import _get_timestamp
from agentscope.utils.tools import _get_process_creation_time
from agentscope.utils.tools import _generate_random_code

_RUNTIME_ID_FORMAT = "run_%Y%m%d-%H%M%S_{}"
Expand All @@ -14,17 +16,20 @@ class _Runtime:
"""A singleton class used to record the runtime information, which will
be initialized when the package is imported."""

project: str = None
project: str
"""The project name, which is used to identify the project."""

name: str = None
name: str
"""The name for runtime, which is used to identify this runtime."""

runtime_id: str = None
runtime_id: str
"""The id for runtime, which is used to identify the this runtime and
name the saving directory."""

_timestamp: datetime = datetime.now()
pid: int
"""The process id of the runtime."""

_timestamp: datetime
"""The timestamp of when the runtime is initialized."""

_instance = None
Expand All @@ -48,13 +53,22 @@ def __init__(self) -> None:
self.project = _generate_random_code()
self.name = _generate_random_code(uppercase=False)

self.pid = os.getpid()
self._timestamp = _get_process_creation_time()

# Obtain time from timestamp in string format, and then turn it into
# runtime ID format
self.runtime_id = _get_timestamp(
_RUNTIME_ID_FORMAT,
self._timestamp,
).format(self.name)

def generate_new_runtime_id(self) -> str:
"""Generate a new random runtime id."""
return _get_timestamp(_RUNTIME_ID_FORMAT).format(
_generate_random_code(uppercase=False),
)

@property
def timestamp(self) -> str:
"""Get the current timestamp in specific format."""
Expand Down
30 changes: 27 additions & 3 deletions src/agentscope/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from loguru import logger

from agentscope.agents.operator import Operator
from agentscope.message import Msg
from agentscope.models import load_model_by_config_name
from agentscope.memory import TemporaryMemory

Expand Down Expand Up @@ -301,10 +302,33 @@ def __call__(self, *args: Any, **kwargs: Any) -> dict:

def speak(
self,
content: Union[str, dict],
content: Union[str, Msg],
) -> None:
"""Speak out the content generated by the agent."""
logger.chat(content)
"""
Speak out the message generated by the agent. If a string is given,
a Msg object will be created with the string as the content.

Args:
content (`Union[str, Msg]`):
The content of the message to be spoken out. If a string is
given, a Msg object will be created with the agent's name, role
as "assistant", and the given string as the content.
"""
if isinstance(content, str):
msg = Msg(
name=self.name,
content=content,
role="assistant",
)
elif isinstance(content, Msg):
msg = content
else:
raise TypeError(
"From version 0.0.5, the speak method only accepts str or Msg "
f"object, got {type(content)} instead.",
)

logger.chat(msg)

def observe(self, x: Union[dict, Sequence[dict]]) -> None:
"""Observe the input, store it in memory without response to it.
Expand Down
5 changes: 5 additions & 0 deletions src/agentscope/agents/rpc_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
)
from agentscope.rpc import RpcAgentClient
from agentscope.server.launcher import RpcAgentServerLauncher
from agentscope.studio._client import _studio_client


class RpcAgent(AgentBase):
Expand Down Expand Up @@ -70,13 +71,17 @@ def __init__(
launch_server = port is None
if launch_server:
self.host = "localhost"
studio_url = None
if _studio_client.active:
studio_url = _studio_client.studio_url
self.server_launcher = RpcAgentServerLauncher(
host=self.host,
port=port,
max_pool_size=max_pool_size,
max_timeout_seconds=max_timeout_seconds,
local_mode=local_mode,
custom_agents=[agent_class],
studio_url=studio_url,
)
if not lazy_launch:
self._launch_server()
Expand Down
Loading