agentscope-runtime 0.2.0b2__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/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} +12 -18
- 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 -2
- agentscope_runtime/sandbox/client/http_client.py +1 -0
- agentscope_runtime/sandbox/enums.py +2 -0
- 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.0b2.dist-info → agentscope_runtime-1.0.0.dist-info}/METADATA +240 -168
- agentscope_runtime-1.0.0.dist-info/RECORD +240 -0
- {agentscope_runtime-0.2.0b2.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 -220
- 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.0b2.dist-info/RECORD +0 -183
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0.dist-info}/WHEEL +0 -0
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0.dist-info}/licenses/LICENSE +0 -0
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0.dist-info}/top_level.txt +0 -0
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""Service configuration models for dynamic service loading."""
|
|
3
|
-
|
|
4
|
-
from enum import Enum
|
|
5
|
-
from typing import Dict, Any, Optional
|
|
6
|
-
|
|
7
|
-
from pydantic import BaseModel
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class ServiceType(str, Enum):
|
|
11
|
-
"""Types of services that can be configured."""
|
|
12
|
-
|
|
13
|
-
MEMORY = "memory"
|
|
14
|
-
SESSION_HISTORY = "session_history"
|
|
15
|
-
SANDBOX = "sandbox"
|
|
16
|
-
RAG = "rag"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class ServiceProvider(str, Enum):
|
|
20
|
-
"""Service implementation providers."""
|
|
21
|
-
|
|
22
|
-
IN_MEMORY = "in_memory"
|
|
23
|
-
REDIS = "redis"
|
|
24
|
-
# Extensible for other providers
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
class ServiceConfig(BaseModel):
|
|
28
|
-
"""Configuration for a single service."""
|
|
29
|
-
|
|
30
|
-
provider: ServiceProvider
|
|
31
|
-
config: Optional[Dict[str, Any]] = {}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
class ServicesConfig(BaseModel):
|
|
35
|
-
"""Configuration for all services."""
|
|
36
|
-
|
|
37
|
-
memory: ServiceConfig = ServiceConfig(provider=ServiceProvider.IN_MEMORY)
|
|
38
|
-
session_history: ServiceConfig = ServiceConfig(
|
|
39
|
-
provider=ServiceProvider.IN_MEMORY,
|
|
40
|
-
)
|
|
41
|
-
sandbox: Optional[ServiceConfig] = None
|
|
42
|
-
rag: Optional[ServiceConfig] = None
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
# Default configuration
|
|
46
|
-
DEFAULT_SERVICES_CONFIG = ServicesConfig()
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
def create_redis_services_config(
|
|
50
|
-
host: str = "localhost",
|
|
51
|
-
port: int = 6379,
|
|
52
|
-
memory_db: int = 0,
|
|
53
|
-
session_db: int = 1,
|
|
54
|
-
) -> ServicesConfig:
|
|
55
|
-
"""Create a ServicesConfig with Redis providers.
|
|
56
|
-
|
|
57
|
-
Args:
|
|
58
|
-
host: Redis host
|
|
59
|
-
port: Redis port
|
|
60
|
-
memory_db: Redis database for memory service
|
|
61
|
-
session_db: Redis database for session history service
|
|
62
|
-
|
|
63
|
-
Returns:
|
|
64
|
-
ServicesConfig: Configuration with Redis services
|
|
65
|
-
"""
|
|
66
|
-
return ServicesConfig(
|
|
67
|
-
memory=ServiceConfig(
|
|
68
|
-
provider=ServiceProvider.REDIS,
|
|
69
|
-
config={"host": host, "port": port, "db": memory_db},
|
|
70
|
-
),
|
|
71
|
-
session_history=ServiceConfig(
|
|
72
|
-
provider=ServiceProvider.REDIS,
|
|
73
|
-
config={"host": host, "port": port, "db": session_db},
|
|
74
|
-
),
|
|
75
|
-
)
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# pylint:disable=line-too-long
|
|
3
|
-
|
|
4
|
-
from typing import Dict, Type, Any
|
|
5
|
-
from .service_config import (
|
|
6
|
-
ServiceType,
|
|
7
|
-
ServiceProvider,
|
|
8
|
-
ServiceConfig,
|
|
9
|
-
ServicesConfig,
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class ServiceFactory:
|
|
14
|
-
"""Factory for creating service instances based on configuration."""
|
|
15
|
-
|
|
16
|
-
# Service registry mapping service types and providers to
|
|
17
|
-
# implementation classes
|
|
18
|
-
_service_registry: Dict[str, Dict[str, Type]] = {}
|
|
19
|
-
|
|
20
|
-
@classmethod
|
|
21
|
-
def _populate_registry(cls):
|
|
22
|
-
"""Populate the service registry with available implementations."""
|
|
23
|
-
if cls._service_registry:
|
|
24
|
-
return # Already populated
|
|
25
|
-
|
|
26
|
-
try:
|
|
27
|
-
# Import service implementations
|
|
28
|
-
from agentscope_runtime.engine.services.memory_service import (
|
|
29
|
-
InMemoryMemoryService,
|
|
30
|
-
)
|
|
31
|
-
from agentscope_runtime.engine.services.session_history_service import ( # noqa E501
|
|
32
|
-
InMemorySessionHistoryService,
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
# Register memory services
|
|
36
|
-
cls._service_registry[ServiceType.MEMORY] = {
|
|
37
|
-
ServiceProvider.IN_MEMORY: InMemoryMemoryService,
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
# Register session history services
|
|
41
|
-
cls._service_registry[ServiceType.SESSION_HISTORY] = {
|
|
42
|
-
ServiceProvider.IN_MEMORY: InMemorySessionHistoryService,
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
# Try to register Redis services if available
|
|
46
|
-
|
|
47
|
-
from agentscope_runtime.engine.services.redis_memory_service import ( # noqa E501
|
|
48
|
-
RedisMemoryService,
|
|
49
|
-
)
|
|
50
|
-
from agentscope_runtime.engine.services.redis_session_history_service import ( # noqa E501
|
|
51
|
-
RedisSessionHistoryService,
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
cls._service_registry[ServiceType.MEMORY][
|
|
55
|
-
ServiceProvider.REDIS
|
|
56
|
-
] = RedisMemoryService
|
|
57
|
-
cls._service_registry[ServiceType.SESSION_HISTORY][
|
|
58
|
-
ServiceProvider.REDIS
|
|
59
|
-
] = RedisSessionHistoryService
|
|
60
|
-
|
|
61
|
-
# Try to register other services if available
|
|
62
|
-
from agentscope_runtime.engine.services.sandbox_service import (
|
|
63
|
-
SandboxService,
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
# Assuming default implementation
|
|
67
|
-
cls._service_registry[ServiceType.SANDBOX] = {
|
|
68
|
-
ServiceProvider.IN_MEMORY: SandboxService,
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
from agentscope_runtime.engine.services.rag_service import (
|
|
72
|
-
RAGService,
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
# Assuming default implementation
|
|
76
|
-
cls._service_registry[ServiceType.RAG] = {
|
|
77
|
-
ServiceProvider.IN_MEMORY: RAGService,
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
except ImportError as e:
|
|
81
|
-
raise RuntimeError(
|
|
82
|
-
f"Failed to import required service classes: {e}",
|
|
83
|
-
) from e
|
|
84
|
-
|
|
85
|
-
@classmethod
|
|
86
|
-
def create_service(
|
|
87
|
-
cls,
|
|
88
|
-
service_type: ServiceType,
|
|
89
|
-
config: ServiceConfig,
|
|
90
|
-
) -> Any:
|
|
91
|
-
"""Create a service instance based on type and configuration.
|
|
92
|
-
|
|
93
|
-
Args:
|
|
94
|
-
service_type: Type of service to create
|
|
95
|
-
config: Configuration for the service
|
|
96
|
-
|
|
97
|
-
Returns:
|
|
98
|
-
Service instance
|
|
99
|
-
|
|
100
|
-
Raises:
|
|
101
|
-
ValueError: If service type or provider is unknown
|
|
102
|
-
RuntimeError: If service creation fails
|
|
103
|
-
"""
|
|
104
|
-
cls._populate_registry()
|
|
105
|
-
|
|
106
|
-
if service_type not in cls._service_registry:
|
|
107
|
-
raise ValueError(f"Unknown service type: {service_type}")
|
|
108
|
-
|
|
109
|
-
providers = cls._service_registry[service_type]
|
|
110
|
-
if config.provider not in providers:
|
|
111
|
-
available_providers = list(providers.keys())
|
|
112
|
-
raise ValueError(
|
|
113
|
-
f"Unknown provider '{config.provider}' for service '"
|
|
114
|
-
f"{service_type}'. Available providers: {available_providers}",
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
service_class = providers[config.provider]
|
|
118
|
-
|
|
119
|
-
try:
|
|
120
|
-
# Create service instance with configuration parameters
|
|
121
|
-
return service_class(**config.config)
|
|
122
|
-
except Exception as e:
|
|
123
|
-
raise RuntimeError(
|
|
124
|
-
f"Failed to create {service_type} service with provider "
|
|
125
|
-
f"'{config.provider}': {e}",
|
|
126
|
-
) from e
|
|
127
|
-
|
|
128
|
-
@classmethod
|
|
129
|
-
def register_service(
|
|
130
|
-
cls,
|
|
131
|
-
service_type: ServiceType,
|
|
132
|
-
provider: ServiceProvider,
|
|
133
|
-
service_class: Type,
|
|
134
|
-
):
|
|
135
|
-
"""Register a new service implementation.
|
|
136
|
-
|
|
137
|
-
Args:
|
|
138
|
-
service_type: Type of service
|
|
139
|
-
provider: Service provider
|
|
140
|
-
service_class: Implementation class
|
|
141
|
-
"""
|
|
142
|
-
cls._populate_registry()
|
|
143
|
-
|
|
144
|
-
if service_type not in cls._service_registry:
|
|
145
|
-
cls._service_registry[service_type] = {}
|
|
146
|
-
|
|
147
|
-
cls._service_registry[service_type][provider] = service_class
|
|
148
|
-
|
|
149
|
-
@classmethod
|
|
150
|
-
def create_services_from_config(
|
|
151
|
-
cls,
|
|
152
|
-
config: ServicesConfig,
|
|
153
|
-
) -> Dict[str, Any]:
|
|
154
|
-
"""Create all services from a services configuration.
|
|
155
|
-
|
|
156
|
-
Args:
|
|
157
|
-
config: Services configuration
|
|
158
|
-
|
|
159
|
-
Returns:
|
|
160
|
-
Dict mapping service names to service instances
|
|
161
|
-
|
|
162
|
-
Raises:
|
|
163
|
-
RuntimeError: If any required service creation fails
|
|
164
|
-
"""
|
|
165
|
-
services = {}
|
|
166
|
-
|
|
167
|
-
# Create required services
|
|
168
|
-
try:
|
|
169
|
-
services["memory"] = cls.create_service(
|
|
170
|
-
ServiceType.MEMORY,
|
|
171
|
-
config.memory,
|
|
172
|
-
)
|
|
173
|
-
services["session_history"] = cls.create_service(
|
|
174
|
-
ServiceType.SESSION_HISTORY,
|
|
175
|
-
config.session_history,
|
|
176
|
-
)
|
|
177
|
-
except Exception as e:
|
|
178
|
-
raise RuntimeError(
|
|
179
|
-
f"Failed to create required services: {e}",
|
|
180
|
-
) from e
|
|
181
|
-
|
|
182
|
-
# Create optional services
|
|
183
|
-
if config.sandbox:
|
|
184
|
-
try:
|
|
185
|
-
services["sandbox"] = cls.create_service(
|
|
186
|
-
ServiceType.SANDBOX,
|
|
187
|
-
config.sandbox,
|
|
188
|
-
)
|
|
189
|
-
except Exception as e:
|
|
190
|
-
# Log warning but don't fail
|
|
191
|
-
print(f"Warning: Failed to create sandbox service: {e}")
|
|
192
|
-
|
|
193
|
-
if config.rag:
|
|
194
|
-
try:
|
|
195
|
-
services["rag"] = cls.create_service(
|
|
196
|
-
ServiceType.RAG,
|
|
197
|
-
config.rag,
|
|
198
|
-
)
|
|
199
|
-
except Exception as e:
|
|
200
|
-
# Log warning but don't fail
|
|
201
|
-
print(f"Warning: Failed to create RAG service: {e}")
|
|
202
|
-
|
|
203
|
-
return services
|
|
204
|
-
|
|
205
|
-
@classmethod
|
|
206
|
-
def get_available_providers(cls, service_type: ServiceType) -> list:
|
|
207
|
-
"""Get list of available providers for a service type.
|
|
208
|
-
|
|
209
|
-
Args:
|
|
210
|
-
service_type: Type of service
|
|
211
|
-
|
|
212
|
-
Returns:
|
|
213
|
-
List of available provider names
|
|
214
|
-
"""
|
|
215
|
-
cls._populate_registry()
|
|
216
|
-
|
|
217
|
-
if service_type not in cls._service_registry:
|
|
218
|
-
return []
|
|
219
|
-
|
|
220
|
-
return list(cls._service_registry[service_type].keys())
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
import logging
|
|
3
|
-
|
|
4
|
-
from agentscope_runtime.engine import Runner
|
|
5
|
-
from agentscope_runtime.engine.schemas.agent_schemas import (
|
|
6
|
-
AgentRequest,
|
|
7
|
-
MessageType,
|
|
8
|
-
RunStatus,
|
|
9
|
-
)
|
|
10
|
-
from agentscope_runtime.engine.services.context_manager import (
|
|
11
|
-
create_context_manager,
|
|
12
|
-
)
|
|
13
|
-
from agentscope_runtime.engine.services.environment_manager import (
|
|
14
|
-
create_environment_manager,
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
logger = logging.getLogger(__name__)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
async def simple_call_agent(query, runner, user_id=None, session_id=None):
|
|
21
|
-
if isinstance(query, str):
|
|
22
|
-
request = AgentRequest(
|
|
23
|
-
input=[
|
|
24
|
-
{
|
|
25
|
-
"role": "user",
|
|
26
|
-
"content": [
|
|
27
|
-
{
|
|
28
|
-
"type": "text",
|
|
29
|
-
"text": query,
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
session_id=session_id,
|
|
35
|
-
)
|
|
36
|
-
else:
|
|
37
|
-
request = query
|
|
38
|
-
|
|
39
|
-
all_result = ""
|
|
40
|
-
async for message in runner.stream_query(
|
|
41
|
-
user_id=user_id,
|
|
42
|
-
request=request,
|
|
43
|
-
):
|
|
44
|
-
if (
|
|
45
|
-
message.object == "message"
|
|
46
|
-
and MessageType.MESSAGE == message.type
|
|
47
|
-
and RunStatus.Completed == message.status
|
|
48
|
-
):
|
|
49
|
-
all_result = message.content[0].text
|
|
50
|
-
|
|
51
|
-
return all_result
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
async def simple_call_agent_direct(agent, query):
|
|
55
|
-
async with create_context_manager() as context_manager:
|
|
56
|
-
runner = Runner(
|
|
57
|
-
agent=agent,
|
|
58
|
-
context_manager=context_manager,
|
|
59
|
-
)
|
|
60
|
-
result = await simple_call_agent(
|
|
61
|
-
query,
|
|
62
|
-
runner,
|
|
63
|
-
)
|
|
64
|
-
return result
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
async def simple_call_agent_tool(agent, query):
|
|
68
|
-
if isinstance(query, str):
|
|
69
|
-
request = AgentRequest(
|
|
70
|
-
input=[
|
|
71
|
-
{
|
|
72
|
-
"role": "user",
|
|
73
|
-
"content": [
|
|
74
|
-
{
|
|
75
|
-
"type": "text",
|
|
76
|
-
"text": query,
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
)
|
|
82
|
-
else:
|
|
83
|
-
request = query
|
|
84
|
-
|
|
85
|
-
all_result = ""
|
|
86
|
-
async with create_context_manager() as context_manager:
|
|
87
|
-
async with create_environment_manager() as environment_manager:
|
|
88
|
-
runner = Runner(
|
|
89
|
-
agent=agent,
|
|
90
|
-
context_manager=context_manager,
|
|
91
|
-
environment_manager=environment_manager,
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
async for message in runner.stream_query(
|
|
95
|
-
request=request,
|
|
96
|
-
):
|
|
97
|
-
if (
|
|
98
|
-
message.object == "message"
|
|
99
|
-
and MessageType.MESSAGE == message.type
|
|
100
|
-
and RunStatus.Completed == message.status
|
|
101
|
-
):
|
|
102
|
-
all_result = message.content[0].text
|
|
103
|
-
return all_result
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
async def simple_call_agent_tool_auto_lifecycle(agent, query):
|
|
107
|
-
if isinstance(query, str):
|
|
108
|
-
request = AgentRequest(
|
|
109
|
-
input=[
|
|
110
|
-
{
|
|
111
|
-
"role": "user",
|
|
112
|
-
"content": [
|
|
113
|
-
{
|
|
114
|
-
"type": "text",
|
|
115
|
-
"text": query,
|
|
116
|
-
},
|
|
117
|
-
],
|
|
118
|
-
},
|
|
119
|
-
],
|
|
120
|
-
)
|
|
121
|
-
else:
|
|
122
|
-
request = query
|
|
123
|
-
|
|
124
|
-
all_result = ""
|
|
125
|
-
async with Runner(
|
|
126
|
-
agent=agent,
|
|
127
|
-
context_manager=create_context_manager(),
|
|
128
|
-
environment_manager=create_environment_manager(),
|
|
129
|
-
) as runner:
|
|
130
|
-
async for message in runner.stream_query(
|
|
131
|
-
request=request,
|
|
132
|
-
):
|
|
133
|
-
if (
|
|
134
|
-
message.object == "message"
|
|
135
|
-
and MessageType.MESSAGE == message.type
|
|
136
|
-
and RunStatus.Completed == message.status
|
|
137
|
-
):
|
|
138
|
-
all_result = message.content[0].text
|
|
139
|
-
return all_result
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
async def simple_call_agent_tool_wo_env(agent, query):
|
|
143
|
-
if isinstance(query, str):
|
|
144
|
-
request = AgentRequest(
|
|
145
|
-
input=[
|
|
146
|
-
{
|
|
147
|
-
"role": "user",
|
|
148
|
-
"content": [
|
|
149
|
-
{
|
|
150
|
-
"type": "text",
|
|
151
|
-
"text": query,
|
|
152
|
-
},
|
|
153
|
-
],
|
|
154
|
-
},
|
|
155
|
-
],
|
|
156
|
-
)
|
|
157
|
-
else:
|
|
158
|
-
request = query
|
|
159
|
-
|
|
160
|
-
all_result = ""
|
|
161
|
-
async with create_context_manager() as context_manager:
|
|
162
|
-
runner = Runner(
|
|
163
|
-
agent=agent,
|
|
164
|
-
context_manager=context_manager,
|
|
165
|
-
)
|
|
166
|
-
|
|
167
|
-
async for message in runner.stream_query(
|
|
168
|
-
request=request,
|
|
169
|
-
):
|
|
170
|
-
if (
|
|
171
|
-
message.object == "message"
|
|
172
|
-
and MessageType.MESSAGE == message.type
|
|
173
|
-
and RunStatus.Completed == message.status
|
|
174
|
-
):
|
|
175
|
-
all_result = message.content[0].text
|
|
176
|
-
|
|
177
|
-
logger.debug(message.model_dump())
|
|
178
|
-
|
|
179
|
-
return all_result
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
from typing import Optional, List, Dict
|
|
3
|
-
|
|
4
|
-
from pydantic import BaseModel, ConfigDict
|
|
5
|
-
|
|
6
|
-
from .agent_schemas import AgentRequest
|
|
7
|
-
from .agent_schemas import Message
|
|
8
|
-
from ..agents.base_agent import Agent
|
|
9
|
-
from ..services.context_manager import ContextManager
|
|
10
|
-
|
|
11
|
-
from ..services.session_history_service import (
|
|
12
|
-
Session,
|
|
13
|
-
)
|
|
14
|
-
from ..services.environment_manager import EnvironmentManager
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class Context(BaseModel):
|
|
18
|
-
"""
|
|
19
|
-
Holds all contextual information for a single agent invocation.
|
|
20
|
-
|
|
21
|
-
This object is created by the Runner and passed through the agent
|
|
22
|
-
execution flow, providing access to necessary services and data,
|
|
23
|
-
including a live request queue for real-time interaction.
|
|
24
|
-
"""
|
|
25
|
-
|
|
26
|
-
model_config = ConfigDict(
|
|
27
|
-
arbitrary_types_allowed=True,
|
|
28
|
-
extra="forbid",
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
# Core context
|
|
32
|
-
user_id: str
|
|
33
|
-
session: Session = Session(id="", user_id="")
|
|
34
|
-
activate_tools: list = []
|
|
35
|
-
new_message: Optional[Message] = None
|
|
36
|
-
current_messages: List[Message] = []
|
|
37
|
-
request: AgentRequest
|
|
38
|
-
new_message_dict: Optional[Dict] = None
|
|
39
|
-
messages_list: List[Dict] = []
|
|
40
|
-
|
|
41
|
-
# Services available to the agent
|
|
42
|
-
|
|
43
|
-
environment_manager: Optional[EnvironmentManager] = None
|
|
44
|
-
context_manager: Optional[ContextManager] = None
|
|
45
|
-
# Agent specific config
|
|
46
|
-
agent: Agent
|
|
47
|
-
agent_config: Optional[dict] = None
|
|
48
|
-
|
|
49
|
-
@property
|
|
50
|
-
def messages(self):
|
|
51
|
-
if self.new_message_dict:
|
|
52
|
-
return self.messages_list + [self.new_message_dict]
|
|
53
|
-
else:
|
|
54
|
-
return self.messages_list
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
from contextlib import asynccontextmanager
|
|
3
|
-
from typing import List
|
|
4
|
-
|
|
5
|
-
from .manager import ServiceManager
|
|
6
|
-
from .memory_service import MemoryService, InMemoryMemoryService
|
|
7
|
-
from .rag_service import RAGService
|
|
8
|
-
from .session_history_service import (
|
|
9
|
-
SessionHistoryService,
|
|
10
|
-
Session,
|
|
11
|
-
InMemorySessionHistoryService,
|
|
12
|
-
)
|
|
13
|
-
from ..schemas.agent_schemas import (
|
|
14
|
-
Message,
|
|
15
|
-
MessageType,
|
|
16
|
-
Role,
|
|
17
|
-
TextContent,
|
|
18
|
-
ContentType,
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class ContextComposer:
|
|
23
|
-
@staticmethod
|
|
24
|
-
async def compose(
|
|
25
|
-
request_input: List[Message], # current input
|
|
26
|
-
session: Session, # session
|
|
27
|
-
memory_service: MemoryService = None,
|
|
28
|
-
session_history_service: SessionHistoryService = None,
|
|
29
|
-
rag_service: RAGService = None,
|
|
30
|
-
):
|
|
31
|
-
# session
|
|
32
|
-
if session_history_service:
|
|
33
|
-
await session_history_service.append_message(
|
|
34
|
-
session=session,
|
|
35
|
-
message=request_input,
|
|
36
|
-
)
|
|
37
|
-
else:
|
|
38
|
-
session.messages += request_input
|
|
39
|
-
# memory
|
|
40
|
-
if memory_service:
|
|
41
|
-
memories: List[Message] = await memory_service.search_memory(
|
|
42
|
-
user_id=session.user_id,
|
|
43
|
-
messages=request_input,
|
|
44
|
-
filters={"top_k": 5},
|
|
45
|
-
)
|
|
46
|
-
await memory_service.add_memory(
|
|
47
|
-
user_id=session.user_id,
|
|
48
|
-
messages=request_input,
|
|
49
|
-
session_id=session.id,
|
|
50
|
-
)
|
|
51
|
-
session.messages = memories + session.messages
|
|
52
|
-
|
|
53
|
-
# rag
|
|
54
|
-
if rag_service:
|
|
55
|
-
query = await rag_service.get_query_text(request_input[-1])
|
|
56
|
-
docs = await rag_service.retrieve(query=query, k=5)
|
|
57
|
-
cooked_doc = "\n".join(docs)
|
|
58
|
-
message = Message(
|
|
59
|
-
type=MessageType.MESSAGE,
|
|
60
|
-
role=Role.SYSTEM,
|
|
61
|
-
content=[TextContent(type=ContentType.TEXT, text=cooked_doc)],
|
|
62
|
-
)
|
|
63
|
-
if len(session.messages) >= 1:
|
|
64
|
-
last_message = session.messages[-1]
|
|
65
|
-
session.messages.remove(last_message)
|
|
66
|
-
session.messages.append(message)
|
|
67
|
-
session.messages.append(last_message)
|
|
68
|
-
else:
|
|
69
|
-
session.messages.append(message)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
class ContextManager(ServiceManager):
|
|
73
|
-
"""
|
|
74
|
-
The contextManager class
|
|
75
|
-
"""
|
|
76
|
-
|
|
77
|
-
def __init__(
|
|
78
|
-
self,
|
|
79
|
-
context_composer_cls=ContextComposer,
|
|
80
|
-
session_history_service: SessionHistoryService = None,
|
|
81
|
-
memory_service: MemoryService = None,
|
|
82
|
-
rag_service: RAGService = None,
|
|
83
|
-
):
|
|
84
|
-
self._context_composer_cls = context_composer_cls
|
|
85
|
-
self._session_history_service = session_history_service
|
|
86
|
-
self._memory_service = memory_service
|
|
87
|
-
self._rag_service = rag_service
|
|
88
|
-
super().__init__()
|
|
89
|
-
|
|
90
|
-
def _register_default_services(self):
|
|
91
|
-
"""Register default services for context management."""
|
|
92
|
-
self._session_history_service = (
|
|
93
|
-
self._session_history_service or InMemorySessionHistoryService()
|
|
94
|
-
)
|
|
95
|
-
self._memory_service = self._memory_service or InMemoryMemoryService()
|
|
96
|
-
|
|
97
|
-
self.register_service("session", self._session_history_service)
|
|
98
|
-
self.register_service("memory", self._memory_service)
|
|
99
|
-
if self._rag_service:
|
|
100
|
-
self.register_service("rag", self._rag_service)
|
|
101
|
-
|
|
102
|
-
async def compose_context(
|
|
103
|
-
self,
|
|
104
|
-
session: Session,
|
|
105
|
-
request_input: List[Message],
|
|
106
|
-
):
|
|
107
|
-
await self._context_composer_cls.compose(
|
|
108
|
-
memory_service=self._memory_service,
|
|
109
|
-
session_history_service=self._session_history_service,
|
|
110
|
-
rag_service=self._rag_service,
|
|
111
|
-
session=session,
|
|
112
|
-
request_input=request_input,
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
async def compose_session(
|
|
116
|
-
self,
|
|
117
|
-
user_id: str,
|
|
118
|
-
session_id: str,
|
|
119
|
-
):
|
|
120
|
-
if self._session_history_service:
|
|
121
|
-
session = await self._session_history_service.get_session(
|
|
122
|
-
user_id=user_id,
|
|
123
|
-
session_id=session_id,
|
|
124
|
-
)
|
|
125
|
-
if not session:
|
|
126
|
-
raise RuntimeError(f"Session {session_id} not found")
|
|
127
|
-
else:
|
|
128
|
-
session = Session(
|
|
129
|
-
user_id=user_id,
|
|
130
|
-
id=session_id,
|
|
131
|
-
messages=[],
|
|
132
|
-
)
|
|
133
|
-
return session
|
|
134
|
-
|
|
135
|
-
async def append(self, session: Session, event_output: List[Message]):
|
|
136
|
-
if self._session_history_service:
|
|
137
|
-
await self._session_history_service.append_message(
|
|
138
|
-
session=session,
|
|
139
|
-
message=event_output,
|
|
140
|
-
)
|
|
141
|
-
if self._memory_service:
|
|
142
|
-
await self._memory_service.add_memory(
|
|
143
|
-
user_id=session.user_id,
|
|
144
|
-
session_id=session.id,
|
|
145
|
-
messages=event_output,
|
|
146
|
-
)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
@asynccontextmanager
|
|
150
|
-
async def create_context_manager(
|
|
151
|
-
memory_service: MemoryService = None,
|
|
152
|
-
session_history_service: SessionHistoryService = None,
|
|
153
|
-
rag_service: RAGService = None,
|
|
154
|
-
context_composer_cls=ContextComposer,
|
|
155
|
-
):
|
|
156
|
-
manager = ContextManager(
|
|
157
|
-
memory_service=memory_service,
|
|
158
|
-
session_history_service=session_history_service,
|
|
159
|
-
rag_service=rag_service,
|
|
160
|
-
context_composer_cls=context_composer_cls,
|
|
161
|
-
)
|
|
162
|
-
|
|
163
|
-
async with manager:
|
|
164
|
-
yield manager
|