agentrun-sdk 0.1.2__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.
Potentially problematic release.
This version of agentrun-sdk might be problematic. Click here for more details.
- agentrun_operation_sdk/cli/__init__.py +1 -0
- agentrun_operation_sdk/cli/cli.py +19 -0
- agentrun_operation_sdk/cli/common.py +21 -0
- agentrun_operation_sdk/cli/runtime/__init__.py +1 -0
- agentrun_operation_sdk/cli/runtime/commands.py +203 -0
- agentrun_operation_sdk/client/client.py +75 -0
- agentrun_operation_sdk/operations/runtime/__init__.py +8 -0
- agentrun_operation_sdk/operations/runtime/configure.py +101 -0
- agentrun_operation_sdk/operations/runtime/launch.py +82 -0
- agentrun_operation_sdk/operations/runtime/models.py +31 -0
- agentrun_operation_sdk/services/runtime.py +152 -0
- agentrun_operation_sdk/utils/logging_config.py +72 -0
- agentrun_operation_sdk/utils/runtime/config.py +94 -0
- agentrun_operation_sdk/utils/runtime/container.py +280 -0
- agentrun_operation_sdk/utils/runtime/entrypoint.py +203 -0
- agentrun_operation_sdk/utils/runtime/schema.py +56 -0
- agentrun_sdk/__init__.py +7 -0
- agentrun_sdk/agent/__init__.py +25 -0
- agentrun_sdk/agent/agent.py +696 -0
- agentrun_sdk/agent/agent_result.py +46 -0
- agentrun_sdk/agent/conversation_manager/__init__.py +26 -0
- agentrun_sdk/agent/conversation_manager/conversation_manager.py +88 -0
- agentrun_sdk/agent/conversation_manager/null_conversation_manager.py +46 -0
- agentrun_sdk/agent/conversation_manager/sliding_window_conversation_manager.py +179 -0
- agentrun_sdk/agent/conversation_manager/summarizing_conversation_manager.py +252 -0
- agentrun_sdk/agent/state.py +97 -0
- agentrun_sdk/event_loop/__init__.py +9 -0
- agentrun_sdk/event_loop/event_loop.py +499 -0
- agentrun_sdk/event_loop/streaming.py +319 -0
- agentrun_sdk/experimental/__init__.py +4 -0
- agentrun_sdk/experimental/hooks/__init__.py +15 -0
- agentrun_sdk/experimental/hooks/events.py +123 -0
- agentrun_sdk/handlers/__init__.py +10 -0
- agentrun_sdk/handlers/callback_handler.py +70 -0
- agentrun_sdk/hooks/__init__.py +49 -0
- agentrun_sdk/hooks/events.py +80 -0
- agentrun_sdk/hooks/registry.py +247 -0
- agentrun_sdk/models/__init__.py +10 -0
- agentrun_sdk/models/anthropic.py +432 -0
- agentrun_sdk/models/bedrock.py +649 -0
- agentrun_sdk/models/litellm.py +225 -0
- agentrun_sdk/models/llamaapi.py +438 -0
- agentrun_sdk/models/mistral.py +539 -0
- agentrun_sdk/models/model.py +95 -0
- agentrun_sdk/models/ollama.py +357 -0
- agentrun_sdk/models/openai.py +436 -0
- agentrun_sdk/models/sagemaker.py +598 -0
- agentrun_sdk/models/writer.py +449 -0
- agentrun_sdk/multiagent/__init__.py +22 -0
- agentrun_sdk/multiagent/a2a/__init__.py +15 -0
- agentrun_sdk/multiagent/a2a/executor.py +148 -0
- agentrun_sdk/multiagent/a2a/server.py +252 -0
- agentrun_sdk/multiagent/base.py +92 -0
- agentrun_sdk/multiagent/graph.py +555 -0
- agentrun_sdk/multiagent/swarm.py +656 -0
- agentrun_sdk/py.typed +1 -0
- agentrun_sdk/session/__init__.py +18 -0
- agentrun_sdk/session/file_session_manager.py +216 -0
- agentrun_sdk/session/repository_session_manager.py +152 -0
- agentrun_sdk/session/s3_session_manager.py +272 -0
- agentrun_sdk/session/session_manager.py +73 -0
- agentrun_sdk/session/session_repository.py +51 -0
- agentrun_sdk/telemetry/__init__.py +21 -0
- agentrun_sdk/telemetry/config.py +194 -0
- agentrun_sdk/telemetry/metrics.py +476 -0
- agentrun_sdk/telemetry/metrics_constants.py +15 -0
- agentrun_sdk/telemetry/tracer.py +563 -0
- agentrun_sdk/tools/__init__.py +17 -0
- agentrun_sdk/tools/decorator.py +569 -0
- agentrun_sdk/tools/executor.py +137 -0
- agentrun_sdk/tools/loader.py +152 -0
- agentrun_sdk/tools/mcp/__init__.py +13 -0
- agentrun_sdk/tools/mcp/mcp_agent_tool.py +99 -0
- agentrun_sdk/tools/mcp/mcp_client.py +423 -0
- agentrun_sdk/tools/mcp/mcp_instrumentation.py +322 -0
- agentrun_sdk/tools/mcp/mcp_types.py +63 -0
- agentrun_sdk/tools/registry.py +607 -0
- agentrun_sdk/tools/structured_output.py +421 -0
- agentrun_sdk/tools/tools.py +217 -0
- agentrun_sdk/tools/watcher.py +136 -0
- agentrun_sdk/types/__init__.py +5 -0
- agentrun_sdk/types/collections.py +23 -0
- agentrun_sdk/types/content.py +188 -0
- agentrun_sdk/types/event_loop.py +48 -0
- agentrun_sdk/types/exceptions.py +81 -0
- agentrun_sdk/types/guardrails.py +254 -0
- agentrun_sdk/types/media.py +89 -0
- agentrun_sdk/types/session.py +152 -0
- agentrun_sdk/types/streaming.py +201 -0
- agentrun_sdk/types/tools.py +258 -0
- agentrun_sdk/types/traces.py +5 -0
- agentrun_sdk-0.1.2.dist-info/METADATA +51 -0
- agentrun_sdk-0.1.2.dist-info/RECORD +115 -0
- agentrun_sdk-0.1.2.dist-info/WHEEL +5 -0
- agentrun_sdk-0.1.2.dist-info/entry_points.txt +2 -0
- agentrun_sdk-0.1.2.dist-info/top_level.txt +3 -0
- agentrun_wrapper/__init__.py +11 -0
- agentrun_wrapper/_utils/__init__.py +6 -0
- agentrun_wrapper/_utils/endpoints.py +16 -0
- agentrun_wrapper/identity/__init__.py +5 -0
- agentrun_wrapper/identity/auth.py +211 -0
- agentrun_wrapper/memory/__init__.py +6 -0
- agentrun_wrapper/memory/client.py +1697 -0
- agentrun_wrapper/memory/constants.py +103 -0
- agentrun_wrapper/memory/controlplane.py +626 -0
- agentrun_wrapper/py.typed +1 -0
- agentrun_wrapper/runtime/__init__.py +13 -0
- agentrun_wrapper/runtime/app.py +473 -0
- agentrun_wrapper/runtime/context.py +34 -0
- agentrun_wrapper/runtime/models.py +25 -0
- agentrun_wrapper/services/__init__.py +1 -0
- agentrun_wrapper/services/identity.py +192 -0
- agentrun_wrapper/tools/__init__.py +6 -0
- agentrun_wrapper/tools/browser_client.py +325 -0
- agentrun_wrapper/tools/code_interpreter_client.py +186 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"""Client for interacting with the Code Interpreter sandbox service.
|
|
2
|
+
|
|
3
|
+
This module provides a client for the AWS Code Interpreter sandbox, allowing
|
|
4
|
+
applications to start, stop, and invoke code execution in a managed sandbox environment.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import uuid
|
|
8
|
+
from contextlib import contextmanager
|
|
9
|
+
from typing import Dict, Generator, Optional
|
|
10
|
+
|
|
11
|
+
import boto3
|
|
12
|
+
|
|
13
|
+
from bedrock_agentcore._utils.endpoints import get_data_plane_endpoint
|
|
14
|
+
|
|
15
|
+
DEFAULT_IDENTIFIER = "aws.codeinterpreter.v1"
|
|
16
|
+
DEFAULT_TIMEOUT = 900
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class CodeInterpreter:
|
|
20
|
+
"""Client for interacting with the AWS Code Interpreter sandbox service.
|
|
21
|
+
|
|
22
|
+
This client handles the session lifecycle and method invocation for
|
|
23
|
+
Code Interpreter sandboxes, providing an interface to execute code
|
|
24
|
+
in a secure, managed environment.
|
|
25
|
+
|
|
26
|
+
Attributes:
|
|
27
|
+
data_plane_service_name (str): AWS service name for the data plane.
|
|
28
|
+
client: The boto3 client for interacting with the service.
|
|
29
|
+
identifier (str, optional): The code interpreter identifier.
|
|
30
|
+
session_id (str, optional): The active session ID.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __init__(self, region: str) -> None:
|
|
34
|
+
"""Initialize a Code Interpreter client for the specified AWS region.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
region (str): The AWS region to use for the Code Interpreter service.
|
|
38
|
+
"""
|
|
39
|
+
self.data_plane_service_name = "bedrock-agentcore"
|
|
40
|
+
self.client = boto3.client(
|
|
41
|
+
self.data_plane_service_name, region_name=region, endpoint_url=get_data_plane_endpoint(region)
|
|
42
|
+
)
|
|
43
|
+
self._identifier = None
|
|
44
|
+
self._session_id = None
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def identifier(self) -> Optional[str]:
|
|
48
|
+
"""Get the current code interpreter identifier.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
Optional[str]: The current identifier or None if not set.
|
|
52
|
+
"""
|
|
53
|
+
return self._identifier
|
|
54
|
+
|
|
55
|
+
@identifier.setter
|
|
56
|
+
def identifier(self, value: Optional[str]):
|
|
57
|
+
"""Set the code interpreter identifier.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
value (Optional[str]): The identifier to set.
|
|
61
|
+
"""
|
|
62
|
+
self._identifier = value
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def session_id(self) -> Optional[str]:
|
|
66
|
+
"""Get the current session ID.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
Optional[str]: The current session ID or None if not set.
|
|
70
|
+
"""
|
|
71
|
+
return self._session_id
|
|
72
|
+
|
|
73
|
+
@session_id.setter
|
|
74
|
+
def session_id(self, value: Optional[str]):
|
|
75
|
+
"""Set the session ID.
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
value (Optional[str]): The session ID to set.
|
|
79
|
+
"""
|
|
80
|
+
self._session_id = value
|
|
81
|
+
|
|
82
|
+
def start(
|
|
83
|
+
self,
|
|
84
|
+
identifier: Optional[str] = DEFAULT_IDENTIFIER,
|
|
85
|
+
name: Optional[str] = None,
|
|
86
|
+
session_timeout_seconds: Optional[int] = DEFAULT_TIMEOUT,
|
|
87
|
+
) -> str:
|
|
88
|
+
"""Start a code interpreter sandbox session.
|
|
89
|
+
|
|
90
|
+
This method initializes a new code interpreter session with the provided parameters.
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
identifier (Optional[str]): The code interpreter sandbox identifier to use.
|
|
94
|
+
Defaults to DEFAULT_IDENTIFIER.
|
|
95
|
+
name (Optional[str]): A name for this session. If not provided, a name
|
|
96
|
+
will be generated using a UUID.
|
|
97
|
+
session_timeout_seconds (Optional[int]): The timeout for the session in seconds.
|
|
98
|
+
Defaults to DEFAULT_TIMEOUT.
|
|
99
|
+
description (Optional[str]): A description for this session.
|
|
100
|
+
Defaults to an empty string.
|
|
101
|
+
|
|
102
|
+
Returns:
|
|
103
|
+
str: The session ID of the newly created session.
|
|
104
|
+
"""
|
|
105
|
+
response = self.client.start_code_interpreter_session(
|
|
106
|
+
codeInterpreterIdentifier=identifier,
|
|
107
|
+
name=name or f"code-session-{uuid.uuid4().hex[:8]}",
|
|
108
|
+
sessionTimeoutSeconds=session_timeout_seconds,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
self.identifier = response["codeInterpreterIdentifier"]
|
|
112
|
+
self.session_id = response["sessionId"]
|
|
113
|
+
|
|
114
|
+
return self.session_id
|
|
115
|
+
|
|
116
|
+
def stop(self):
|
|
117
|
+
"""Stop the current code interpreter session if one is active.
|
|
118
|
+
|
|
119
|
+
This method stops any active session and clears the session state.
|
|
120
|
+
If no session is active, this method does nothing.
|
|
121
|
+
|
|
122
|
+
Returns:
|
|
123
|
+
bool: True if no session was active or the session was successfully stopped.
|
|
124
|
+
"""
|
|
125
|
+
if not self.session_id or not self.identifier:
|
|
126
|
+
return True
|
|
127
|
+
|
|
128
|
+
self.client.stop_code_interpreter_session(
|
|
129
|
+
**{"codeInterpreterIdentifier": self.identifier, "sessionId": self.session_id}
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
self.identifier = None
|
|
133
|
+
self.session_id = None
|
|
134
|
+
|
|
135
|
+
def invoke(self, method: str, params: Optional[Dict] = None):
|
|
136
|
+
"""Invoke a method in the code interpreter sandbox.
|
|
137
|
+
|
|
138
|
+
If no session is active, this method automatically starts a new session
|
|
139
|
+
before invoking the requested method.
|
|
140
|
+
|
|
141
|
+
Args:
|
|
142
|
+
method (str): The name of the method to invoke in the sandbox.
|
|
143
|
+
params (Optional[Dict]): Parameters to pass to the method. Defaults to None.
|
|
144
|
+
request_id (Optional[str]): A custom request ID. If not provided, a unique ID is generated.
|
|
145
|
+
|
|
146
|
+
Returns:
|
|
147
|
+
dict: The response from the code interpreter service.
|
|
148
|
+
"""
|
|
149
|
+
if not self.session_id or not self.identifier:
|
|
150
|
+
self.start()
|
|
151
|
+
|
|
152
|
+
return self.client.invoke_code_interpreter(
|
|
153
|
+
**{
|
|
154
|
+
"codeInterpreterIdentifier": self.identifier,
|
|
155
|
+
"sessionId": self.session_id,
|
|
156
|
+
"name": method,
|
|
157
|
+
"arguments": params or {},
|
|
158
|
+
}
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
@contextmanager
|
|
163
|
+
def code_session(region: str) -> Generator[CodeInterpreter, None, None]:
|
|
164
|
+
"""Context manager for creating and managing a code interpreter session.
|
|
165
|
+
|
|
166
|
+
This context manager handles creating a client, starting a session, and
|
|
167
|
+
ensuring the session is properly cleaned up when the context exits.
|
|
168
|
+
|
|
169
|
+
Args:
|
|
170
|
+
region (str): The AWS region to use for the Code Interpreter service.
|
|
171
|
+
|
|
172
|
+
Yields:
|
|
173
|
+
CodeInterpreterClient: An initialized and started code interpreter client.
|
|
174
|
+
|
|
175
|
+
Example:
|
|
176
|
+
>>> with code_session('us-west-2') as client:
|
|
177
|
+
... result = client.invoke('listFiles')
|
|
178
|
+
... # Process result here
|
|
179
|
+
"""
|
|
180
|
+
client = CodeInterpreter(region)
|
|
181
|
+
client.start()
|
|
182
|
+
|
|
183
|
+
try:
|
|
184
|
+
yield client
|
|
185
|
+
finally:
|
|
186
|
+
client.stop()
|