aip-agents-binary 0.5.21__py3-none-any.whl → 0.5.23__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.
- aip_agents/examples/{hello_world_langgraph_bosa_twitter.py → hello_world_langgraph_gl_connector_twitter.py} +10 -7
- aip_agents/examples/hello_world_langgraph_gl_connector_twitter.pyi +5 -0
- aip_agents/examples/hello_world_sentry.py +2 -2
- aip_agents/mcp/client/transports.py +15 -2
- aip_agents/sentry/__init__.py +1 -1
- aip_agents/sentry/sentry.py +4 -4
- aip_agents/sentry/sentry.pyi +2 -2
- aip_agents/tools/__init__.py +8 -2
- aip_agents/tools/__init__.pyi +2 -2
- aip_agents/tools/code_sandbox/e2b_cloud_sandbox_extended.py +80 -31
- aip_agents/tools/code_sandbox/e2b_cloud_sandbox_extended.pyi +25 -9
- aip_agents/tools/code_sandbox/e2b_sandbox_tool.py +6 -6
- aip_agents/tools/constants.py +24 -12
- aip_agents/tools/constants.pyi +14 -11
- aip_agents/tools/gl_connector/__init__.py +1 -1
- aip_agents/tools/gl_connector/tool.py +62 -30
- aip_agents/tools/gl_connector/tool.pyi +3 -3
- aip_agents/tools/gl_connector_tools.py +119 -0
- aip_agents/tools/gl_connector_tools.pyi +39 -0
- {aip_agents_binary-0.5.21.dist-info → aip_agents_binary-0.5.23.dist-info}/METADATA +5 -5
- {aip_agents_binary-0.5.21.dist-info → aip_agents_binary-0.5.23.dist-info}/RECORD +23 -23
- aip_agents/examples/hello_world_langgraph_bosa_twitter.pyi +0 -5
- aip_agents/tools/bosa_tools.py +0 -105
- aip_agents/tools/bosa_tools.pyi +0 -37
- {aip_agents_binary-0.5.21.dist-info → aip_agents_binary-0.5.23.dist-info}/WHEEL +0 -0
- {aip_agents_binary-0.5.21.dist-info → aip_agents_binary-0.5.23.dist-info}/top_level.txt +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Minimal LangGraph agent with
|
|
1
|
+
"""Minimal LangGraph agent with GL Connectors support example demonstrating asynchronous run.
|
|
2
2
|
|
|
3
3
|
Authors:
|
|
4
4
|
Saul Sayers (saul.sayers@gdplabs.id)
|
|
@@ -6,22 +6,25 @@ Authors:
|
|
|
6
6
|
|
|
7
7
|
import asyncio
|
|
8
8
|
|
|
9
|
+
from dotenv import load_dotenv
|
|
9
10
|
from langchain_openai import ChatOpenAI
|
|
10
11
|
|
|
11
12
|
from aip_agents.agent import LangGraphAgent
|
|
12
|
-
from aip_agents.tools import
|
|
13
|
+
from aip_agents.tools import GL_CONNECTORS_AUTOMATED_TOOLS
|
|
13
14
|
|
|
15
|
+
load_dotenv(override=True)
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
|
|
18
|
+
async def langgraph_gl_connector_example():
|
|
16
19
|
"""Demonstrates the LangGraphAgent's arun method."""
|
|
17
20
|
model = ChatOpenAI(model="gpt-4.1", temperature=0)
|
|
18
|
-
agent_name = "
|
|
21
|
+
agent_name = "GLConnectorTwitterAgent"
|
|
19
22
|
|
|
20
23
|
langgraph_agent = LangGraphAgent(
|
|
21
24
|
name=agent_name,
|
|
22
|
-
instruction="You are a helpful assistant that
|
|
25
|
+
instruction="You are a helpful assistant that uses GL Connectors to connect with the Twitter API.",
|
|
23
26
|
model=model,
|
|
24
|
-
tools=
|
|
27
|
+
tools=GL_CONNECTORS_AUTOMATED_TOOLS["twitter"],
|
|
25
28
|
)
|
|
26
29
|
|
|
27
30
|
query = "Get 3 tweets about the latest Air India Incident"
|
|
@@ -38,4 +41,4 @@ async def langgraph_bosa_example():
|
|
|
38
41
|
|
|
39
42
|
|
|
40
43
|
if __name__ == "__main__":
|
|
41
|
-
asyncio.run(
|
|
44
|
+
asyncio.run(langgraph_gl_connector_example())
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""This is a simple FastAPI app to test Sentry with Open Telemetry from
|
|
1
|
+
"""This is a simple FastAPI app to test Sentry with Open Telemetry from GL Connectors SDK.
|
|
2
2
|
|
|
3
3
|
To run this example, make sure to set the following environment variables:
|
|
4
4
|
SENTRY_DSN
|
|
@@ -63,7 +63,7 @@ def create_app() -> FastAPI:
|
|
|
63
63
|
FastAPI: The configured FastAPI application.
|
|
64
64
|
"""
|
|
65
65
|
app = FastAPI(
|
|
66
|
-
title="
|
|
66
|
+
title="GL Connectors SDK - Sentry with Open Telemetry",
|
|
67
67
|
description="This is a simple FastAPI app to test Sentry with Open Telemetry.",
|
|
68
68
|
version="0.0.1",
|
|
69
69
|
docs_url=None,
|
|
@@ -45,6 +45,19 @@ DEFAULT_TIMEOUT: float = 30.0
|
|
|
45
45
|
"""Default connection timeout in seconds."""
|
|
46
46
|
|
|
47
47
|
|
|
48
|
+
def _sanitize_headers(config: MCPConfiguration) -> dict[str, str]:
|
|
49
|
+
"""Remove headers with None values to avoid invalid HTTP headers.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
config (MCPConfiguration): Transport configuration containing optional headers.
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
dict[str, str]: Filtered headers with None values removed.
|
|
56
|
+
"""
|
|
57
|
+
headers = config.get("headers", {}) or {}
|
|
58
|
+
return {key: value for key, value in headers.items() if value is not None}
|
|
59
|
+
|
|
60
|
+
|
|
48
61
|
class TransportType(StrEnum):
|
|
49
62
|
"""Enum for supported MCP transport types."""
|
|
50
63
|
|
|
@@ -115,7 +128,7 @@ class SSETransport(Transport):
|
|
|
115
128
|
|
|
116
129
|
url = f"{base_url}/sse" if not base_url.endswith("/sse") else base_url
|
|
117
130
|
timeout = self.config.get("timeout", DEFAULT_TIMEOUT)
|
|
118
|
-
headers = self.config
|
|
131
|
+
headers = _sanitize_headers(self.config)
|
|
119
132
|
logger.debug(f"Attempting SSE connection to {url} with headers: {list(headers.keys())}")
|
|
120
133
|
try:
|
|
121
134
|
self.ctx = sse_client(url=url, timeout=timeout, sse_read_timeout=300.0, headers=headers)
|
|
@@ -147,7 +160,7 @@ class HTTPTransport(Transport):
|
|
|
147
160
|
|
|
148
161
|
url = f"{base_url}/mcp" if not base_url.endswith("/mcp") else base_url
|
|
149
162
|
timeout = self.config.get("timeout", DEFAULT_TIMEOUT)
|
|
150
|
-
headers = self.config
|
|
163
|
+
headers = _sanitize_headers(self.config)
|
|
151
164
|
logger.debug(f"Attempting streamable HTTP connection to {url} with headers: {list(headers.keys())}")
|
|
152
165
|
try:
|
|
153
166
|
self.ctx = streamablehttp_client(url=url, timeout=timeout, headers=headers)
|
aip_agents/sentry/__init__.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""This module provides a centralized way to handle Sentry and OpenTelemetry configuration for
|
|
1
|
+
"""This module provides a centralized way to handle Sentry and OpenTelemetry configuration for GL Connectors SDK.
|
|
2
2
|
|
|
3
3
|
Authors:
|
|
4
4
|
Saul Sayers (saul.sayers@gdplabs.id)
|
aip_agents/sentry/sentry.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""This file contains the Sentry and OpenTelemetry configuration for
|
|
1
|
+
"""This file contains the Sentry and OpenTelemetry configuration for GL Connectors SDK.
|
|
2
2
|
|
|
3
3
|
Authors:
|
|
4
4
|
Saul Sayers (saul.sayers@gdplabs.id)
|
|
@@ -61,8 +61,8 @@ def get_all_methods(cls: type) -> list:
|
|
|
61
61
|
return methods
|
|
62
62
|
|
|
63
63
|
|
|
64
|
-
def
|
|
65
|
-
"""Instrument
|
|
64
|
+
def instrument_gl_functions() -> None:
|
|
65
|
+
"""Instrument GL functions."""
|
|
66
66
|
if BOSAFunctionsInstrumentor is None:
|
|
67
67
|
return
|
|
68
68
|
agent_methods = []
|
|
@@ -148,4 +148,4 @@ def setup_telemetry(app: FastAPI) -> None:
|
|
|
148
148
|
setup_sentry_with_open_telemetry(app)
|
|
149
149
|
else:
|
|
150
150
|
setup_sentry_only()
|
|
151
|
-
|
|
151
|
+
instrument_gl_functions()
|
aip_agents/sentry/sentry.pyi
CHANGED
|
@@ -21,8 +21,8 @@ def get_all_methods(cls) -> list:
|
|
|
21
21
|
Returns:
|
|
22
22
|
list: A list of methods.
|
|
23
23
|
"""
|
|
24
|
-
def
|
|
25
|
-
"""Instrument
|
|
24
|
+
def instrument_gl_functions() -> None:
|
|
25
|
+
"""Instrument GL functions."""
|
|
26
26
|
def traces_sampler(*args) -> float:
|
|
27
27
|
"""Determine appropriate sampling rate for Sentry transactions.
|
|
28
28
|
|
aip_agents/tools/__init__.py
CHANGED
|
@@ -3,15 +3,21 @@
|
|
|
3
3
|
from importlib import import_module
|
|
4
4
|
from typing import TYPE_CHECKING
|
|
5
5
|
|
|
6
|
-
from aip_agents.tools.bosa_tools import BOSA_AUTOMATED_TOOLS
|
|
7
6
|
from aip_agents.tools.gl_connector import GLConnectorTool
|
|
7
|
+
from aip_agents.tools.gl_connector_tools import BOSA_AUTOMATED_TOOLS, GL_CONNECTORS_AUTOMATED_TOOLS
|
|
8
8
|
from aip_agents.tools.time_tool import TimeTool
|
|
9
9
|
from aip_agents.tools.web_search import GoogleSerperTool
|
|
10
10
|
from aip_agents.utils.logger import get_logger
|
|
11
11
|
|
|
12
12
|
logger = get_logger(__name__)
|
|
13
13
|
|
|
14
|
-
__all__ = [
|
|
14
|
+
__all__ = [
|
|
15
|
+
"BOSA_AUTOMATED_TOOLS",
|
|
16
|
+
"GL_CONNECTORS_AUTOMATED_TOOLS",
|
|
17
|
+
"GLConnectorTool",
|
|
18
|
+
"GoogleSerperTool",
|
|
19
|
+
"TimeTool",
|
|
20
|
+
]
|
|
15
21
|
|
|
16
22
|
|
|
17
23
|
def _register_optional(module_path: str, export_name: str) -> None:
|
aip_agents/tools/__init__.pyi
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
from aip_agents.tools.bosa_tools import BOSA_AUTOMATED_TOOLS as BOSA_AUTOMATED_TOOLS
|
|
2
1
|
from aip_agents.tools.browser_use import BrowserUseTool as BrowserUseTool
|
|
3
2
|
from aip_agents.tools.code_sandbox import E2BCodeSandboxTool as E2BCodeSandboxTool
|
|
4
3
|
from aip_agents.tools.document_loader import DocxReaderTool as DocxReaderTool, ExcelReaderTool as ExcelReaderTool, PDFReaderTool as PDFReaderTool
|
|
5
4
|
from aip_agents.tools.gl_connector import GLConnectorTool as GLConnectorTool
|
|
5
|
+
from aip_agents.tools.gl_connector_tools import BOSA_AUTOMATED_TOOLS as BOSA_AUTOMATED_TOOLS, GL_CONNECTORS_AUTOMATED_TOOLS as GL_CONNECTORS_AUTOMATED_TOOLS
|
|
6
6
|
from aip_agents.tools.time_tool import TimeTool as TimeTool
|
|
7
7
|
from aip_agents.tools.web_search import GoogleSerperTool as GoogleSerperTool
|
|
8
8
|
|
|
9
|
-
__all__ = ['BOSA_AUTOMATED_TOOLS', 'GLConnectorTool', 'GoogleSerperTool', 'TimeTool', 'BrowserUseTool', 'E2BCodeSandboxTool', 'DocxReaderTool', 'ExcelReaderTool', 'PDFReaderTool']
|
|
9
|
+
__all__ = ['BOSA_AUTOMATED_TOOLS', 'GL_CONNECTORS_AUTOMATED_TOOLS', 'GLConnectorTool', 'GoogleSerperTool', 'TimeTool', 'BrowserUseTool', 'E2BCodeSandboxTool', 'DocxReaderTool', 'ExcelReaderTool', 'PDFReaderTool']
|
|
@@ -11,12 +11,10 @@ from http import HTTPStatus
|
|
|
11
11
|
from typing import Any
|
|
12
12
|
|
|
13
13
|
import requests
|
|
14
|
+
from e2b_code_interpreter import Sandbox
|
|
14
15
|
from gllm_inference.schema import Attachment
|
|
15
|
-
from gllm_tools.code_interpreter.code_sandbox.
|
|
16
|
-
from gllm_tools.code_interpreter.code_sandbox.models import
|
|
17
|
-
ExecutionResult,
|
|
18
|
-
ExecutionStatus,
|
|
19
|
-
)
|
|
16
|
+
from gllm_tools.code_interpreter.code_sandbox.e2b_sandbox import E2BSandbox
|
|
17
|
+
from gllm_tools.code_interpreter.code_sandbox.models import ExecutionResult, ExecutionStatus
|
|
20
18
|
from gllm_tools.code_interpreter.code_sandbox.utils import calculate_duration_ms
|
|
21
19
|
|
|
22
20
|
from aip_agents.tools.code_sandbox.constant import DATA_FILE_PATH
|
|
@@ -123,19 +121,57 @@ class SandboxFileWatcher:
|
|
|
123
121
|
return self._created_files.copy()
|
|
124
122
|
|
|
125
123
|
|
|
126
|
-
class MyE2BCloudSandbox(
|
|
127
|
-
"""Extended E2B
|
|
124
|
+
class MyE2BCloudSandbox(E2BSandbox):
|
|
125
|
+
"""Extended E2B sandbox with filesystem monitoring capabilities.
|
|
128
126
|
|
|
129
|
-
|
|
130
|
-
|
|
127
|
+
Use `create()` in production to build a fully initialized sandbox wrapper.
|
|
128
|
+
Direct construction is intentionally blocked to prevent partially initialized
|
|
129
|
+
instances that lack the underlying E2B sandbox clients.
|
|
130
|
+
"""
|
|
131
|
+
|
|
132
|
+
def __init__(self, language: str = "python", *, _unsafe_allow_init: bool = False) -> None:
|
|
133
|
+
"""Initialize the sandbox wrapper.
|
|
131
134
|
|
|
132
135
|
Args:
|
|
133
|
-
|
|
134
|
-
|
|
136
|
+
language (str): Language to execute inside the sandbox.
|
|
137
|
+
_unsafe_allow_init (bool): Escape hatch for tests/mocks only.
|
|
138
|
+
|
|
139
|
+
Raises:
|
|
140
|
+
RuntimeError: When instantiated directly without `create()`.
|
|
135
141
|
"""
|
|
136
|
-
|
|
142
|
+
if not _unsafe_allow_init:
|
|
143
|
+
raise RuntimeError("Use MyE2BCloudSandbox.create(...) to initialize a sandbox instance.")
|
|
144
|
+
super().__init__(language=language)
|
|
137
145
|
self.file_watcher: SandboxFileWatcher | None = None
|
|
138
146
|
|
|
147
|
+
@classmethod
|
|
148
|
+
async def create(
|
|
149
|
+
cls,
|
|
150
|
+
api_key: str,
|
|
151
|
+
domain: str | None = None,
|
|
152
|
+
template: str | None = None,
|
|
153
|
+
language: str = "python",
|
|
154
|
+
additional_packages: list[str] | None = None,
|
|
155
|
+
**kwargs: Any,
|
|
156
|
+
) -> "MyE2BCloudSandbox":
|
|
157
|
+
"""Create a fully initialized sandbox wrapper.
|
|
158
|
+
|
|
159
|
+
This is the supported construction path for production usage. It wires
|
|
160
|
+
the E2B sandbox instance and its filesystem/command clients, then
|
|
161
|
+
installs language dependencies.
|
|
162
|
+
"""
|
|
163
|
+
sandbox = Sandbox.create(api_key=api_key, domain=domain, template=template, **kwargs)
|
|
164
|
+
|
|
165
|
+
instance = cls(language=language, _unsafe_allow_init=True)
|
|
166
|
+
instance.sandbox = sandbox
|
|
167
|
+
instance.files = sandbox.files
|
|
168
|
+
instance.commands = sandbox.commands
|
|
169
|
+
instance.additional_packages = additional_packages or []
|
|
170
|
+
|
|
171
|
+
instance._install_language_dependencies()
|
|
172
|
+
|
|
173
|
+
return instance
|
|
174
|
+
|
|
139
175
|
async def execute_code(
|
|
140
176
|
self,
|
|
141
177
|
code: str,
|
|
@@ -161,11 +197,10 @@ class MyE2BCloudSandbox(E2BCloudSandbox):
|
|
|
161
197
|
Raises:
|
|
162
198
|
RuntimeError: If sandbox is not initialized.
|
|
163
199
|
"""
|
|
164
|
-
if not self.sandbox:
|
|
200
|
+
if not self.sandbox or not self.files or not self.commands:
|
|
165
201
|
raise RuntimeError("Sandbox is not initialized")
|
|
166
202
|
|
|
167
203
|
start_time = time.time()
|
|
168
|
-
|
|
169
204
|
try:
|
|
170
205
|
# Initialize filesystem monitoring
|
|
171
206
|
self.file_watcher = SandboxFileWatcher(self.sandbox)
|
|
@@ -176,8 +211,12 @@ class MyE2BCloudSandbox(E2BCloudSandbox):
|
|
|
176
211
|
# Pre-populate the variable `df` for direct use in the code
|
|
177
212
|
if files:
|
|
178
213
|
logger.info("Pre-populating the variable `df` with the data from the file.")
|
|
179
|
-
self.sandbox.run_code(
|
|
180
|
-
|
|
214
|
+
self.sandbox.run_code(
|
|
215
|
+
f"import pandas as pd; df = pd.read_csv('{DATA_FILE_PATH}')",
|
|
216
|
+
language=self.language,
|
|
217
|
+
timeout=timeout,
|
|
218
|
+
)
|
|
219
|
+
execution = self.sandbox.run_code(code, language=self.language, timeout=timeout)
|
|
181
220
|
duration_ms = calculate_duration_ms(start_time)
|
|
182
221
|
status = ExecutionStatus.ERROR if execution.error else ExecutionStatus.SUCCESS
|
|
183
222
|
|
|
@@ -191,8 +230,8 @@ class MyE2BCloudSandbox(E2BCloudSandbox):
|
|
|
191
230
|
return ExecutionResult.create(
|
|
192
231
|
status=status,
|
|
193
232
|
code=code,
|
|
194
|
-
stdout=(execution.logs.stdout
|
|
195
|
-
stderr=(execution.logs.stderr
|
|
233
|
+
stdout=("\n".join(execution.logs.stdout) if execution.logs and execution.logs.stdout else ""),
|
|
234
|
+
stderr=("\n".join(execution.logs.stderr) if execution.logs and execution.logs.stderr else ""),
|
|
196
235
|
error=(str(execution.error) if execution.error else ""), # Convert to string here
|
|
197
236
|
duration_ms=duration_ms,
|
|
198
237
|
)
|
|
@@ -218,8 +257,8 @@ class MyE2BCloudSandbox(E2BCloudSandbox):
|
|
|
218
257
|
def download_file(self, file_path: str) -> bytes | None:
|
|
219
258
|
"""Download file content from the sandbox.
|
|
220
259
|
|
|
221
|
-
Uses download_url
|
|
222
|
-
|
|
260
|
+
Uses download_url when available to avoid binary corruption issues.
|
|
261
|
+
Falls back to the filesystem API when download_url fails or is unavailable.
|
|
223
262
|
|
|
224
263
|
Args:
|
|
225
264
|
file_path (str): Path to the file in the sandbox.
|
|
@@ -237,18 +276,28 @@ class MyE2BCloudSandbox(E2BCloudSandbox):
|
|
|
237
276
|
if hasattr(self.sandbox, "download_url"):
|
|
238
277
|
logger.info(f"Downloading {file_path} via download_url method")
|
|
239
278
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
response = requests.get(url, timeout=30)
|
|
245
|
-
|
|
246
|
-
if response.status_code == HTTPStatus.OK:
|
|
247
|
-
content = response.content
|
|
248
|
-
logger.info(f"Successfully downloaded {len(content)} bytes via URL")
|
|
249
|
-
return content
|
|
279
|
+
try:
|
|
280
|
+
url = self.sandbox.download_url(file_path)
|
|
281
|
+
except Exception as e:
|
|
282
|
+
logger.warning(f"Failed to get download URL: {str(e)}")
|
|
250
283
|
else:
|
|
251
|
-
logger.
|
|
284
|
+
logger.debug(f"Got download URL: {url}")
|
|
285
|
+
|
|
286
|
+
try:
|
|
287
|
+
response = requests.get(url, timeout=30)
|
|
288
|
+
except Exception as e:
|
|
289
|
+
logger.warning(f"URL download failed with error: {str(e)}")
|
|
290
|
+
else:
|
|
291
|
+
if response.status_code == HTTPStatus.OK:
|
|
292
|
+
content = response.content
|
|
293
|
+
logger.info(f"Successfully downloaded {len(content)} bytes via URL")
|
|
294
|
+
return content
|
|
295
|
+
logger.warning(f"URL download failed with status {response.status_code}")
|
|
296
|
+
|
|
297
|
+
if self.files:
|
|
298
|
+
logger.info(f"Downloading {file_path} via filesystem API")
|
|
299
|
+
content = self.files.read(file_path, format="bytes")
|
|
300
|
+
return bytes(content)
|
|
252
301
|
|
|
253
302
|
return None
|
|
254
303
|
|
|
@@ -2,7 +2,7 @@ from _typeshed import Incomplete
|
|
|
2
2
|
from aip_agents.tools.code_sandbox.constant import DATA_FILE_PATH as DATA_FILE_PATH
|
|
3
3
|
from aip_agents.utils.logger import get_logger as get_logger
|
|
4
4
|
from gllm_inference.schema import Attachment as Attachment
|
|
5
|
-
from gllm_tools.code_interpreter.code_sandbox.
|
|
5
|
+
from gllm_tools.code_interpreter.code_sandbox.e2b_sandbox import E2BSandbox
|
|
6
6
|
from gllm_tools.code_interpreter.code_sandbox.models import ExecutionResult
|
|
7
7
|
from typing import Any
|
|
8
8
|
|
|
@@ -34,15 +34,31 @@ class SandboxFileWatcher:
|
|
|
34
34
|
list[str]: List of file paths that were created.
|
|
35
35
|
"""
|
|
36
36
|
|
|
37
|
-
class MyE2BCloudSandbox(
|
|
38
|
-
"""Extended E2B
|
|
37
|
+
class MyE2BCloudSandbox(E2BSandbox):
|
|
38
|
+
"""Extended E2B sandbox with filesystem monitoring capabilities.
|
|
39
|
+
|
|
40
|
+
Use `create()` in production to build a fully initialized sandbox wrapper.
|
|
41
|
+
Direct construction is intentionally blocked to prevent partially initialized
|
|
42
|
+
instances that lack the underlying E2B sandbox clients.
|
|
43
|
+
"""
|
|
39
44
|
file_watcher: SandboxFileWatcher | None
|
|
40
|
-
def __init__(self,
|
|
41
|
-
"""Initialize the sandbox
|
|
45
|
+
def __init__(self, language: str = 'python', *, _unsafe_allow_init: bool = False) -> None:
|
|
46
|
+
"""Initialize the sandbox wrapper.
|
|
42
47
|
|
|
43
48
|
Args:
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
language (str): Language to execute inside the sandbox.
|
|
50
|
+
_unsafe_allow_init (bool): Escape hatch for tests/mocks only.
|
|
51
|
+
|
|
52
|
+
Raises:
|
|
53
|
+
RuntimeError: When instantiated directly without `create()`.
|
|
54
|
+
"""
|
|
55
|
+
@classmethod
|
|
56
|
+
async def create(cls, api_key: str, domain: str | None = None, template: str | None = None, language: str = 'python', additional_packages: list[str] | None = None, **kwargs: Any) -> MyE2BCloudSandbox:
|
|
57
|
+
"""Create a fully initialized sandbox wrapper.
|
|
58
|
+
|
|
59
|
+
This is the supported construction path for production usage. It wires
|
|
60
|
+
the E2B sandbox instance and its filesystem/command clients, then
|
|
61
|
+
installs language dependencies.
|
|
46
62
|
"""
|
|
47
63
|
async def execute_code(self, code: str, timeout: int = 30, files: list[Attachment] | None = None, **kwargs: Any) -> ExecutionResult:
|
|
48
64
|
"""Execute code in the E2B Cloud sandbox with filesystem monitoring.
|
|
@@ -72,8 +88,8 @@ class MyE2BCloudSandbox(E2BCloudSandbox):
|
|
|
72
88
|
def download_file(self, file_path: str) -> bytes | None:
|
|
73
89
|
"""Download file content from the sandbox.
|
|
74
90
|
|
|
75
|
-
Uses download_url
|
|
76
|
-
|
|
91
|
+
Uses download_url when available to avoid binary corruption issues.
|
|
92
|
+
Falls back to the filesystem API when download_url fails or is unavailable.
|
|
77
93
|
|
|
78
94
|
Args:
|
|
79
95
|
file_path (str): Path to the file in the sandbox.
|
|
@@ -12,7 +12,7 @@ from typing import Any
|
|
|
12
12
|
|
|
13
13
|
import pandas as pd
|
|
14
14
|
from gllm_inference.schema import Attachment
|
|
15
|
-
from gllm_tools.code_interpreter.code_sandbox.
|
|
15
|
+
from gllm_tools.code_interpreter.code_sandbox.sandbox import BaseSandbox
|
|
16
16
|
from langchain_core.tools import BaseTool
|
|
17
17
|
from langgraph.types import Command
|
|
18
18
|
from pydantic import BaseModel, Field
|
|
@@ -260,7 +260,7 @@ class E2BCodeSandboxTool(BaseTool):
|
|
|
260
260
|
"""
|
|
261
261
|
unique_packages = self._prepare_packages(additional_packages)
|
|
262
262
|
|
|
263
|
-
return MyE2BCloudSandbox(
|
|
263
|
+
return await MyE2BCloudSandbox.create(
|
|
264
264
|
api_key=self.api_key,
|
|
265
265
|
language=language,
|
|
266
266
|
additional_packages=unique_packages,
|
|
@@ -304,11 +304,11 @@ class E2BCodeSandboxTool(BaseTool):
|
|
|
304
304
|
except Exception as e:
|
|
305
305
|
logger.warning(f"Error terminating sandbox: {str(e)}")
|
|
306
306
|
|
|
307
|
-
def _create_artifacts_from_files(self, sandbox:
|
|
307
|
+
def _create_artifacts_from_files(self, sandbox: BaseSandbox, file_paths: list[str]) -> list[dict[str, Any]]:
|
|
308
308
|
"""Create artifacts from a list of file paths using ArtifactHandler.
|
|
309
309
|
|
|
310
310
|
Args:
|
|
311
|
-
sandbox (
|
|
311
|
+
sandbox (BaseSandbox): The active sandbox instance.
|
|
312
312
|
file_paths (list[str]): List of file paths to download.
|
|
313
313
|
|
|
314
314
|
Returns:
|
|
@@ -358,11 +358,11 @@ class E2BCodeSandboxTool(BaseTool):
|
|
|
358
358
|
|
|
359
359
|
return execution_summary
|
|
360
360
|
|
|
361
|
-
def _download_and_create_artifact(self, sandbox:
|
|
361
|
+
def _download_and_create_artifact(self, sandbox: BaseSandbox, file_path: str) -> dict[str, Any] | None:
|
|
362
362
|
"""Download a single file and create an artifact using ArtifactHandler.
|
|
363
363
|
|
|
364
364
|
Args:
|
|
365
|
-
sandbox (
|
|
365
|
+
sandbox (BaseSandbox): The active sandbox instance.
|
|
366
366
|
file_path (str): Path to the file in the sandbox.
|
|
367
367
|
|
|
368
368
|
Returns:
|
aip_agents/tools/constants.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Constants for tools using
|
|
1
|
+
"""Constants for tools using GL Connectors.
|
|
2
2
|
|
|
3
3
|
Authors:
|
|
4
4
|
Saul Sayers (saul.sayers@gdplabs.id)
|
|
@@ -7,20 +7,32 @@ Authors:
|
|
|
7
7
|
import os
|
|
8
8
|
from enum import Enum, StrEnum
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
GL_CONNECTORS_BASE_URL = (
|
|
11
|
+
os.getenv("GL_CONNECTORS_BASE_URL")
|
|
12
|
+
or os.getenv("GL_CONNECTORS_API_BASE_URL")
|
|
13
|
+
or os.getenv("BOSA_API_BASE_URL")
|
|
14
|
+
or os.getenv("BOSA_BASE_URL")
|
|
15
|
+
)
|
|
16
|
+
GL_CONNECTORS_API_KEY = os.getenv("GL_CONNECTORS_API_KEY") or os.getenv("BOSA_API_KEY")
|
|
17
|
+
GL_CONNECTORS_FETCH_MAX_RETRIES = int(
|
|
18
|
+
os.getenv("GL_CONNECTORS_FETCH_MAX_RETRIES") or os.getenv("BOSA_FETCH_MAX_RETRIES") or 3
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
# For backward compatibility
|
|
22
|
+
BOSA_API_BASE_URL = GL_CONNECTORS_BASE_URL
|
|
23
|
+
BOSA_API_KEY = GL_CONNECTORS_API_KEY
|
|
24
|
+
BOSA_FETCH_MAX_RETRIES = GL_CONNECTORS_FETCH_MAX_RETRIES
|
|
13
25
|
|
|
14
26
|
|
|
15
27
|
class ToolType(StrEnum):
|
|
16
|
-
"""Tool types for
|
|
28
|
+
"""Tool types for GL Connectors."""
|
|
17
29
|
|
|
18
30
|
GLLM = "gllm"
|
|
19
31
|
LANGCHAIN = "langchain"
|
|
20
32
|
|
|
21
33
|
|
|
22
34
|
class Action(Enum):
|
|
23
|
-
"""Actions for
|
|
35
|
+
"""Actions for GL Connectors."""
|
|
24
36
|
|
|
25
37
|
GITHUB = "github"
|
|
26
38
|
GOOGLE = "google"
|
|
@@ -30,7 +42,7 @@ class Action(Enum):
|
|
|
30
42
|
|
|
31
43
|
|
|
32
44
|
class GitHubEndpoint(Enum):
|
|
33
|
-
"""GitHub endpoints for
|
|
45
|
+
"""GitHub endpoints for GL Connectors."""
|
|
34
46
|
|
|
35
47
|
INTEGRATIONS = "integrations"
|
|
36
48
|
USER_HAS_INTEGRATION = "integration-exists"
|
|
@@ -59,7 +71,7 @@ class GitHubEndpoint(Enum):
|
|
|
59
71
|
|
|
60
72
|
|
|
61
73
|
class GoogleDriveEndpoint(Enum):
|
|
62
|
-
"""Google Drive endpoints for
|
|
74
|
+
"""Google Drive endpoints for GL Connectors."""
|
|
63
75
|
|
|
64
76
|
INTEGRATIONS = "integrations"
|
|
65
77
|
USER_HAS_INTEGRATION = "integration-exists"
|
|
@@ -84,7 +96,7 @@ class GoogleDriveEndpoint(Enum):
|
|
|
84
96
|
|
|
85
97
|
|
|
86
98
|
class GoogleDocsEndpoint(Enum):
|
|
87
|
-
"""Google Docs endpoints for
|
|
99
|
+
"""Google Docs endpoints for GL Connectors."""
|
|
88
100
|
|
|
89
101
|
INTEGRATIONS = "integrations"
|
|
90
102
|
USER_HAS_INTEGRATION = "integration-exists"
|
|
@@ -100,7 +112,7 @@ class GoogleDocsEndpoint(Enum):
|
|
|
100
112
|
|
|
101
113
|
|
|
102
114
|
class GoogleEndpoint(Enum):
|
|
103
|
-
"""Google endpoints for
|
|
115
|
+
"""Google endpoints for GL Connectors."""
|
|
104
116
|
|
|
105
117
|
INTEGRATIONS = "integrations"
|
|
106
118
|
USER_HAS_INTEGRATION = "integration-exists"
|
|
@@ -109,7 +121,7 @@ class GoogleEndpoint(Enum):
|
|
|
109
121
|
|
|
110
122
|
|
|
111
123
|
class TwitterEndpoint(Enum):
|
|
112
|
-
"""Twitter endpoints for
|
|
124
|
+
"""Twitter endpoints for GL Connectors."""
|
|
113
125
|
|
|
114
126
|
INTEGRATIONS = "integrations"
|
|
115
127
|
USER_HAS_INTEGRATION = "integration-exists"
|
|
@@ -121,7 +133,7 @@ class TwitterEndpoint(Enum):
|
|
|
121
133
|
|
|
122
134
|
|
|
123
135
|
class GoogleMailEndpoint(Enum):
|
|
124
|
-
"""Google Mail endpoints for
|
|
136
|
+
"""Google Mail endpoints for GL Connectors."""
|
|
125
137
|
|
|
126
138
|
INTEGRATIONS = "integrations"
|
|
127
139
|
USER_HAS_INTEGRATION = "integration-exists"
|
aip_agents/tools/constants.pyi
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
from _typeshed import Incomplete
|
|
2
2
|
from enum import Enum, StrEnum
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
GL_CONNECTORS_BASE_URL: Incomplete
|
|
5
|
+
GL_CONNECTORS_API_KEY: Incomplete
|
|
6
|
+
GL_CONNECTORS_FETCH_MAX_RETRIES: Incomplete
|
|
7
|
+
BOSA_API_BASE_URL = GL_CONNECTORS_BASE_URL
|
|
8
|
+
BOSA_API_KEY = GL_CONNECTORS_API_KEY
|
|
9
|
+
BOSA_FETCH_MAX_RETRIES = GL_CONNECTORS_FETCH_MAX_RETRIES
|
|
7
10
|
|
|
8
11
|
class ToolType(StrEnum):
|
|
9
|
-
"""Tool types for
|
|
12
|
+
"""Tool types for GL Connectors."""
|
|
10
13
|
GLLM: str
|
|
11
14
|
LANGCHAIN: str
|
|
12
15
|
|
|
13
16
|
class Action(Enum):
|
|
14
|
-
"""Actions for
|
|
17
|
+
"""Actions for GL Connectors."""
|
|
15
18
|
GITHUB: str
|
|
16
19
|
GOOGLE: str
|
|
17
20
|
GOOGLE_DRIVE: str
|
|
@@ -19,7 +22,7 @@ class Action(Enum):
|
|
|
19
22
|
TWITTER: str
|
|
20
23
|
|
|
21
24
|
class GitHubEndpoint(Enum):
|
|
22
|
-
"""GitHub endpoints for
|
|
25
|
+
"""GitHub endpoints for GL Connectors."""
|
|
23
26
|
INTEGRATIONS: str
|
|
24
27
|
USER_HAS_INTEGRATION: str
|
|
25
28
|
SUCCESS_AUTHORIZE_CALLBACK: str
|
|
@@ -46,7 +49,7 @@ class GitHubEndpoint(Enum):
|
|
|
46
49
|
LIST_PROJECTS: str
|
|
47
50
|
|
|
48
51
|
class GoogleDriveEndpoint(Enum):
|
|
49
|
-
"""Google Drive endpoints for
|
|
52
|
+
"""Google Drive endpoints for GL Connectors."""
|
|
50
53
|
INTEGRATIONS: str
|
|
51
54
|
USER_HAS_INTEGRATION: str
|
|
52
55
|
SUCCESS_AUTHORIZE_CALLBACK: str
|
|
@@ -69,7 +72,7 @@ class GoogleDriveEndpoint(Enum):
|
|
|
69
72
|
DOWNLOAD_FILE: str
|
|
70
73
|
|
|
71
74
|
class GoogleDocsEndpoint(Enum):
|
|
72
|
-
"""Google Docs endpoints for
|
|
75
|
+
"""Google Docs endpoints for GL Connectors."""
|
|
73
76
|
INTEGRATIONS: str
|
|
74
77
|
USER_HAS_INTEGRATION: str
|
|
75
78
|
SUCCESS_AUTHORIZE_CALLBACK: str
|
|
@@ -83,14 +86,14 @@ class GoogleDocsEndpoint(Enum):
|
|
|
83
86
|
SUMMARIZE_COMMENTS: str
|
|
84
87
|
|
|
85
88
|
class GoogleEndpoint(Enum):
|
|
86
|
-
"""Google endpoints for
|
|
89
|
+
"""Google endpoints for GL Connectors."""
|
|
87
90
|
INTEGRATIONS: str
|
|
88
91
|
USER_HAS_INTEGRATION: str
|
|
89
92
|
SUCCESS_AUTHORIZE_CALLBACK: str
|
|
90
93
|
USERINFO: str
|
|
91
94
|
|
|
92
95
|
class TwitterEndpoint(Enum):
|
|
93
|
-
"""Twitter endpoints for
|
|
96
|
+
"""Twitter endpoints for GL Connectors."""
|
|
94
97
|
INTEGRATIONS: str
|
|
95
98
|
USER_HAS_INTEGRATION: str
|
|
96
99
|
SUCCESS_AUTHORIZE_CALLBACK: str
|
|
@@ -100,7 +103,7 @@ class TwitterEndpoint(Enum):
|
|
|
100
103
|
GET_USERS: str
|
|
101
104
|
|
|
102
105
|
class GoogleMailEndpoint(Enum):
|
|
103
|
-
"""Google Mail endpoints for
|
|
106
|
+
"""Google Mail endpoints for GL Connectors."""
|
|
104
107
|
INTEGRATIONS: str
|
|
105
108
|
USER_HAS_INTEGRATION: str
|
|
106
109
|
SUCCESS_AUTHORIZE_CALLBACK: str
|