agentscope-runtime 0.2.0b1__py3-none-any.whl → 1.0.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/adapters/__init__.py +0 -0
- agentscope_runtime/adapters/agentscope/__init__.py +0 -0
- agentscope_runtime/adapters/agentscope/long_term_memory/__init__.py +6 -0
- agentscope_runtime/adapters/agentscope/long_term_memory/_long_term_memory_adapter.py +258 -0
- agentscope_runtime/adapters/agentscope/memory/__init__.py +6 -0
- agentscope_runtime/adapters/agentscope/memory/_memory_adapter.py +152 -0
- agentscope_runtime/adapters/agentscope/message.py +535 -0
- agentscope_runtime/adapters/agentscope/stream.py +506 -0
- agentscope_runtime/adapters/agentscope/tool/__init__.py +9 -0
- agentscope_runtime/adapters/agentscope/tool/sandbox_tool.py +69 -0
- agentscope_runtime/adapters/agentscope/tool/tool.py +233 -0
- agentscope_runtime/adapters/autogen/__init__.py +0 -0
- agentscope_runtime/adapters/autogen/tool/__init__.py +7 -0
- agentscope_runtime/adapters/autogen/tool/tool.py +211 -0
- agentscope_runtime/adapters/text/__init__.py +0 -0
- agentscope_runtime/adapters/text/stream.py +29 -0
- agentscope_runtime/common/collections/redis_mapping.py +4 -1
- agentscope_runtime/common/container_clients/fc_client.py +855 -0
- agentscope_runtime/common/container_clients/kubernetes_client.py +6 -13
- agentscope_runtime/common/utils/__init__.py +0 -0
- agentscope_runtime/common/utils/lazy_loader.py +57 -0
- agentscope_runtime/engine/__init__.py +25 -18
- agentscope_runtime/engine/app/agent_app.py +161 -91
- agentscope_runtime/engine/app/base_app.py +4 -118
- agentscope_runtime/engine/constant.py +8 -0
- agentscope_runtime/engine/deployers/__init__.py +8 -0
- agentscope_runtime/engine/deployers/adapter/__init__.py +2 -0
- agentscope_runtime/engine/deployers/adapter/a2a/a2a_adapter_utils.py +0 -21
- agentscope_runtime/engine/deployers/adapter/a2a/a2a_protocol_adapter.py +28 -9
- agentscope_runtime/engine/deployers/adapter/responses/__init__.py +2 -0
- agentscope_runtime/engine/deployers/adapter/responses/response_api_adapter_utils.py +5 -2
- agentscope_runtime/engine/deployers/adapter/responses/response_api_protocol_adapter.py +1 -1
- agentscope_runtime/engine/deployers/agentrun_deployer.py +2541 -0
- agentscope_runtime/engine/deployers/cli_fc_deploy.py +1 -1
- agentscope_runtime/engine/deployers/kubernetes_deployer.py +9 -21
- agentscope_runtime/engine/deployers/local_deployer.py +47 -74
- agentscope_runtime/engine/deployers/modelstudio_deployer.py +216 -50
- agentscope_runtime/engine/deployers/utils/app_runner_utils.py +29 -0
- agentscope_runtime/engine/deployers/utils/detached_app.py +510 -0
- agentscope_runtime/engine/deployers/utils/docker_image_utils/__init__.py +1 -1
- agentscope_runtime/engine/deployers/utils/docker_image_utils/dockerfile_generator.py +1 -1
- agentscope_runtime/engine/deployers/utils/docker_image_utils/{runner_image_factory.py → image_factory.py} +121 -61
- agentscope_runtime/engine/deployers/utils/package.py +693 -0
- agentscope_runtime/engine/deployers/utils/service_utils/__init__.py +0 -5
- agentscope_runtime/engine/deployers/utils/service_utils/fastapi_factory.py +301 -282
- agentscope_runtime/engine/deployers/utils/service_utils/fastapi_templates.py +2 -4
- agentscope_runtime/engine/deployers/utils/service_utils/process_manager.py +23 -1
- agentscope_runtime/engine/deployers/utils/templates/app_main.py.j2 +84 -0
- agentscope_runtime/engine/deployers/utils/templates/runner_main.py.j2 +95 -0
- agentscope_runtime/engine/deployers/utils/{service_utils → templates}/standalone_main.py.j2 +0 -45
- agentscope_runtime/engine/deployers/utils/wheel_packager.py +119 -18
- agentscope_runtime/engine/helpers/runner.py +40 -0
- agentscope_runtime/engine/runner.py +171 -130
- agentscope_runtime/engine/schemas/agent_schemas.py +114 -3
- agentscope_runtime/engine/schemas/modelstudio_llm.py +4 -2
- agentscope_runtime/engine/schemas/oai_llm.py +23 -23
- agentscope_runtime/engine/schemas/response_api.py +65 -0
- agentscope_runtime/engine/schemas/session.py +24 -0
- agentscope_runtime/engine/services/__init__.py +0 -9
- agentscope_runtime/engine/services/agent_state/__init__.py +16 -0
- agentscope_runtime/engine/services/agent_state/redis_state_service.py +113 -0
- agentscope_runtime/engine/services/agent_state/state_service.py +179 -0
- agentscope_runtime/engine/services/memory/__init__.py +24 -0
- agentscope_runtime/engine/services/{mem0_memory_service.py → memory/mem0_memory_service.py} +17 -13
- agentscope_runtime/engine/services/{memory_service.py → memory/memory_service.py} +28 -7
- agentscope_runtime/engine/services/{redis_memory_service.py → memory/redis_memory_service.py} +1 -1
- agentscope_runtime/engine/services/{reme_personal_memory_service.py → memory/reme_personal_memory_service.py} +9 -6
- agentscope_runtime/engine/services/{reme_task_memory_service.py → memory/reme_task_memory_service.py} +2 -2
- agentscope_runtime/engine/services/{tablestore_memory_service.py → memory/tablestore_memory_service.py} +16 -19
- agentscope_runtime/engine/services/sandbox/__init__.py +13 -0
- agentscope_runtime/engine/services/{sandbox_service.py → sandbox/sandbox_service.py} +86 -71
- agentscope_runtime/engine/services/session_history/__init__.py +23 -0
- agentscope_runtime/engine/services/{redis_session_history_service.py → session_history/redis_session_history_service.py} +3 -2
- agentscope_runtime/engine/services/{session_history_service.py → session_history/session_history_service.py} +44 -34
- agentscope_runtime/engine/services/{tablestore_session_history_service.py → session_history/tablestore_session_history_service.py} +14 -19
- agentscope_runtime/engine/services/utils/tablestore_service_utils.py +2 -2
- agentscope_runtime/engine/tracing/base.py +10 -9
- agentscope_runtime/engine/tracing/message_util.py +1 -1
- agentscope_runtime/engine/tracing/tracing_util.py +7 -2
- agentscope_runtime/engine/tracing/wrapper.py +49 -31
- agentscope_runtime/sandbox/__init__.py +10 -2
- agentscope_runtime/sandbox/box/agentbay/__init__.py +4 -0
- agentscope_runtime/sandbox/box/agentbay/agentbay_sandbox.py +559 -0
- agentscope_runtime/sandbox/box/base/base_sandbox.py +12 -0
- agentscope_runtime/sandbox/box/browser/browser_sandbox.py +115 -11
- agentscope_runtime/sandbox/box/cloud/__init__.py +4 -0
- agentscope_runtime/sandbox/box/cloud/cloud_sandbox.py +254 -0
- agentscope_runtime/sandbox/box/filesystem/filesystem_sandbox.py +66 -0
- agentscope_runtime/sandbox/box/gui/gui_sandbox.py +42 -0
- agentscope_runtime/sandbox/box/mobile/__init__.py +4 -0
- agentscope_runtime/sandbox/box/mobile/box/__init__.py +0 -0
- agentscope_runtime/sandbox/box/mobile/mobile_sandbox.py +216 -0
- agentscope_runtime/sandbox/box/training_box/training_box.py +2 -44
- agentscope_runtime/sandbox/client/http_client.py +1 -0
- agentscope_runtime/sandbox/enums.py +2 -1
- agentscope_runtime/sandbox/manager/sandbox_manager.py +15 -2
- agentscope_runtime/sandbox/manager/server/app.py +12 -0
- agentscope_runtime/sandbox/manager/server/config.py +19 -0
- agentscope_runtime/sandbox/model/manager_config.py +79 -2
- agentscope_runtime/sandbox/utils.py +0 -18
- agentscope_runtime/tools/RAGs/__init__.py +0 -0
- agentscope_runtime/tools/RAGs/modelstudio_rag.py +377 -0
- agentscope_runtime/tools/RAGs/modelstudio_rag_lite.py +219 -0
- agentscope_runtime/tools/__init__.py +119 -0
- agentscope_runtime/tools/_constants.py +18 -0
- agentscope_runtime/tools/alipay/__init__.py +4 -0
- agentscope_runtime/tools/alipay/base.py +334 -0
- agentscope_runtime/tools/alipay/payment.py +835 -0
- agentscope_runtime/tools/alipay/subscribe.py +551 -0
- agentscope_runtime/tools/base.py +264 -0
- agentscope_runtime/tools/cli/__init__.py +0 -0
- agentscope_runtime/tools/cli/modelstudio_mcp_server.py +78 -0
- agentscope_runtime/tools/generations/__init__.py +75 -0
- agentscope_runtime/tools/generations/async_image_to_video.py +350 -0
- agentscope_runtime/tools/generations/async_image_to_video_wan25.py +366 -0
- agentscope_runtime/tools/generations/async_speech_to_video.py +422 -0
- agentscope_runtime/tools/generations/async_text_to_video.py +320 -0
- agentscope_runtime/tools/generations/async_text_to_video_wan25.py +334 -0
- agentscope_runtime/tools/generations/image_edit.py +208 -0
- agentscope_runtime/tools/generations/image_edit_wan25.py +193 -0
- agentscope_runtime/tools/generations/image_generation.py +202 -0
- agentscope_runtime/tools/generations/image_generation_wan25.py +201 -0
- agentscope_runtime/tools/generations/image_style_repaint.py +208 -0
- agentscope_runtime/tools/generations/image_to_video.py +233 -0
- agentscope_runtime/tools/generations/qwen_image_edit.py +205 -0
- agentscope_runtime/tools/generations/qwen_image_generation.py +214 -0
- agentscope_runtime/tools/generations/qwen_text_to_speech.py +154 -0
- agentscope_runtime/tools/generations/speech_to_text.py +260 -0
- agentscope_runtime/tools/generations/speech_to_video.py +314 -0
- agentscope_runtime/tools/generations/text_to_video.py +221 -0
- agentscope_runtime/tools/mcp_wrapper.py +215 -0
- agentscope_runtime/tools/realtime_clients/__init__.py +13 -0
- agentscope_runtime/tools/realtime_clients/asr_client.py +27 -0
- agentscope_runtime/tools/realtime_clients/azure_asr_client.py +195 -0
- agentscope_runtime/tools/realtime_clients/azure_tts_client.py +383 -0
- agentscope_runtime/tools/realtime_clients/modelstudio_asr_client.py +151 -0
- agentscope_runtime/tools/realtime_clients/modelstudio_tts_client.py +199 -0
- agentscope_runtime/tools/realtime_clients/realtime_tool.py +55 -0
- agentscope_runtime/tools/realtime_clients/tts_client.py +33 -0
- agentscope_runtime/tools/searches/__init__.py +3 -0
- agentscope_runtime/tools/searches/modelstudio_search.py +877 -0
- agentscope_runtime/tools/searches/modelstudio_search_lite.py +310 -0
- agentscope_runtime/tools/utils/__init__.py +0 -0
- agentscope_runtime/tools/utils/api_key_util.py +45 -0
- agentscope_runtime/tools/utils/crypto_utils.py +99 -0
- agentscope_runtime/tools/utils/mcp_util.py +35 -0
- agentscope_runtime/version.py +1 -1
- {agentscope_runtime-0.2.0b1.dist-info → agentscope_runtime-1.0.0.dist-info}/METADATA +244 -168
- agentscope_runtime-1.0.0.dist-info/RECORD +240 -0
- {agentscope_runtime-0.2.0b1.dist-info → agentscope_runtime-1.0.0.dist-info}/entry_points.txt +1 -0
- agentscope_runtime/engine/agents/__init__.py +0 -2
- agentscope_runtime/engine/agents/agentscope_agent.py +0 -488
- agentscope_runtime/engine/agents/agno_agent.py +0 -222
- agentscope_runtime/engine/agents/autogen_agent.py +0 -250
- agentscope_runtime/engine/agents/base_agent.py +0 -29
- agentscope_runtime/engine/agents/langgraph_agent.py +0 -59
- agentscope_runtime/engine/agents/utils.py +0 -53
- agentscope_runtime/engine/deployers/utils/package_project_utils.py +0 -1163
- agentscope_runtime/engine/deployers/utils/service_utils/service_config.py +0 -75
- agentscope_runtime/engine/deployers/utils/service_utils/service_factory.py +0 -220
- agentscope_runtime/engine/helpers/helper.py +0 -179
- agentscope_runtime/engine/schemas/context.py +0 -54
- agentscope_runtime/engine/services/context_manager.py +0 -164
- agentscope_runtime/engine/services/environment_manager.py +0 -50
- agentscope_runtime/engine/services/manager.py +0 -174
- agentscope_runtime/engine/services/rag_service.py +0 -195
- agentscope_runtime/engine/services/tablestore_rag_service.py +0 -143
- agentscope_runtime/sandbox/tools/__init__.py +0 -12
- agentscope_runtime/sandbox/tools/base/__init__.py +0 -8
- agentscope_runtime/sandbox/tools/base/tool.py +0 -52
- agentscope_runtime/sandbox/tools/browser/__init__.py +0 -57
- agentscope_runtime/sandbox/tools/browser/tool.py +0 -597
- agentscope_runtime/sandbox/tools/filesystem/__init__.py +0 -32
- agentscope_runtime/sandbox/tools/filesystem/tool.py +0 -319
- agentscope_runtime/sandbox/tools/function_tool.py +0 -321
- agentscope_runtime/sandbox/tools/gui/__init__.py +0 -7
- agentscope_runtime/sandbox/tools/gui/tool.py +0 -77
- agentscope_runtime/sandbox/tools/mcp_tool.py +0 -195
- agentscope_runtime/sandbox/tools/sandbox_tool.py +0 -104
- agentscope_runtime/sandbox/tools/tool.py +0 -238
- agentscope_runtime/sandbox/tools/utils.py +0 -68
- agentscope_runtime-0.2.0b1.dist-info/RECORD +0 -183
- {agentscope_runtime-0.2.0b1.dist-info → agentscope_runtime-1.0.0.dist-info}/WHEEL +0 -0
- {agentscope_runtime-0.2.0b1.dist-info → agentscope_runtime-1.0.0.dist-info}/licenses/LICENSE +0 -0
- {agentscope_runtime-0.2.0b1.dist-info → agentscope_runtime-1.0.0.dist-info}/top_level.txt +0 -0
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
from typing import Optional, Type
|
|
3
|
-
|
|
4
|
-
from autogen_core.models import ChatCompletionClient
|
|
5
|
-
from autogen_core.tools import FunctionTool
|
|
6
|
-
from autogen_agentchat.agents import AssistantAgent
|
|
7
|
-
from autogen_agentchat.messages import (
|
|
8
|
-
TextMessage,
|
|
9
|
-
ToolCallExecutionEvent,
|
|
10
|
-
ToolCallRequestEvent,
|
|
11
|
-
ModelClientStreamingChunkEvent,
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
from .utils import build_agent
|
|
15
|
-
from ..agents import Agent
|
|
16
|
-
from ..schemas.context import Context
|
|
17
|
-
from ..schemas.agent_schemas import (
|
|
18
|
-
Message,
|
|
19
|
-
TextContent,
|
|
20
|
-
DataContent,
|
|
21
|
-
FunctionCall,
|
|
22
|
-
FunctionCallOutput,
|
|
23
|
-
MessageType,
|
|
24
|
-
RunStatus,
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class AutogenContextAdapter:
|
|
29
|
-
def __init__(self, context: Context, attr: dict):
|
|
30
|
-
self.context = context
|
|
31
|
-
self.attr = attr
|
|
32
|
-
|
|
33
|
-
# Adapted attribute
|
|
34
|
-
self.toolkit = None
|
|
35
|
-
self.model = None
|
|
36
|
-
self.memory = None
|
|
37
|
-
self.new_message = None
|
|
38
|
-
|
|
39
|
-
async def initialize(self):
|
|
40
|
-
self.model = await self.adapt_model()
|
|
41
|
-
self.memory = await self.adapt_memory()
|
|
42
|
-
self.new_message = await self.adapt_new_message()
|
|
43
|
-
self.toolkit = await self.adapt_tools()
|
|
44
|
-
|
|
45
|
-
async def adapt_memory(self):
|
|
46
|
-
messages = []
|
|
47
|
-
|
|
48
|
-
# Build context
|
|
49
|
-
for msg in self.context.session.messages[:-1]: # Exclude the last one
|
|
50
|
-
messages.append(AutogenContextAdapter.converter(msg))
|
|
51
|
-
|
|
52
|
-
return messages
|
|
53
|
-
|
|
54
|
-
@staticmethod
|
|
55
|
-
def converter(message: Message):
|
|
56
|
-
# TODO: support more message type
|
|
57
|
-
return TextMessage.load(
|
|
58
|
-
{
|
|
59
|
-
"id": message.id,
|
|
60
|
-
"source": message.role,
|
|
61
|
-
"content": message.content[0].text if message.content else "",
|
|
62
|
-
},
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
async def adapt_new_message(self):
|
|
66
|
-
last_message = self.context.session.messages[-1]
|
|
67
|
-
|
|
68
|
-
return AutogenContextAdapter.converter(last_message)
|
|
69
|
-
|
|
70
|
-
async def adapt_model(self):
|
|
71
|
-
return self.attr["model"]
|
|
72
|
-
|
|
73
|
-
async def adapt_tools(self):
|
|
74
|
-
toolkit = self.attr["agent_config"].get("toolkit", [])
|
|
75
|
-
tools = self.attr["tools"]
|
|
76
|
-
|
|
77
|
-
# in case, tools is None and tools == []
|
|
78
|
-
if not tools:
|
|
79
|
-
return toolkit
|
|
80
|
-
|
|
81
|
-
if self.context.activate_tools:
|
|
82
|
-
# Only add activated tool
|
|
83
|
-
activated_tools = self.context.activate_tools
|
|
84
|
-
else:
|
|
85
|
-
from ...sandbox.tools.utils import setup_tools
|
|
86
|
-
|
|
87
|
-
activated_tools = setup_tools(
|
|
88
|
-
tools=self.attr["tools"],
|
|
89
|
-
environment_manager=self.context.environment_manager,
|
|
90
|
-
session_id=self.context.session.id,
|
|
91
|
-
user_id=self.context.session.user_id,
|
|
92
|
-
include_schemas=False,
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
for tool in activated_tools:
|
|
96
|
-
func = FunctionTool(
|
|
97
|
-
func=tool.make_function(),
|
|
98
|
-
description=tool.schema["function"]["description"],
|
|
99
|
-
name=tool.name,
|
|
100
|
-
)
|
|
101
|
-
toolkit.append(func)
|
|
102
|
-
|
|
103
|
-
return toolkit
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
class AutogenAgent(Agent):
|
|
107
|
-
def __init__(
|
|
108
|
-
self,
|
|
109
|
-
name: str,
|
|
110
|
-
model: ChatCompletionClient,
|
|
111
|
-
tools=None,
|
|
112
|
-
agent_config=None,
|
|
113
|
-
agent_builder: Optional[Type[AssistantAgent]] = AssistantAgent,
|
|
114
|
-
):
|
|
115
|
-
super().__init__(name=name, agent_config=agent_config)
|
|
116
|
-
|
|
117
|
-
assert isinstance(
|
|
118
|
-
model,
|
|
119
|
-
ChatCompletionClient,
|
|
120
|
-
), "model must be a subclass of ChatCompletionClient in autogen"
|
|
121
|
-
|
|
122
|
-
# Set default agent_builder
|
|
123
|
-
if agent_builder is None:
|
|
124
|
-
agent_builder = AssistantAgent
|
|
125
|
-
|
|
126
|
-
assert issubclass(
|
|
127
|
-
agent_builder,
|
|
128
|
-
AssistantAgent,
|
|
129
|
-
), "agent_builder must be a subclass of AssistantAgent in autogen"
|
|
130
|
-
|
|
131
|
-
# Replace name if not exists
|
|
132
|
-
self.agent_config["name"] = self.agent_config.get("name") or name
|
|
133
|
-
|
|
134
|
-
self._attr = {
|
|
135
|
-
"model": model,
|
|
136
|
-
"tools": tools,
|
|
137
|
-
"agent_config": self.agent_config,
|
|
138
|
-
"agent_builder": agent_builder,
|
|
139
|
-
}
|
|
140
|
-
self.tools = tools
|
|
141
|
-
|
|
142
|
-
def copy(self) -> "AutogenAgent":
|
|
143
|
-
return AutogenAgent(**self._attr)
|
|
144
|
-
|
|
145
|
-
def build(self, as_context):
|
|
146
|
-
params = {
|
|
147
|
-
**self._attr["agent_config"],
|
|
148
|
-
**{
|
|
149
|
-
"model_client": as_context.model,
|
|
150
|
-
"tools": as_context.toolkit,
|
|
151
|
-
}, # Context will be added at `_agent.run_stream`
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
builder_cls = self._attr["agent_builder"]
|
|
155
|
-
_agent = build_agent(builder_cls, params)
|
|
156
|
-
|
|
157
|
-
return _agent
|
|
158
|
-
|
|
159
|
-
async def run(self, context):
|
|
160
|
-
ag_context = AutogenContextAdapter(context=context, attr=self._attr)
|
|
161
|
-
await ag_context.initialize()
|
|
162
|
-
|
|
163
|
-
# We should always build a new agent since the state is manage outside
|
|
164
|
-
# the agent
|
|
165
|
-
_agent = self.build(ag_context)
|
|
166
|
-
|
|
167
|
-
resp = _agent.run_stream(
|
|
168
|
-
task=ag_context.memory + [ag_context.new_message],
|
|
169
|
-
)
|
|
170
|
-
|
|
171
|
-
text_message = Message(
|
|
172
|
-
type=MessageType.MESSAGE,
|
|
173
|
-
role="assistant",
|
|
174
|
-
status=RunStatus.InProgress,
|
|
175
|
-
)
|
|
176
|
-
yield text_message
|
|
177
|
-
|
|
178
|
-
text_delta_content = TextContent(delta=True)
|
|
179
|
-
is_text_delta = False
|
|
180
|
-
stream_mode = False
|
|
181
|
-
async for event in resp:
|
|
182
|
-
if getattr(event, "source", "user") == "user":
|
|
183
|
-
continue
|
|
184
|
-
|
|
185
|
-
if isinstance(event, TextMessage):
|
|
186
|
-
if stream_mode:
|
|
187
|
-
continue
|
|
188
|
-
is_text_delta = True
|
|
189
|
-
text_delta_content.text = event.content
|
|
190
|
-
text_delta_content = text_message.add_delta_content(
|
|
191
|
-
new_content=text_delta_content,
|
|
192
|
-
)
|
|
193
|
-
yield text_delta_content
|
|
194
|
-
elif isinstance(event, ModelClientStreamingChunkEvent):
|
|
195
|
-
stream_mode = True
|
|
196
|
-
is_text_delta = True
|
|
197
|
-
text_delta_content.text = event.content
|
|
198
|
-
text_delta_content = text_message.add_delta_content(
|
|
199
|
-
new_content=text_delta_content,
|
|
200
|
-
)
|
|
201
|
-
yield text_delta_content
|
|
202
|
-
elif isinstance(event, ToolCallRequestEvent):
|
|
203
|
-
data = DataContent(
|
|
204
|
-
data=FunctionCall(
|
|
205
|
-
call_id=event.id,
|
|
206
|
-
name=event.content[0].name,
|
|
207
|
-
arguments=event.content[0].arguments,
|
|
208
|
-
).model_dump(),
|
|
209
|
-
)
|
|
210
|
-
message = Message(
|
|
211
|
-
type=MessageType.PLUGIN_CALL,
|
|
212
|
-
role="assistant",
|
|
213
|
-
status=RunStatus.Completed,
|
|
214
|
-
content=[data],
|
|
215
|
-
)
|
|
216
|
-
yield message
|
|
217
|
-
elif isinstance(event, ToolCallExecutionEvent):
|
|
218
|
-
data = DataContent(
|
|
219
|
-
data=FunctionCallOutput(
|
|
220
|
-
call_id=event.id,
|
|
221
|
-
output=event.content[0].content,
|
|
222
|
-
).model_dump(),
|
|
223
|
-
)
|
|
224
|
-
message = Message(
|
|
225
|
-
type=MessageType.PLUGIN_CALL_OUTPUT,
|
|
226
|
-
role="assistant",
|
|
227
|
-
status=RunStatus.Completed,
|
|
228
|
-
content=[data],
|
|
229
|
-
)
|
|
230
|
-
yield message
|
|
231
|
-
|
|
232
|
-
# Add to message
|
|
233
|
-
is_text_delta = True
|
|
234
|
-
text_delta_content.text = event.content[0].content
|
|
235
|
-
text_delta_content = text_message.add_delta_content(
|
|
236
|
-
new_content=text_delta_content,
|
|
237
|
-
)
|
|
238
|
-
yield text_delta_content
|
|
239
|
-
|
|
240
|
-
if is_text_delta:
|
|
241
|
-
yield text_message.content_completed(text_delta_content.index)
|
|
242
|
-
yield text_message.completed()
|
|
243
|
-
|
|
244
|
-
async def run_async(
|
|
245
|
-
self,
|
|
246
|
-
context,
|
|
247
|
-
**kwargs,
|
|
248
|
-
):
|
|
249
|
-
async for event in self.run(context):
|
|
250
|
-
yield event
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
from typing import AsyncGenerator
|
|
3
|
-
|
|
4
|
-
from ..schemas.agent_schemas import Event
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class Agent:
|
|
8
|
-
def __init__(
|
|
9
|
-
self,
|
|
10
|
-
name: str = "",
|
|
11
|
-
description: str = "",
|
|
12
|
-
before_agent_callback=None,
|
|
13
|
-
after_agent_callback=None,
|
|
14
|
-
agent_config=None,
|
|
15
|
-
**kwargs,
|
|
16
|
-
):
|
|
17
|
-
self.name = name
|
|
18
|
-
self.description = description
|
|
19
|
-
self.before_agent_callback = before_agent_callback or []
|
|
20
|
-
self.after_agent_callback = after_agent_callback or []
|
|
21
|
-
self.agent_config = agent_config or {}
|
|
22
|
-
self.kwargs = kwargs
|
|
23
|
-
|
|
24
|
-
async def run_async(
|
|
25
|
-
self,
|
|
26
|
-
context,
|
|
27
|
-
**kwargs,
|
|
28
|
-
) -> AsyncGenerator[Event, None]:
|
|
29
|
-
raise NotImplementedError("Subclasses must implement this method")
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
import json
|
|
3
|
-
|
|
4
|
-
from langgraph.graph.state import CompiledStateGraph
|
|
5
|
-
|
|
6
|
-
from .base_agent import Agent
|
|
7
|
-
from ..schemas.agent_schemas import (
|
|
8
|
-
Message,
|
|
9
|
-
TextContent,
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def _state_folder(messages):
|
|
14
|
-
if len(messages) > 0:
|
|
15
|
-
return json.loads(messages[0]["content"])
|
|
16
|
-
else:
|
|
17
|
-
return []
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def _state_unfolder(state):
|
|
21
|
-
state_jsons = json.dumps(state)
|
|
22
|
-
return state_jsons
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class LangGraphAgent(Agent):
|
|
26
|
-
def __init__(
|
|
27
|
-
self,
|
|
28
|
-
graph: CompiledStateGraph = None,
|
|
29
|
-
state_folder=_state_folder,
|
|
30
|
-
state_unfolder=_state_unfolder,
|
|
31
|
-
**kwargs,
|
|
32
|
-
):
|
|
33
|
-
super().__init__(**kwargs)
|
|
34
|
-
self.state_folder = state_folder
|
|
35
|
-
self.state_unfolder = state_unfolder
|
|
36
|
-
self.graph = graph
|
|
37
|
-
|
|
38
|
-
async def run_async(
|
|
39
|
-
self,
|
|
40
|
-
context,
|
|
41
|
-
**kwargs,
|
|
42
|
-
):
|
|
43
|
-
# fold the last m
|
|
44
|
-
list_messages = []
|
|
45
|
-
for m in context.session.messages:
|
|
46
|
-
dumped = m.model_dump()
|
|
47
|
-
dumped["content"] = dumped["content"][0]["text"]
|
|
48
|
-
list_messages.append(dumped)
|
|
49
|
-
|
|
50
|
-
_input = self.state_folder(list_messages)
|
|
51
|
-
|
|
52
|
-
output = await self.graph.ainvoke(_input)
|
|
53
|
-
content = self.state_unfolder(output)
|
|
54
|
-
|
|
55
|
-
message = Message(role="assistant")
|
|
56
|
-
text = TextContent(type="text", text=content)
|
|
57
|
-
message.add_content(text)
|
|
58
|
-
message.completed()
|
|
59
|
-
yield message
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
import inspect
|
|
3
|
-
import logging
|
|
4
|
-
|
|
5
|
-
logger = logging.getLogger(__name__)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def build_agent(builder_cls, params):
|
|
9
|
-
"""
|
|
10
|
-
Filters out unsupported parameters based on the __init__ signature of
|
|
11
|
-
builder_cls
|
|
12
|
-
and instantiates the class.
|
|
13
|
-
|
|
14
|
-
Args:
|
|
15
|
-
builder_cls (type): The class to instantiate.
|
|
16
|
-
params (dict): Dictionary of parameters to pass to the constructor.
|
|
17
|
-
|
|
18
|
-
Returns:
|
|
19
|
-
object: An instance of builder_cls.
|
|
20
|
-
"""
|
|
21
|
-
try:
|
|
22
|
-
# Get the signature of the __init__ method
|
|
23
|
-
sig = inspect.signature(builder_cls.__init__)
|
|
24
|
-
allowed_params = set(sig.parameters.keys())
|
|
25
|
-
# Remove 'self' from the list of allowed parameters
|
|
26
|
-
allowed_params.discard("self")
|
|
27
|
-
except (TypeError, ValueError):
|
|
28
|
-
# If signature cannot be inspected, allow all given params
|
|
29
|
-
allowed_params = set(params.keys())
|
|
30
|
-
|
|
31
|
-
filtered_params = {} # Parameters that are accepted by the constructor
|
|
32
|
-
unsupported = [] # Parameters that are not accepted
|
|
33
|
-
|
|
34
|
-
# Separate supported and unsupported parameters
|
|
35
|
-
for k, v in params.items():
|
|
36
|
-
if k in allowed_params:
|
|
37
|
-
filtered_params[k] = v
|
|
38
|
-
else:
|
|
39
|
-
unsupported.append(f"{k}={v!r}")
|
|
40
|
-
|
|
41
|
-
# Log a warning if there are unsupported parameters
|
|
42
|
-
if unsupported:
|
|
43
|
-
unsupported_str = ", ".join(unsupported)
|
|
44
|
-
logger.warning(
|
|
45
|
-
f"The following parameters are not supported by "
|
|
46
|
-
f"{builder_cls.__name__} and have been ignored: "
|
|
47
|
-
f"{unsupported_str}. If you require these parameters, "
|
|
48
|
-
f"please update the `__init__` method of "
|
|
49
|
-
f"{builder_cls.__name__} to accept and handle them.",
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
# Instantiate the class with only supported parameters
|
|
53
|
-
return builder_cls(**filtered_params)
|