agentscope-runtime 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentscope_runtime/__init__.py +4 -0
- agentscope_runtime/engine/__init__.py +9 -0
- agentscope_runtime/engine/agents/__init__.py +2 -0
- agentscope_runtime/engine/agents/agentscope_agent/__init__.py +6 -0
- agentscope_runtime/engine/agents/agentscope_agent/agent.py +342 -0
- agentscope_runtime/engine/agents/agentscope_agent/hooks.py +156 -0
- agentscope_runtime/engine/agents/agno_agent.py +220 -0
- agentscope_runtime/engine/agents/base_agent.py +29 -0
- agentscope_runtime/engine/agents/langgraph_agent.py +59 -0
- agentscope_runtime/engine/agents/llm_agent.py +51 -0
- agentscope_runtime/engine/deployers/__init__.py +3 -0
- agentscope_runtime/engine/deployers/adapter/__init__.py +0 -0
- agentscope_runtime/engine/deployers/adapter/a2a/__init__.py +2 -0
- agentscope_runtime/engine/deployers/adapter/a2a/a2a_adapter_utils.py +425 -0
- agentscope_runtime/engine/deployers/adapter/a2a/a2a_agent_adapter.py +69 -0
- agentscope_runtime/engine/deployers/adapter/a2a/a2a_protocol_adapter.py +60 -0
- agentscope_runtime/engine/deployers/adapter/protocol_adapter.py +24 -0
- agentscope_runtime/engine/deployers/base.py +17 -0
- agentscope_runtime/engine/deployers/local_deployer.py +586 -0
- agentscope_runtime/engine/helpers/helper.py +127 -0
- agentscope_runtime/engine/llms/__init__.py +3 -0
- agentscope_runtime/engine/llms/base_llm.py +60 -0
- agentscope_runtime/engine/llms/qwen_llm.py +47 -0
- agentscope_runtime/engine/misc/__init__.py +0 -0
- agentscope_runtime/engine/runner.py +186 -0
- agentscope_runtime/engine/schemas/__init__.py +0 -0
- agentscope_runtime/engine/schemas/agent_schemas.py +551 -0
- agentscope_runtime/engine/schemas/context.py +54 -0
- agentscope_runtime/engine/services/__init__.py +9 -0
- agentscope_runtime/engine/services/base.py +77 -0
- agentscope_runtime/engine/services/context_manager.py +129 -0
- agentscope_runtime/engine/services/environment_manager.py +50 -0
- agentscope_runtime/engine/services/manager.py +174 -0
- agentscope_runtime/engine/services/memory_service.py +270 -0
- agentscope_runtime/engine/services/sandbox_service.py +198 -0
- agentscope_runtime/engine/services/session_history_service.py +256 -0
- agentscope_runtime/engine/tracing/__init__.py +40 -0
- agentscope_runtime/engine/tracing/base.py +309 -0
- agentscope_runtime/engine/tracing/local_logging_handler.py +356 -0
- agentscope_runtime/engine/tracing/tracing_metric.py +69 -0
- agentscope_runtime/engine/tracing/wrapper.py +321 -0
- agentscope_runtime/sandbox/__init__.py +14 -0
- agentscope_runtime/sandbox/box/__init__.py +0 -0
- agentscope_runtime/sandbox/box/base/__init__.py +0 -0
- agentscope_runtime/sandbox/box/base/base_sandbox.py +37 -0
- agentscope_runtime/sandbox/box/base/box/__init__.py +0 -0
- agentscope_runtime/sandbox/box/browser/__init__.py +0 -0
- agentscope_runtime/sandbox/box/browser/box/__init__.py +0 -0
- agentscope_runtime/sandbox/box/browser/browser_sandbox.py +176 -0
- agentscope_runtime/sandbox/box/dummy/__init__.py +0 -0
- agentscope_runtime/sandbox/box/dummy/dummy_sandbox.py +26 -0
- agentscope_runtime/sandbox/box/filesystem/__init__.py +0 -0
- agentscope_runtime/sandbox/box/filesystem/box/__init__.py +0 -0
- agentscope_runtime/sandbox/box/filesystem/filesystem_sandbox.py +87 -0
- agentscope_runtime/sandbox/box/sandbox.py +115 -0
- agentscope_runtime/sandbox/box/shared/__init__.py +0 -0
- agentscope_runtime/sandbox/box/shared/app.py +44 -0
- agentscope_runtime/sandbox/box/shared/dependencies/__init__.py +5 -0
- agentscope_runtime/sandbox/box/shared/dependencies/deps.py +22 -0
- agentscope_runtime/sandbox/box/shared/routers/__init__.py +12 -0
- agentscope_runtime/sandbox/box/shared/routers/generic.py +173 -0
- agentscope_runtime/sandbox/box/shared/routers/mcp.py +207 -0
- agentscope_runtime/sandbox/box/shared/routers/mcp_utils.py +153 -0
- agentscope_runtime/sandbox/box/shared/routers/runtime_watcher.py +187 -0
- agentscope_runtime/sandbox/box/shared/routers/workspace.py +325 -0
- agentscope_runtime/sandbox/box/training_box/__init__.py +0 -0
- agentscope_runtime/sandbox/box/training_box/base.py +120 -0
- agentscope_runtime/sandbox/box/training_box/env_service.py +752 -0
- agentscope_runtime/sandbox/box/training_box/environments/__init__.py +0 -0
- agentscope_runtime/sandbox/box/training_box/environments/appworld/appworld_env.py +987 -0
- agentscope_runtime/sandbox/box/training_box/registry.py +54 -0
- agentscope_runtime/sandbox/box/training_box/src/trajectory.py +278 -0
- agentscope_runtime/sandbox/box/training_box/training_box.py +219 -0
- agentscope_runtime/sandbox/build.py +213 -0
- agentscope_runtime/sandbox/client/__init__.py +5 -0
- agentscope_runtime/sandbox/client/http_client.py +527 -0
- agentscope_runtime/sandbox/client/training_client.py +265 -0
- agentscope_runtime/sandbox/constant.py +5 -0
- agentscope_runtime/sandbox/custom/__init__.py +16 -0
- agentscope_runtime/sandbox/custom/custom_sandbox.py +40 -0
- agentscope_runtime/sandbox/custom/example.py +37 -0
- agentscope_runtime/sandbox/enums.py +68 -0
- agentscope_runtime/sandbox/manager/__init__.py +4 -0
- agentscope_runtime/sandbox/manager/collections/__init__.py +22 -0
- agentscope_runtime/sandbox/manager/collections/base_mapping.py +20 -0
- agentscope_runtime/sandbox/manager/collections/base_queue.py +25 -0
- agentscope_runtime/sandbox/manager/collections/base_set.py +25 -0
- agentscope_runtime/sandbox/manager/collections/in_memory_mapping.py +22 -0
- agentscope_runtime/sandbox/manager/collections/in_memory_queue.py +28 -0
- agentscope_runtime/sandbox/manager/collections/in_memory_set.py +27 -0
- agentscope_runtime/sandbox/manager/collections/redis_mapping.py +26 -0
- agentscope_runtime/sandbox/manager/collections/redis_queue.py +27 -0
- agentscope_runtime/sandbox/manager/collections/redis_set.py +23 -0
- agentscope_runtime/sandbox/manager/container_clients/__init__.py +8 -0
- agentscope_runtime/sandbox/manager/container_clients/base_client.py +39 -0
- agentscope_runtime/sandbox/manager/container_clients/docker_client.py +170 -0
- agentscope_runtime/sandbox/manager/sandbox_manager.py +694 -0
- agentscope_runtime/sandbox/manager/server/__init__.py +0 -0
- agentscope_runtime/sandbox/manager/server/app.py +194 -0
- agentscope_runtime/sandbox/manager/server/config.py +68 -0
- agentscope_runtime/sandbox/manager/server/models.py +17 -0
- agentscope_runtime/sandbox/manager/storage/__init__.py +10 -0
- agentscope_runtime/sandbox/manager/storage/data_storage.py +16 -0
- agentscope_runtime/sandbox/manager/storage/local_storage.py +44 -0
- agentscope_runtime/sandbox/manager/storage/oss_storage.py +89 -0
- agentscope_runtime/sandbox/manager/utils.py +78 -0
- agentscope_runtime/sandbox/mcp_server.py +192 -0
- agentscope_runtime/sandbox/model/__init__.py +12 -0
- agentscope_runtime/sandbox/model/api.py +16 -0
- agentscope_runtime/sandbox/model/container.py +72 -0
- agentscope_runtime/sandbox/model/manager_config.py +158 -0
- agentscope_runtime/sandbox/registry.py +129 -0
- agentscope_runtime/sandbox/tools/__init__.py +12 -0
- agentscope_runtime/sandbox/tools/base/__init__.py +8 -0
- agentscope_runtime/sandbox/tools/base/tool.py +52 -0
- agentscope_runtime/sandbox/tools/browser/__init__.py +57 -0
- agentscope_runtime/sandbox/tools/browser/tool.py +597 -0
- agentscope_runtime/sandbox/tools/filesystem/__init__.py +32 -0
- agentscope_runtime/sandbox/tools/filesystem/tool.py +319 -0
- agentscope_runtime/sandbox/tools/function_tool.py +321 -0
- agentscope_runtime/sandbox/tools/mcp_tool.py +191 -0
- agentscope_runtime/sandbox/tools/sandbox_tool.py +104 -0
- agentscope_runtime/sandbox/tools/tool.py +123 -0
- agentscope_runtime/sandbox/tools/utils.py +68 -0
- agentscope_runtime/version.py +2 -0
- agentscope_runtime-0.1.0.dist-info/METADATA +327 -0
- agentscope_runtime-0.1.0.dist-info/RECORD +131 -0
- agentscope_runtime-0.1.0.dist-info/WHEEL +5 -0
- agentscope_runtime-0.1.0.dist-info/entry_points.txt +4 -0
- agentscope_runtime-0.1.0.dist-info/licenses/LICENSE +202 -0
- agentscope_runtime-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from typing import AsyncGenerator
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class BaseLLM:
|
|
6
|
+
base_url = None
|
|
7
|
+
|
|
8
|
+
def __init__(self, model_name: str, **kwargs):
|
|
9
|
+
self.client = None
|
|
10
|
+
self.async_client = None
|
|
11
|
+
self.model_name = model_name
|
|
12
|
+
self.kwargs = kwargs
|
|
13
|
+
|
|
14
|
+
def generate(self, prompt: str, **kwargs) -> str:
|
|
15
|
+
"""
|
|
16
|
+
Generate a response from the Qwen LLM model.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
prompt (str): The prompt to generate a response for.
|
|
20
|
+
**kwargs: Additional keyword arguments to pass to the model.
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
str: The generated response.
|
|
24
|
+
"""
|
|
25
|
+
response = self.client.chat.completions.create(
|
|
26
|
+
model=self.model_name,
|
|
27
|
+
messages=[
|
|
28
|
+
{"role": "system", "content": "You are a helpful assistant."},
|
|
29
|
+
{"role": "user", "content": prompt},
|
|
30
|
+
],
|
|
31
|
+
**kwargs,
|
|
32
|
+
)
|
|
33
|
+
return response.choices[0].message.content
|
|
34
|
+
|
|
35
|
+
def chat(self, messages, **kwargs) -> str:
|
|
36
|
+
response = self.client.chat.completions.create(
|
|
37
|
+
model=self.model_name,
|
|
38
|
+
messages=messages,
|
|
39
|
+
**kwargs,
|
|
40
|
+
)
|
|
41
|
+
return response.choices[0].message.content
|
|
42
|
+
|
|
43
|
+
async def chat_stream(
|
|
44
|
+
self,
|
|
45
|
+
messages,
|
|
46
|
+
tools=None,
|
|
47
|
+
**kwargs,
|
|
48
|
+
) -> AsyncGenerator[str, None]:
|
|
49
|
+
# call model
|
|
50
|
+
# TODO: use async client
|
|
51
|
+
generator = self.client.chat.completions.create(
|
|
52
|
+
model=self.model_name,
|
|
53
|
+
messages=messages,
|
|
54
|
+
tools=tools,
|
|
55
|
+
stream=True,
|
|
56
|
+
**kwargs,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
for chunk in generator:
|
|
60
|
+
yield chunk
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
from openai import Client, AsyncClient
|
|
5
|
+
|
|
6
|
+
from .base_llm import BaseLLM
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class QwenLLM(BaseLLM):
|
|
10
|
+
"""
|
|
11
|
+
QwenLLM is a class that provides a wrapper around the Qwen LLM model.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
base_url = None
|
|
15
|
+
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
model_name: str = "qwen-turbo",
|
|
19
|
+
api_key: str = None,
|
|
20
|
+
**kwargs,
|
|
21
|
+
):
|
|
22
|
+
"""
|
|
23
|
+
Initialize the QwenLLM class.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
model_name (str): The name of the Qwen LLM model to use.
|
|
27
|
+
Defaults to "qwen-turbo".
|
|
28
|
+
api_key (str): The API key for Qwen service.
|
|
29
|
+
If None, will read from DASHSCOPE_API_KEY environment variable.
|
|
30
|
+
"""
|
|
31
|
+
super().__init__(model_name, **kwargs)
|
|
32
|
+
|
|
33
|
+
if api_key is None:
|
|
34
|
+
api_key = os.getenv("DASHSCOPE_API_KEY")
|
|
35
|
+
if self.base_url is None:
|
|
36
|
+
default_base_url = (
|
|
37
|
+
"https://dashscope.aliyuncs.com/compatible-mode/v1"
|
|
38
|
+
)
|
|
39
|
+
self.base_url = os.getenv("DASHSCOPE_BASE_URL", default_base_url)
|
|
40
|
+
self.client = Client(
|
|
41
|
+
api_key=api_key,
|
|
42
|
+
base_url=self.base_url,
|
|
43
|
+
)
|
|
44
|
+
self.async_client = AsyncClient(
|
|
45
|
+
api_key=api_key,
|
|
46
|
+
base_url=self.base_url,
|
|
47
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import uuid
|
|
3
|
+
from typing import Optional, List, AsyncGenerator, Any
|
|
4
|
+
|
|
5
|
+
from openai.types.chat import ChatCompletion
|
|
6
|
+
|
|
7
|
+
from .deployers.adapter.protocol_adapter import ProtocolAdapter
|
|
8
|
+
from .agents import Agent
|
|
9
|
+
from .schemas.context import Context
|
|
10
|
+
from .deployers import (
|
|
11
|
+
DeployManager,
|
|
12
|
+
LocalDeployManager,
|
|
13
|
+
)
|
|
14
|
+
from .schemas.agent_schemas import (
|
|
15
|
+
Event,
|
|
16
|
+
AgentRequest,
|
|
17
|
+
RunStatus,
|
|
18
|
+
AgentResponse,
|
|
19
|
+
)
|
|
20
|
+
from .services.context_manager import ContextManager
|
|
21
|
+
from .services.environment_manager import EnvironmentManager
|
|
22
|
+
from .tracing import TraceType
|
|
23
|
+
from .tracing.wrapper import trace
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Runner:
|
|
27
|
+
def __init__(
|
|
28
|
+
self,
|
|
29
|
+
agent: Agent,
|
|
30
|
+
environment_manager: Optional[EnvironmentManager] = None,
|
|
31
|
+
context_manager: Optional[ContextManager] = None,
|
|
32
|
+
) -> None:
|
|
33
|
+
"""
|
|
34
|
+
Initializes a runner as core function.
|
|
35
|
+
Args:
|
|
36
|
+
agent: The agent to run.
|
|
37
|
+
environment_manager: The environment manager
|
|
38
|
+
context_manager: The context manager
|
|
39
|
+
"""
|
|
40
|
+
self._agent = agent
|
|
41
|
+
self._environment_manager = environment_manager
|
|
42
|
+
self._context_manager = context_manager
|
|
43
|
+
self._deploy_managers = {}
|
|
44
|
+
|
|
45
|
+
# TODO: should be sync method?
|
|
46
|
+
async def deploy(
|
|
47
|
+
self,
|
|
48
|
+
deploy_manager: DeployManager = LocalDeployManager(),
|
|
49
|
+
endpoint_path: str = "/process",
|
|
50
|
+
stream: bool = True,
|
|
51
|
+
protocol_adapters: Optional[list[ProtocolAdapter]] = None,
|
|
52
|
+
):
|
|
53
|
+
"""
|
|
54
|
+
Deploys the agent as a service.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
protocol_adapters: protocol adapters
|
|
58
|
+
deploy_manager: Deployment manager to handle service deployment
|
|
59
|
+
endpoint_path: API endpoint path for the processing function
|
|
60
|
+
stream: If start a streaming service
|
|
61
|
+
Returns:
|
|
62
|
+
URL of the deployed service
|
|
63
|
+
|
|
64
|
+
Raises:
|
|
65
|
+
RuntimeError: If deployment fails
|
|
66
|
+
"""
|
|
67
|
+
if stream:
|
|
68
|
+
deploy_func = self.stream_query
|
|
69
|
+
else:
|
|
70
|
+
deploy_func = self.query
|
|
71
|
+
deploy_result = await deploy_manager.deploy(
|
|
72
|
+
deploy_func,
|
|
73
|
+
endpoint_path=endpoint_path,
|
|
74
|
+
protocol_adapters=protocol_adapters,
|
|
75
|
+
)
|
|
76
|
+
self._deploy_managers[deploy_manager.deploy_id] = deploy_result
|
|
77
|
+
return deploy_result
|
|
78
|
+
|
|
79
|
+
@trace(TraceType.AGENT_STEP)
|
|
80
|
+
async def stream_query( # pylint:disable=unused-argument
|
|
81
|
+
self,
|
|
82
|
+
request: AgentRequest,
|
|
83
|
+
user_id: Optional[str] = None,
|
|
84
|
+
tools: Optional[List] = None,
|
|
85
|
+
**kwargs: Any,
|
|
86
|
+
) -> AsyncGenerator[Event, None]:
|
|
87
|
+
"""
|
|
88
|
+
Streams the agent.
|
|
89
|
+
"""
|
|
90
|
+
response = AgentResponse()
|
|
91
|
+
yield response
|
|
92
|
+
|
|
93
|
+
response.in_progress()
|
|
94
|
+
yield response
|
|
95
|
+
|
|
96
|
+
user_id = user_id or str(uuid.uuid4())
|
|
97
|
+
session_id = request.session_id or str(uuid.uuid4())
|
|
98
|
+
request_input = request.input
|
|
99
|
+
session = await self._context_manager.compose_session(
|
|
100
|
+
user_id=user_id,
|
|
101
|
+
session_id=session_id,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
context = Context(
|
|
105
|
+
user_id=session.user_id,
|
|
106
|
+
session=session,
|
|
107
|
+
request=request,
|
|
108
|
+
current_messages=request_input,
|
|
109
|
+
context_manager=self._context_manager,
|
|
110
|
+
environment_manager=self._environment_manager,
|
|
111
|
+
agent=self._agent,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
# TODO: Update activate tools into the context (not schema only)
|
|
115
|
+
tools = tools or getattr(self._agent, "tools", None)
|
|
116
|
+
if tools:
|
|
117
|
+
# Lazy import
|
|
118
|
+
from ..sandbox.tools.utils import setup_tools
|
|
119
|
+
|
|
120
|
+
activated_tools, schemas = setup_tools(
|
|
121
|
+
tools=tools,
|
|
122
|
+
environment_manager=context.environment_manager,
|
|
123
|
+
session_id=session.id,
|
|
124
|
+
user_id=session.user_id,
|
|
125
|
+
include_schemas=True,
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
# update the context
|
|
129
|
+
context.activate_tools = activated_tools
|
|
130
|
+
|
|
131
|
+
# convert schema to a function call tool lists
|
|
132
|
+
# TODO: use pydantic model
|
|
133
|
+
if hasattr(context.request, "tools") and context.request.tools:
|
|
134
|
+
context.request.tools.extend(schemas)
|
|
135
|
+
|
|
136
|
+
# update message in session
|
|
137
|
+
await context.context_manager.compose_context(
|
|
138
|
+
session=context.session,
|
|
139
|
+
request_input=request_input,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
async for event in context.agent.run_async(context):
|
|
143
|
+
if (
|
|
144
|
+
event.status == RunStatus.Completed
|
|
145
|
+
and event.object == "message"
|
|
146
|
+
):
|
|
147
|
+
response.add_new_message(event)
|
|
148
|
+
yield event
|
|
149
|
+
|
|
150
|
+
await context.context_manager.append(
|
|
151
|
+
session=context.session,
|
|
152
|
+
event_output=response.output,
|
|
153
|
+
)
|
|
154
|
+
yield response.completed()
|
|
155
|
+
|
|
156
|
+
@trace(TraceType.AGENT_STEP)
|
|
157
|
+
async def query( # pylint:disable=unused-argument
|
|
158
|
+
self,
|
|
159
|
+
message: List[dict],
|
|
160
|
+
session_id: Optional[str] = None,
|
|
161
|
+
**kwargs: Any,
|
|
162
|
+
) -> ChatCompletion:
|
|
163
|
+
"""
|
|
164
|
+
Streams the agent.
|
|
165
|
+
"""
|
|
166
|
+
return self._agent.query(message, session_id)
|
|
167
|
+
|
|
168
|
+
# TODO: should be sync method?
|
|
169
|
+
async def stop(
|
|
170
|
+
self,
|
|
171
|
+
deploy_id: str,
|
|
172
|
+
) -> None:
|
|
173
|
+
"""
|
|
174
|
+
Stops the agent service.
|
|
175
|
+
|
|
176
|
+
Args:
|
|
177
|
+
deploy_id: Optional deploy ID (not used for service shutdown)
|
|
178
|
+
|
|
179
|
+
Raises:
|
|
180
|
+
RuntimeError: If stopping fails
|
|
181
|
+
"""
|
|
182
|
+
if hasattr(self, "_deploy_manager") and self._deploy_manager:
|
|
183
|
+
await self._deploy_manager[deploy_id].stop()
|
|
184
|
+
else:
|
|
185
|
+
# No deploy manager found, nothing to stop
|
|
186
|
+
pass
|
|
File without changes
|