managed-deepagents 0.9.0.dev3__py3-none-win_amd64.whl → 0.9.1.dev2__py3-none-win_amd64.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.
- managed_deepagents/_binaries/mda.exe +0 -0
- managed_deepagents/_connectors/mcp/langsmith_url.py +1 -1
- managed_deepagents/_connectors/mcp/load.py +46 -8
- managed_deepagents/_sandbox_proxy.py +13 -0
- managed_deepagents/runtime.py +161 -328
- {managed_deepagents-0.9.0.dev3.dist-info → managed_deepagents-0.9.1.dev2.dist-info}/METADATA +2 -2
- {managed_deepagents-0.9.0.dev3.dist-info → managed_deepagents-0.9.1.dev2.dist-info}/RECORD +11 -11
- {managed_deepagents-0.9.0.dev3.dist-info → managed_deepagents-0.9.1.dev2.dist-info}/WHEEL +0 -0
- {managed_deepagents-0.9.0.dev3.dist-info → managed_deepagents-0.9.1.dev2.dist-info}/entry_points.txt +0 -0
- {managed_deepagents-0.9.0.dev3.dist-info → managed_deepagents-0.9.1.dev2.dist-info}/licenses/LICENSE +0 -0
- {managed_deepagents-0.9.0.dev3.dist-info → managed_deepagents-0.9.1.dev2.dist-info}/top_level.txt +0 -0
|
Binary file
|
|
@@ -6,7 +6,7 @@ import re
|
|
|
6
6
|
from urllib.parse import ParseResult, urlparse
|
|
7
7
|
|
|
8
8
|
_LANGSMITH_MCP_PATH = re.compile(
|
|
9
|
-
r"^/v1/managed-tools/servers/[A-Za-z0-9][A-Za-z0-9_-]{0,127}/mcp/?$"
|
|
9
|
+
r"^/v1/managed-tools/(?:servers|gateways)/[A-Za-z0-9][A-Za-z0-9_-]{0,127}/mcp/?$"
|
|
10
10
|
)
|
|
11
11
|
_DEFAULT_PORT = {"http": 80, "https": 443}
|
|
12
12
|
|
|
@@ -247,8 +247,8 @@ def _resolve_langsmith_servers(
|
|
|
247
247
|
stacklevel=2,
|
|
248
248
|
)
|
|
249
249
|
continue
|
|
250
|
-
if required
|
|
251
|
-
pending.
|
|
250
|
+
if required:
|
|
251
|
+
pending.extend(required)
|
|
252
252
|
continue
|
|
253
253
|
out[server_name] = _langsmith_server_config(declared)
|
|
254
254
|
return out, pending
|
|
@@ -283,8 +283,11 @@ def _probe_langsmith_server_access(
|
|
|
283
283
|
server_name: str,
|
|
284
284
|
url: str,
|
|
285
285
|
headers: Mapping[str, str],
|
|
286
|
-
) -> PendingCredential
|
|
287
|
-
"""Return pending OAuth when LMT 428 is complete; raise for other auth gaps.
|
|
286
|
+
) -> list[PendingCredential]:
|
|
287
|
+
"""Return pending OAuth when LMT 428 is complete; raise for other auth gaps.
|
|
288
|
+
|
|
289
|
+
An empty list means the server is accessible.
|
|
290
|
+
"""
|
|
288
291
|
status, payload = request_agent_auth_json(
|
|
289
292
|
"POST",
|
|
290
293
|
url,
|
|
@@ -293,10 +296,13 @@ def _probe_langsmith_server_access(
|
|
|
293
296
|
timeout=AGENT_AUTH_TIMEOUT_SECONDS,
|
|
294
297
|
)
|
|
295
298
|
if status != HTTPStatus.PRECONDITION_REQUIRED:
|
|
296
|
-
return
|
|
299
|
+
return []
|
|
300
|
+
credentials = payload.get("credentials")
|
|
301
|
+
if isinstance(credentials, list):
|
|
302
|
+
return _pending_credentials_from_langsmith_gateway_428(credentials, server_name)
|
|
297
303
|
pending = _oauth_pending_credential_from_langsmith_428(payload, provider=server_name)
|
|
298
304
|
if pending is not None:
|
|
299
|
-
return pending
|
|
305
|
+
return [pending]
|
|
300
306
|
# Secret / incomplete 428s: do not guess kind. Point the caller at Tools.
|
|
301
307
|
verification_url = payload.get("verification_url")
|
|
302
308
|
if isinstance(verification_url, str) and verification_url:
|
|
@@ -310,6 +316,36 @@ def _probe_langsmith_server_access(
|
|
|
310
316
|
)
|
|
311
317
|
|
|
312
318
|
|
|
319
|
+
def _pending_credentials_from_langsmith_gateway_428(
|
|
320
|
+
credentials: list[object],
|
|
321
|
+
server_name: str,
|
|
322
|
+
) -> list[PendingCredential]:
|
|
323
|
+
"""Map every OAuth entry of a gateway 428 to an interrupt credential.
|
|
324
|
+
|
|
325
|
+
Secret entries cannot be completed from an interrupt, so any of them raise
|
|
326
|
+
with every missing name before an interrupt is shown.
|
|
327
|
+
"""
|
|
328
|
+
pending: list[PendingCredential] = []
|
|
329
|
+
unresolved: list[str] = []
|
|
330
|
+
for entry in credentials:
|
|
331
|
+
if not isinstance(entry, Mapping):
|
|
332
|
+
unresolved.append(server_name)
|
|
333
|
+
continue
|
|
334
|
+
credential = _oauth_pending_credential_from_langsmith_428(entry, provider=server_name)
|
|
335
|
+
if credential is not None:
|
|
336
|
+
pending.append(credential)
|
|
337
|
+
continue
|
|
338
|
+
label = entry.get("display_name") or entry.get("slug")
|
|
339
|
+
unresolved.append(label if isinstance(label, str) and label else server_name)
|
|
340
|
+
if unresolved or not pending:
|
|
341
|
+
names = ", ".join(unresolved) if unresolved else server_name
|
|
342
|
+
raise RuntimeError(
|
|
343
|
+
f'LangSmith MCP server "{server_name}" requires credentials for {names}; '
|
|
344
|
+
"connect them in LangSmith Tools before running the agent"
|
|
345
|
+
)
|
|
346
|
+
return pending
|
|
347
|
+
|
|
348
|
+
|
|
313
349
|
def _oauth_pending_credential_from_langsmith_428(
|
|
314
350
|
payload: Mapping[str, object],
|
|
315
351
|
*,
|
|
@@ -319,7 +355,8 @@ def _oauth_pending_credential_from_langsmith_428(
|
|
|
319
355
|
|
|
320
356
|
Secret and other auth modes are intentionally not inferred from missing
|
|
321
357
|
fields; wait for an explicit wire contract before interrupting those.
|
|
322
|
-
``provider`` is the MCP server key for Slack/Studio display labels
|
|
358
|
+
``provider`` is the MCP server key, used for Slack/Studio display labels
|
|
359
|
+
when LMT does not return ``display_name``.
|
|
323
360
|
"""
|
|
324
361
|
verification_url = payload.get("verification_url")
|
|
325
362
|
auth_id = payload.get("auth_id")
|
|
@@ -333,12 +370,13 @@ def _oauth_pending_credential_from_langsmith_428(
|
|
|
333
370
|
and slug
|
|
334
371
|
):
|
|
335
372
|
return None
|
|
373
|
+
display_name = payload.get("display_name")
|
|
336
374
|
return {
|
|
337
375
|
"slug": slug,
|
|
338
376
|
"kind": "oauth2",
|
|
339
377
|
"connect_url": verification_url,
|
|
340
378
|
"auth_id": auth_id,
|
|
341
|
-
"provider": provider,
|
|
379
|
+
"provider": display_name if isinstance(display_name, str) and display_name else provider,
|
|
342
380
|
}
|
|
343
381
|
|
|
344
382
|
|
|
@@ -10,6 +10,7 @@ import json
|
|
|
10
10
|
import os
|
|
11
11
|
from collections.abc import Coroutine, Mapping
|
|
12
12
|
from concurrent.futures import ThreadPoolExecutor
|
|
13
|
+
from http import HTTPStatus
|
|
13
14
|
from importlib import import_module
|
|
14
15
|
from typing import TYPE_CHECKING, cast
|
|
15
16
|
from urllib.parse import quote
|
|
@@ -145,6 +146,8 @@ def run_sync(coroutine: Coroutine[object, object, None]) -> None:
|
|
|
145
146
|
def patch_sandbox_proxy_config(
|
|
146
147
|
sandbox: SandboxDefinition, name: str, config: dict[str, object]
|
|
147
148
|
) -> None:
|
|
149
|
+
from langsmith.sandbox import ResourceNotFoundError # noqa: PLC0415
|
|
150
|
+
|
|
148
151
|
from managed_deepagents.runtime import _sandbox_client_kwargs # noqa: PLC0415
|
|
149
152
|
|
|
150
153
|
kwargs = _sandbox_client_kwargs(sandbox)
|
|
@@ -167,6 +170,10 @@ def patch_sandbox_proxy_config(
|
|
|
167
170
|
)
|
|
168
171
|
except Exception: # noqa: BLE001 — omit secret-bearing transport causes
|
|
169
172
|
raise RuntimeError("Could not update sandbox proxy credentials.") from None
|
|
173
|
+
if response.status_code == HTTPStatus.NOT_FOUND:
|
|
174
|
+
raise ResourceNotFoundError(
|
|
175
|
+
"Could not update sandbox proxy credentials.", "sandbox"
|
|
176
|
+
) from None
|
|
170
177
|
if not response.is_success:
|
|
171
178
|
raise RuntimeError("Could not update sandbox proxy credentials.")
|
|
172
179
|
|
|
@@ -187,6 +194,8 @@ class SandboxProxyConfigSync:
|
|
|
187
194
|
async def sync(
|
|
188
195
|
self, sandbox: SandboxDefinition, name: str | None, config: Mapping[str, object] | None
|
|
189
196
|
) -> None:
|
|
197
|
+
from langsmith.sandbox import ResourceNotFoundError # noqa: PLC0415
|
|
198
|
+
|
|
190
199
|
template = sandbox.options.get("proxy_config")
|
|
191
200
|
if template is None:
|
|
192
201
|
return
|
|
@@ -198,6 +207,10 @@ class SandboxProxyConfigSync:
|
|
|
198
207
|
return
|
|
199
208
|
try:
|
|
200
209
|
await asyncio.to_thread(patch_sandbox_proxy_config, sandbox, name, wire)
|
|
210
|
+
except ResourceNotFoundError:
|
|
211
|
+
raise ResourceNotFoundError(
|
|
212
|
+
"Could not update sandbox proxy credentials.", "sandbox"
|
|
213
|
+
) from None
|
|
201
214
|
except Exception: # noqa: BLE001 — omit secret-bearing transport causes
|
|
202
215
|
raise RuntimeError("Could not update sandbox proxy credentials.") from None
|
|
203
216
|
self._hashes[name] = digest
|
managed_deepagents/runtime.py
CHANGED
|
@@ -22,6 +22,7 @@ import threading
|
|
|
22
22
|
import time
|
|
23
23
|
from collections.abc import Callable, Iterable, Mapping
|
|
24
24
|
from functools import partial
|
|
25
|
+
from http import HTTPStatus
|
|
25
26
|
from typing import TYPE_CHECKING, Any, Literal, Protocol, TypedDict, cast
|
|
26
27
|
|
|
27
28
|
from deepagents import FilesystemPermission, create_deep_agent
|
|
@@ -127,18 +128,6 @@ class _Omitted:
|
|
|
127
128
|
|
|
128
129
|
_OMITTED = _Omitted()
|
|
129
130
|
|
|
130
|
-
# Cold-box race: command stream died before the sandbox accepted the command.
|
|
131
|
-
_STREAM_NEVER_STARTED_RE = re.compile(
|
|
132
|
-
r"Command stream ended before ['\"]started['\"] message",
|
|
133
|
-
flags=re.IGNORECASE,
|
|
134
|
-
)
|
|
135
|
-
_STREAM_NEVER_STARTED_TYPES = frozenset(
|
|
136
|
-
{
|
|
137
|
-
"_StreamEndedBeforeStarted",
|
|
138
|
-
"StreamEndedBeforeStarted",
|
|
139
|
-
}
|
|
140
|
-
)
|
|
141
|
-
|
|
142
131
|
if TYPE_CHECKING:
|
|
143
132
|
from deepagents.backends.protocol import BackendProtocol as DeepAgentsBackend
|
|
144
133
|
from deepagents.backends.protocol import FileDownloadResponse, FileUploadResponse
|
|
@@ -309,13 +298,16 @@ _SANDBOX_NAME_CONFLICT_RE = re.compile(
|
|
|
309
298
|
class _ManagedSandboxEntry:
|
|
310
299
|
"""Cached sandbox plus per-thread connector sandbox sync state."""
|
|
311
300
|
|
|
312
|
-
__slots__ = ("backend", "host_name", "synced_threads")
|
|
301
|
+
__slots__ = ("backend", "host_name", "sandbox_id", "synced_threads")
|
|
313
302
|
|
|
314
|
-
def __init__(
|
|
303
|
+
def __init__(
|
|
304
|
+
self, backend: object, host_name: str | None = None, sandbox_id: str | None = None
|
|
305
|
+
) -> None:
|
|
315
306
|
self.backend = backend
|
|
316
307
|
self.synced_threads: set[str] = set()
|
|
317
308
|
#: LangSmith box name for this entry (deterministic or unique-suffixed).
|
|
318
309
|
self.host_name = host_name
|
|
310
|
+
self.sandbox_id = sandbox_id
|
|
319
311
|
|
|
320
312
|
|
|
321
313
|
#: Created sandboxes, keyed by thread and any explicit dynamic selection,
|
|
@@ -351,13 +343,11 @@ def _peek_managed_host_name(key: str) -> str | None:
|
|
|
351
343
|
return entry.host_name if entry is not None else None
|
|
352
344
|
|
|
353
345
|
|
|
354
|
-
def _sandbox_create_kwargs(
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
and are not passed here.
|
|
360
|
-
"""
|
|
346
|
+
def _sandbox_create_kwargs(
|
|
347
|
+
sandbox: SandboxDefinition,
|
|
348
|
+
selection_fingerprint: str | None = None,
|
|
349
|
+
) -> dict[str, object]:
|
|
350
|
+
"""Options for ``create_sandbox``."""
|
|
361
351
|
create_kwargs = {
|
|
362
352
|
key: value
|
|
363
353
|
for key, value in sandbox.options.items()
|
|
@@ -375,27 +365,17 @@ def _sandbox_create_kwargs(sandbox: SandboxDefinition) -> dict[str, object]:
|
|
|
375
365
|
if "proxy_config" in create_kwargs:
|
|
376
366
|
create_kwargs["proxy_config"] = static_sandbox_proxy_config(create_kwargs["proxy_config"])
|
|
377
367
|
recipe = _string_option(os.environ.get(RECIPE_SNAPSHOT_ENV))
|
|
378
|
-
|
|
368
|
+
snapshot_id = sandbox.options.get("snapshot_id")
|
|
369
|
+
snapshot_name = sandbox.options.get("snapshot_name")
|
|
370
|
+
if selection_fingerprint and snapshot_id:
|
|
371
|
+
create_kwargs["snapshot_id"] = snapshot_id
|
|
372
|
+
elif selection_fingerprint and snapshot_name:
|
|
373
|
+
create_kwargs["snapshot_name"] = snapshot_name
|
|
374
|
+
elif recipe:
|
|
379
375
|
create_kwargs["snapshot_name"] = recipe
|
|
380
376
|
return create_kwargs
|
|
381
377
|
|
|
382
378
|
|
|
383
|
-
def _host_sandbox_names_for(
|
|
384
|
-
sandbox: SandboxDefinition,
|
|
385
|
-
config: ManagedRunConfig | Mapping[str, object] | None,
|
|
386
|
-
selection_fingerprint: str | None = None,
|
|
387
|
-
) -> list[str]:
|
|
388
|
-
"""Deterministic Host box names to adopt or invalidate for this thread."""
|
|
389
|
-
deployment = _managed_deployment_name()
|
|
390
|
-
if deployment is None:
|
|
391
|
-
return []
|
|
392
|
-
return _managed_sandbox_lookup_names(
|
|
393
|
-
deployment,
|
|
394
|
-
_thread_scope_key(config, selection_fingerprint),
|
|
395
|
-
sandbox,
|
|
396
|
-
)
|
|
397
|
-
|
|
398
|
-
|
|
399
379
|
def _sandbox_client_kwargs(sandbox: SandboxDefinition) -> dict[str, object]:
|
|
400
380
|
"""Client kwargs pinning the API key and the workspace holding the recipe."""
|
|
401
381
|
kwargs: dict[str, object] = {}
|
|
@@ -418,29 +398,6 @@ def _sandbox_client_for(sandbox: SandboxDefinition) -> object:
|
|
|
418
398
|
return sandbox_client_cls(**_sandbox_client_kwargs(sandbox))
|
|
419
399
|
|
|
420
400
|
|
|
421
|
-
def _delete_host_sandbox(sandbox: SandboxDefinition, name: str) -> None:
|
|
422
|
-
"""Best-effort Host delete so the next resolve cannot adopt a broken box."""
|
|
423
|
-
try:
|
|
424
|
-
client = _sandbox_client_for(sandbox)
|
|
425
|
-
delete_sandbox = getattr(client, "delete_sandbox", None)
|
|
426
|
-
if not callable(delete_sandbox):
|
|
427
|
-
return
|
|
428
|
-
_await_if_needed(delete_sandbox(name))
|
|
429
|
-
_LOG.info("[mda] sandbox invalidate: deleted name=%r", name)
|
|
430
|
-
except Exception as error: # noqa: BLE001 — recreate must proceed anyway
|
|
431
|
-
_LOG.warning(
|
|
432
|
-
"[mda] sandbox invalidate: delete failed name=%r err=%s: %s",
|
|
433
|
-
name,
|
|
434
|
-
type(error).__name__,
|
|
435
|
-
error,
|
|
436
|
-
)
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
def _block_sandbox_names(names: Iterable[str]) -> None:
|
|
440
|
-
with _managed_sandbox_lock:
|
|
441
|
-
_invalidated_sandbox_names.update(names)
|
|
442
|
-
|
|
443
|
-
|
|
444
401
|
def _sandbox_name_blocked(name: str) -> bool:
|
|
445
402
|
with _managed_sandbox_lock:
|
|
446
403
|
return name in _invalidated_sandbox_names
|
|
@@ -451,16 +408,6 @@ def _unblock_sandbox_name(name: str) -> None:
|
|
|
451
408
|
_invalidated_sandbox_names.discard(name)
|
|
452
409
|
|
|
453
410
|
|
|
454
|
-
def _backend_id(backend: object | None) -> str | None:
|
|
455
|
-
if backend is None:
|
|
456
|
-
return None
|
|
457
|
-
value = getattr(backend, "id", None)
|
|
458
|
-
if value is None:
|
|
459
|
-
return None
|
|
460
|
-
text = str(value).strip()
|
|
461
|
-
return text or None
|
|
462
|
-
|
|
463
|
-
|
|
464
411
|
def _sandbox_handle_name(handle: object) -> str | None:
|
|
465
412
|
"""Read ``name`` from an SDK sandbox handle (object or mapping)."""
|
|
466
413
|
name = _string_option(getattr(handle, "name", None))
|
|
@@ -482,115 +429,6 @@ def _sandbox_handle_id(handle: object) -> str | None:
|
|
|
482
429
|
return text or None
|
|
483
430
|
|
|
484
431
|
|
|
485
|
-
def _cache_entry_matches_expected(
|
|
486
|
-
entry: _ManagedSandboxEntry,
|
|
487
|
-
*,
|
|
488
|
-
expected_backend_id: str | None,
|
|
489
|
-
expected_host_name: str | None,
|
|
490
|
-
) -> bool:
|
|
491
|
-
"""True when ``entry`` is still the sandbox the caller failed on."""
|
|
492
|
-
if expected_backend_id is not None:
|
|
493
|
-
return _backend_id(entry.backend) == expected_backend_id
|
|
494
|
-
return expected_host_name is not None and entry.host_name == expected_host_name
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
def _invalidate_managed_sandbox( # noqa: C901
|
|
498
|
-
sandbox: SandboxDefinition,
|
|
499
|
-
config: ManagedRunConfig | Mapping[str, object] | None,
|
|
500
|
-
*,
|
|
501
|
-
expected_backend_id: str | None = None,
|
|
502
|
-
expected_host_name: str | None = None,
|
|
503
|
-
selection_fingerprint: str | None = None,
|
|
504
|
-
) -> None:
|
|
505
|
-
"""Drop a cached sandbox and delete its Host box so recreate cannot adopt it.
|
|
506
|
-
|
|
507
|
-
Process-cache clear alone is not enough under deploy: names are deterministic
|
|
508
|
-
per scope, so the next resolve would re-adopt the same broken box. Mark the
|
|
509
|
-
name blocked (delete can lag) and best-effort ``delete_sandbox``.
|
|
510
|
-
|
|
511
|
-
When ``expected_backend_id`` / ``expected_host_name`` are set, only pop the
|
|
512
|
-
cache entry if it still refers to that failing sandbox. A concurrent sibling
|
|
513
|
-
may already have replaced it — deleting the replacement would strand the
|
|
514
|
-
healthy recreate.
|
|
515
|
-
"""
|
|
516
|
-
key = _thread_scope_key(config, selection_fingerprint)
|
|
517
|
-
names: list[str] = []
|
|
518
|
-
has_expected = expected_backend_id is not None or expected_host_name is not None
|
|
519
|
-
# Take the per-key lock so we do not race an in-flight provisioner that
|
|
520
|
-
# would otherwise re-insert a box we just invalidated.
|
|
521
|
-
with _sandbox_key_lock(key), _managed_sandbox_lock:
|
|
522
|
-
entry = _managed_sandboxes.get(key)
|
|
523
|
-
if entry is not None and has_expected:
|
|
524
|
-
if _cache_entry_matches_expected(
|
|
525
|
-
entry,
|
|
526
|
-
expected_backend_id=expected_backend_id,
|
|
527
|
-
expected_host_name=expected_host_name,
|
|
528
|
-
):
|
|
529
|
-
entry = _managed_sandboxes.pop(key, None)
|
|
530
|
-
else:
|
|
531
|
-
# Safe to delete the failing box only when the replacement uses
|
|
532
|
-
# a different Host name (unique-suffix path).
|
|
533
|
-
if expected_host_name and entry.host_name and expected_host_name != entry.host_name:
|
|
534
|
-
names.append(expected_host_name)
|
|
535
|
-
entry = None
|
|
536
|
-
elif entry is not None:
|
|
537
|
-
entry = _managed_sandboxes.pop(key, None)
|
|
538
|
-
|
|
539
|
-
popped = entry is not None
|
|
540
|
-
if entry is not None and entry.host_name:
|
|
541
|
-
names.append(entry.host_name)
|
|
542
|
-
if expected_host_name and (popped or not has_expected):
|
|
543
|
-
names.append(expected_host_name)
|
|
544
|
-
if not has_expected:
|
|
545
|
-
# Failed before a resolved identity was captured (e.g. cold provision):
|
|
546
|
-
# delete the deterministic name so the next resolve cannot re-adopt it.
|
|
547
|
-
try:
|
|
548
|
-
extra = _host_sandbox_names_for(sandbox, config, selection_fingerprint)
|
|
549
|
-
except Exception: # noqa: BLE001 — still clear cache even if naming fails
|
|
550
|
-
extra = []
|
|
551
|
-
names.extend(extra)
|
|
552
|
-
unique_names = list(dict.fromkeys(names))
|
|
553
|
-
if not unique_names:
|
|
554
|
-
return
|
|
555
|
-
|
|
556
|
-
_block_sandbox_names(unique_names)
|
|
557
|
-
for name in unique_names:
|
|
558
|
-
_delete_host_sandbox(sandbox, name)
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
def _is_sandbox_stream_error(error: object) -> bool:
|
|
562
|
-
"""True when execute failed before the sandbox accepted the command.
|
|
563
|
-
|
|
564
|
-
Matches only the cold-box readiness race (named error or message). Ambiguous
|
|
565
|
-
stream/transport errors may have already started a command — those belong on
|
|
566
|
-
other recreate matchers, not this classifier.
|
|
567
|
-
"""
|
|
568
|
-
if type(error).__name__ in _STREAM_NEVER_STARTED_TYPES:
|
|
569
|
-
return True
|
|
570
|
-
message = f"{type(error).__name__}: {error}"
|
|
571
|
-
return bool(_STREAM_NEVER_STARTED_RE.search(message))
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
def _is_transient_sandbox_error(error: object) -> bool:
|
|
575
|
-
"""True when a sandbox API error is worth invalidating + recreating once."""
|
|
576
|
-
# Never-started stream race is recreate-safe. Truncated HTTP bodies and
|
|
577
|
-
# peer-closed errors are recreate-only as well.
|
|
578
|
-
if _is_sandbox_stream_error(error):
|
|
579
|
-
return True
|
|
580
|
-
message = f"{type(error).__name__}: {error}"
|
|
581
|
-
return bool(
|
|
582
|
-
re.search(
|
|
583
|
-
r"LangSmithSandboxError|HTTP 502|Bad Gateway|HTTP 503|HTTP 504|"
|
|
584
|
-
r"ECONNRESET|ETIMEDOUT|"
|
|
585
|
-
r"peer closed connection without sending complete message body|"
|
|
586
|
-
r"incomplete chunked read|"
|
|
587
|
-
r"sandbox.*(not found|gone|unavailable|terminated)",
|
|
588
|
-
message,
|
|
589
|
-
flags=re.IGNORECASE,
|
|
590
|
-
)
|
|
591
|
-
)
|
|
592
|
-
|
|
593
|
-
|
|
594
432
|
(SandboxClient,) = _optional_runtime_symbols("langsmith.sandbox", "SandboxClient")
|
|
595
433
|
|
|
596
434
|
|
|
@@ -1595,8 +1433,6 @@ def _managed_sandbox_backend( # noqa: C901
|
|
|
1595
1433
|
def __init__(self, bound_configurable: Mapping[str, object] | None) -> None:
|
|
1596
1434
|
self._bound_configurable = bound_configurable
|
|
1597
1435
|
self._resolved_backend: ResolvedSandboxBackend | None = None
|
|
1598
|
-
self._resolved_host_name: str | None = None
|
|
1599
|
-
self._recreated_after_transient = False
|
|
1600
1436
|
|
|
1601
1437
|
def bind_runtime(self, runtime: object) -> _LazyManagedSandboxBackend:
|
|
1602
1438
|
"""Capture this run's configuration without resolving the sandbox."""
|
|
@@ -1621,15 +1457,13 @@ def _managed_sandbox_backend( # noqa: C901
|
|
|
1621
1457
|
return "pending:sandbox"
|
|
1622
1458
|
|
|
1623
1459
|
def ls(self, path: str = "/") -> object:
|
|
1624
|
-
return self.
|
|
1460
|
+
return self._call("ls", path)
|
|
1625
1461
|
|
|
1626
1462
|
async def als(self, path: str = "/") -> object:
|
|
1627
1463
|
return await self._acall("als", path)
|
|
1628
1464
|
|
|
1629
1465
|
def read(self, file_path: str, offset: int = 0, limit: int = 2000) -> object:
|
|
1630
|
-
return self.
|
|
1631
|
-
lambda: self._backend().read(file_path, offset=offset, limit=limit)
|
|
1632
|
-
)
|
|
1466
|
+
return self._call("read", file_path, offset=offset, limit=limit)
|
|
1633
1467
|
|
|
1634
1468
|
async def aread(self, file_path: str, offset: int = 0, limit: int = 2000) -> object:
|
|
1635
1469
|
return await self._acall("aread", file_path, offset, limit)
|
|
@@ -1643,10 +1477,8 @@ def _managed_sandbox_backend( # noqa: C901
|
|
|
1643
1477
|
max_count: int | None = None,
|
|
1644
1478
|
) -> object:
|
|
1645
1479
|
if max_count is not None:
|
|
1646
|
-
return self.
|
|
1647
|
-
|
|
1648
|
-
)
|
|
1649
|
-
return self._with_sandbox_retry(lambda: self._backend().grep(pattern, path, glob))
|
|
1480
|
+
return self._call("grep", pattern, path, glob, max_count=max_count)
|
|
1481
|
+
return self._call("grep", pattern, path, glob)
|
|
1650
1482
|
|
|
1651
1483
|
async def agrep(
|
|
1652
1484
|
self,
|
|
@@ -1664,7 +1496,7 @@ def _managed_sandbox_backend( # noqa: C901
|
|
|
1664
1496
|
# Refuse before resolving: a root glob is never worth creating a sandbox for.
|
|
1665
1497
|
if _is_filesystem_root(path):
|
|
1666
1498
|
return _root_glob_refusal()
|
|
1667
|
-
return self.
|
|
1499
|
+
return self._call("glob", pattern, path)
|
|
1668
1500
|
|
|
1669
1501
|
async def aglob(self, pattern: str, path: str | None = None) -> object:
|
|
1670
1502
|
if _is_filesystem_root(path):
|
|
@@ -1672,7 +1504,7 @@ def _managed_sandbox_backend( # noqa: C901
|
|
|
1672
1504
|
return await self._acall("aglob", pattern, path)
|
|
1673
1505
|
|
|
1674
1506
|
def write(self, file_path: str, content: str) -> object:
|
|
1675
|
-
return self.
|
|
1507
|
+
return self._call("write", file_path, content)
|
|
1676
1508
|
|
|
1677
1509
|
async def awrite(self, file_path: str, content: str) -> object:
|
|
1678
1510
|
return await self._acall("awrite", file_path, content)
|
|
@@ -1684,13 +1516,12 @@ def _managed_sandbox_backend( # noqa: C901
|
|
|
1684
1516
|
new_string: str,
|
|
1685
1517
|
replace_all: bool = False,
|
|
1686
1518
|
) -> object:
|
|
1687
|
-
return self.
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
)
|
|
1519
|
+
return self._call(
|
|
1520
|
+
"edit",
|
|
1521
|
+
file_path,
|
|
1522
|
+
old_string,
|
|
1523
|
+
new_string,
|
|
1524
|
+
replace_all=replace_all,
|
|
1694
1525
|
)
|
|
1695
1526
|
|
|
1696
1527
|
async def aedit(
|
|
@@ -1709,49 +1540,30 @@ def _managed_sandbox_backend( # noqa: C901
|
|
|
1709
1540
|
)
|
|
1710
1541
|
|
|
1711
1542
|
def delete(self, file_path: str) -> object:
|
|
1712
|
-
return self.
|
|
1543
|
+
return self._call("delete", file_path)
|
|
1713
1544
|
|
|
1714
1545
|
async def adelete(self, file_path: str) -> object:
|
|
1715
1546
|
return await self._acall("adelete", file_path)
|
|
1716
1547
|
|
|
1717
1548
|
def upload_files(self, files: list[tuple[str, bytes]]) -> list[FileUploadResponse]:
|
|
1718
|
-
return cast(
|
|
1719
|
-
"list[FileUploadResponse]",
|
|
1720
|
-
self._with_sandbox_retry(lambda: self._backend().upload_files(files)),
|
|
1721
|
-
)
|
|
1549
|
+
return cast("list[FileUploadResponse]", self._call("upload_files", files))
|
|
1722
1550
|
|
|
1723
1551
|
async def aupload_files(self, files: list[tuple[str, bytes]]) -> list[FileUploadResponse]:
|
|
1724
1552
|
return cast("list[FileUploadResponse]", await self._acall("aupload_files", files))
|
|
1725
1553
|
|
|
1726
1554
|
def download_files(self, paths: list[str]) -> list[FileDownloadResponse]:
|
|
1727
|
-
return cast(
|
|
1728
|
-
"list[FileDownloadResponse]",
|
|
1729
|
-
self._with_sandbox_retry(lambda: self._backend().download_files(paths)),
|
|
1730
|
-
)
|
|
1555
|
+
return cast("list[FileDownloadResponse]", self._call("download_files", paths))
|
|
1731
1556
|
|
|
1732
1557
|
async def adownload_files(self, paths: list[str]) -> list[FileDownloadResponse]:
|
|
1733
1558
|
return cast("list[FileDownloadResponse]", await self._acall("adownload_files", paths))
|
|
1734
1559
|
|
|
1735
1560
|
def execute(self, command: str, *, timeout: int | None = None) -> object:
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
is_syncing_sandbox_proxy_config = True
|
|
1743
|
-
run_sync(self._sync_sandbox_proxy_config())
|
|
1744
|
-
is_syncing_sandbox_proxy_config = False
|
|
1745
|
-
if timeout is not None:
|
|
1746
|
-
try:
|
|
1747
|
-
return backend.execute(command, timeout=timeout)
|
|
1748
|
-
except TypeError:
|
|
1749
|
-
return backend.execute(command)
|
|
1750
|
-
return backend.execute(command)
|
|
1751
|
-
|
|
1752
|
-
return self._with_sandbox_retry(
|
|
1753
|
-
_run, retry_allowed=lambda: not is_syncing_sandbox_proxy_config
|
|
1754
|
-
)
|
|
1561
|
+
if timeout is not None:
|
|
1562
|
+
try:
|
|
1563
|
+
return self._call("execute", command, timeout=timeout)
|
|
1564
|
+
except TypeError:
|
|
1565
|
+
return self._call("execute", command)
|
|
1566
|
+
return self._call("execute", command)
|
|
1755
1567
|
|
|
1756
1568
|
async def aexecute(
|
|
1757
1569
|
self,
|
|
@@ -1775,20 +1587,12 @@ def _managed_sandbox_backend( # noqa: C901
|
|
|
1775
1587
|
config,
|
|
1776
1588
|
)
|
|
1777
1589
|
|
|
1778
|
-
def _remember_resolved(
|
|
1779
|
-
self, backend: ResolvedSandboxBackend, scope_key: str
|
|
1780
|
-
) -> ResolvedSandboxBackend:
|
|
1781
|
-
self._resolved_backend = backend
|
|
1782
|
-
self._resolved_host_name = _peek_managed_host_name(scope_key)
|
|
1783
|
-
return backend
|
|
1784
|
-
|
|
1785
1590
|
def _backend(self) -> ResolvedSandboxBackend:
|
|
1786
1591
|
if self._resolved_backend is not None:
|
|
1787
1592
|
return self._resolved_backend
|
|
1788
1593
|
config = _effective_sandbox_run_config(
|
|
1789
1594
|
run_config, bound_configurable=self._bound_configurable
|
|
1790
1595
|
)
|
|
1791
|
-
key = _thread_scope_key(config, selection_fingerprint)
|
|
1792
1596
|
backend = cast(
|
|
1793
1597
|
"ResolvedSandboxBackend",
|
|
1794
1598
|
_resolve_managed_sandbox(
|
|
@@ -1799,7 +1603,8 @@ def _managed_sandbox_backend( # noqa: C901
|
|
|
1799
1603
|
selection_fingerprint=selection_fingerprint,
|
|
1800
1604
|
),
|
|
1801
1605
|
)
|
|
1802
|
-
|
|
1606
|
+
self._resolved_backend = backend
|
|
1607
|
+
return backend
|
|
1803
1608
|
|
|
1804
1609
|
async def _abackend(self) -> ResolvedSandboxBackend:
|
|
1805
1610
|
if self._resolved_backend is not None:
|
|
@@ -1807,7 +1612,6 @@ def _managed_sandbox_backend( # noqa: C901
|
|
|
1807
1612
|
config = _effective_sandbox_run_config(
|
|
1808
1613
|
run_config, bound_configurable=self._bound_configurable
|
|
1809
1614
|
)
|
|
1810
|
-
key = _thread_scope_key(config, selection_fingerprint)
|
|
1811
1615
|
backend = cast(
|
|
1812
1616
|
"ResolvedSandboxBackend",
|
|
1813
1617
|
await asyncio.to_thread(
|
|
@@ -1819,100 +1623,51 @@ def _managed_sandbox_backend( # noqa: C901
|
|
|
1819
1623
|
selection_fingerprint,
|
|
1820
1624
|
),
|
|
1821
1625
|
)
|
|
1822
|
-
|
|
1626
|
+
self._resolved_backend = backend
|
|
1627
|
+
return backend
|
|
1823
1628
|
|
|
1824
|
-
def
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
*,
|
|
1828
|
-
retry_allowed: Callable[[], bool] | None = None,
|
|
1829
|
-
) -> object:
|
|
1629
|
+
def _recover(self, backend: ResolvedSandboxBackend, error: Exception) -> None:
|
|
1630
|
+
if not _is_sandbox_not_found_error(error):
|
|
1631
|
+
return
|
|
1830
1632
|
config = _effective_sandbox_run_config(
|
|
1831
1633
|
run_config, bound_configurable=self._bound_configurable
|
|
1832
1634
|
)
|
|
1635
|
+
previous_name = _peek_managed_host_name(
|
|
1636
|
+
_thread_scope_key(config, selection_fingerprint)
|
|
1637
|
+
)
|
|
1833
1638
|
try:
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
if retry_allowed is not None and not retry_allowed():
|
|
1837
|
-
raise
|
|
1838
|
-
if self._recreated_after_transient or not _is_transient_sandbox_error(error):
|
|
1839
|
-
raise
|
|
1840
|
-
key = _thread_scope_key(config, selection_fingerprint)
|
|
1841
|
-
failing_id = _backend_id(self._resolved_backend)
|
|
1842
|
-
failing_name = self._resolved_host_name
|
|
1843
|
-
_LOG.warning(
|
|
1844
|
-
"[mda] sandbox op failed; invalidating and recreating once "
|
|
1845
|
-
"scope=%r sandbox_id=%r err=%s: %s",
|
|
1846
|
-
key,
|
|
1847
|
-
failing_id,
|
|
1848
|
-
type(error).__name__,
|
|
1849
|
-
error,
|
|
1639
|
+
recovered = _recover_managed_sandbox(
|
|
1640
|
+
sandbox, config, backend, connectors, identity, selection_fingerprint
|
|
1850
1641
|
)
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1642
|
+
except Exception: # noqa: BLE001
|
|
1643
|
+
return
|
|
1644
|
+
if recovered is not backend:
|
|
1645
|
+
sandbox_proxy_config_sync.invalidate(previous_name)
|
|
1646
|
+
if self._resolved_backend is backend:
|
|
1647
|
+
self._resolved_backend = recovered
|
|
1648
|
+
|
|
1649
|
+
def _call(self, method: str, *args: object, **kwargs: object) -> object:
|
|
1650
|
+
backend = self._backend()
|
|
1651
|
+
try:
|
|
1652
|
+
if method == "execute" and has_proxy_config:
|
|
1653
|
+
run_sync(self._sync_sandbox_proxy_config())
|
|
1654
|
+
return getattr(backend, method)(*args, **kwargs)
|
|
1655
|
+
except Exception as error:
|
|
1656
|
+
self._recover(backend, error)
|
|
1657
|
+
raise
|
|
1863
1658
|
|
|
1864
1659
|
async def _acall(self, method: str, *args: object, **kwargs: object) -> object:
|
|
1865
|
-
|
|
1866
|
-
run_config, bound_configurable=self._bound_configurable
|
|
1867
|
-
)
|
|
1868
|
-
failing_id: str | None = None
|
|
1869
|
-
failing_name: str | None = None
|
|
1870
|
-
is_syncing_sandbox_proxy_config = False
|
|
1660
|
+
backend = await self._abackend()
|
|
1871
1661
|
try:
|
|
1872
|
-
backend = await self._abackend()
|
|
1873
|
-
failing_id = _backend_id(backend)
|
|
1874
|
-
failing_name = self._resolved_host_name
|
|
1875
1662
|
if method == "aexecute":
|
|
1876
|
-
is_syncing_sandbox_proxy_config = True
|
|
1877
1663
|
await self._sync_sandbox_proxy_config()
|
|
1878
|
-
is_syncing_sandbox_proxy_config = False
|
|
1879
1664
|
result = getattr(backend, method)(*args, **kwargs)
|
|
1880
1665
|
if inspect.isawaitable(result):
|
|
1881
1666
|
return await result
|
|
1882
1667
|
return result
|
|
1883
1668
|
except Exception as error:
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
if self._recreated_after_transient or not _is_transient_sandbox_error(error):
|
|
1887
|
-
raise
|
|
1888
|
-
key = _thread_scope_key(config, selection_fingerprint)
|
|
1889
|
-
_LOG.warning(
|
|
1890
|
-
"[mda] sandbox op failed; invalidating and recreating once "
|
|
1891
|
-
"scope=%r method=%r sandbox_id=%r err=%s: %s",
|
|
1892
|
-
key,
|
|
1893
|
-
method,
|
|
1894
|
-
failing_id,
|
|
1895
|
-
type(error).__name__,
|
|
1896
|
-
error,
|
|
1897
|
-
)
|
|
1898
|
-
self._recreated_after_transient = True
|
|
1899
|
-
_invalidate_managed_sandbox(
|
|
1900
|
-
sandbox,
|
|
1901
|
-
config,
|
|
1902
|
-
expected_backend_id=failing_id,
|
|
1903
|
-
expected_host_name=failing_name,
|
|
1904
|
-
selection_fingerprint=selection_fingerprint,
|
|
1905
|
-
)
|
|
1906
|
-
sandbox_proxy_config_sync.invalidate(failing_name)
|
|
1907
|
-
self._resolved_backend = None
|
|
1908
|
-
self._resolved_host_name = None
|
|
1909
|
-
backend = await self._abackend()
|
|
1910
|
-
if method == "aexecute":
|
|
1911
|
-
await self._sync_sandbox_proxy_config()
|
|
1912
|
-
result = getattr(backend, method)(*args, **kwargs)
|
|
1913
|
-
if inspect.isawaitable(result):
|
|
1914
|
-
return await result
|
|
1915
|
-
return result
|
|
1669
|
+
await asyncio.to_thread(self._recover, backend, error)
|
|
1670
|
+
raise
|
|
1916
1671
|
|
|
1917
1672
|
return _LazyManagedSandboxBackend(None)
|
|
1918
1673
|
|
|
@@ -2016,21 +1771,77 @@ def _resolve_managed_sandbox(
|
|
|
2016
1771
|
# Cold create/provision while holding only the per-key lock. Do not hold
|
|
2017
1772
|
# ``_managed_sandbox_lock`` here — websocket retries can take tens of
|
|
2018
1773
|
# seconds and would wedge every other Host worker.
|
|
2019
|
-
backend, host_name = _create_langsmith_sandbox(
|
|
1774
|
+
backend, host_name, sandbox_id = _create_langsmith_sandbox(
|
|
2020
1775
|
sandbox,
|
|
2021
1776
|
config=config,
|
|
2022
1777
|
connectors=connectors,
|
|
2023
1778
|
identity=identity,
|
|
2024
1779
|
sandbox_mode="create",
|
|
2025
1780
|
scope_key=key,
|
|
1781
|
+
selection_fingerprint=selection_fingerprint,
|
|
2026
1782
|
)
|
|
2027
|
-
entry = _ManagedSandboxEntry(backend, host_name=host_name)
|
|
1783
|
+
entry = _ManagedSandboxEntry(backend, host_name=host_name, sandbox_id=sandbox_id)
|
|
2028
1784
|
entry.synced_threads.add(thread_key)
|
|
2029
1785
|
with _managed_sandbox_lock:
|
|
2030
1786
|
_managed_sandboxes[key] = entry
|
|
2031
1787
|
return entry.backend
|
|
2032
1788
|
|
|
2033
1789
|
|
|
1790
|
+
def _is_sandbox_not_found_error(error: Exception) -> bool:
|
|
1791
|
+
from langsmith.sandbox import ResourceNotFoundError, SandboxConnectionError # noqa: PLC0415
|
|
1792
|
+
|
|
1793
|
+
if isinstance(error, ResourceNotFoundError):
|
|
1794
|
+
return True
|
|
1795
|
+
if isinstance(error, SandboxConnectionError):
|
|
1796
|
+
response = getattr(error.__cause__, "response", None)
|
|
1797
|
+
return getattr(response, "status_code", None) == HTTPStatus.NOT_FOUND
|
|
1798
|
+
return False
|
|
1799
|
+
|
|
1800
|
+
|
|
1801
|
+
def _recover_managed_sandbox(
|
|
1802
|
+
sandbox: SandboxDefinition,
|
|
1803
|
+
config: ManagedRunConfig | Mapping[str, object] | None,
|
|
1804
|
+
failed_backend: ResolvedSandboxBackend,
|
|
1805
|
+
connectors: list[Connector] | None = None,
|
|
1806
|
+
identity: IdentityDefinitionLike | None = None,
|
|
1807
|
+
selection_fingerprint: str | None = None,
|
|
1808
|
+
) -> ResolvedSandboxBackend:
|
|
1809
|
+
from langsmith.sandbox import ResourceNotFoundError # noqa: PLC0415
|
|
1810
|
+
|
|
1811
|
+
key = _thread_scope_key(config, selection_fingerprint)
|
|
1812
|
+
with _sandbox_key_lock(key):
|
|
1813
|
+
with _managed_sandbox_lock:
|
|
1814
|
+
entry = _managed_sandboxes.get(key)
|
|
1815
|
+
if entry is None:
|
|
1816
|
+
return failed_backend
|
|
1817
|
+
current = cast("ResolvedSandboxBackend", entry.backend)
|
|
1818
|
+
if current is not failed_backend or entry.host_name is None:
|
|
1819
|
+
return current
|
|
1820
|
+
client = _sandbox_client_for(sandbox)
|
|
1821
|
+
get_sandbox = cast("Callable[[str], object]", getattr(client, "get_sandbox")) # noqa: B009
|
|
1822
|
+
try:
|
|
1823
|
+
existing = _await_if_needed(get_sandbox(entry.host_name))
|
|
1824
|
+
except ResourceNotFoundError:
|
|
1825
|
+
existing = None
|
|
1826
|
+
if existing is not None and _sandbox_handle_id(existing) == entry.sandbox_id:
|
|
1827
|
+
return current
|
|
1828
|
+
backend, host_name, sandbox_id = _create_langsmith_sandbox(
|
|
1829
|
+
sandbox,
|
|
1830
|
+
config=config,
|
|
1831
|
+
connectors=connectors,
|
|
1832
|
+
identity=identity,
|
|
1833
|
+
scope_key=key,
|
|
1834
|
+
selection_fingerprint=selection_fingerprint,
|
|
1835
|
+
recovery_name=entry.host_name,
|
|
1836
|
+
existing_sandbox=existing,
|
|
1837
|
+
)
|
|
1838
|
+
replacement = _ManagedSandboxEntry(backend, host_name=host_name, sandbox_id=sandbox_id)
|
|
1839
|
+
replacement.synced_threads.add(_thread_sync_key(config))
|
|
1840
|
+
with _managed_sandbox_lock:
|
|
1841
|
+
_managed_sandboxes[key] = replacement
|
|
1842
|
+
return backend
|
|
1843
|
+
|
|
1844
|
+
|
|
2034
1845
|
def _thread_sync_key(
|
|
2035
1846
|
config: ManagedRunConfig | Mapping[str, object] | None,
|
|
2036
1847
|
) -> str:
|
|
@@ -2359,6 +2170,22 @@ def _resolve_sandbox_instance(
|
|
|
2359
2170
|
return created, False
|
|
2360
2171
|
|
|
2361
2172
|
|
|
2173
|
+
def _create_replacement_sandbox(
|
|
2174
|
+
client: object, create_kwargs: dict[str, object], name: str
|
|
2175
|
+
) -> tuple[object, bool]:
|
|
2176
|
+
from langsmith.sandbox import ( # noqa: PLC0415
|
|
2177
|
+
ResourceAlreadyExistsError,
|
|
2178
|
+
ResourceNameConflictError,
|
|
2179
|
+
)
|
|
2180
|
+
|
|
2181
|
+
create_sandbox = cast("Callable[..., object]", getattr(client, "create_sandbox")) # noqa: B009
|
|
2182
|
+
try:
|
|
2183
|
+
return _await_if_needed(create_sandbox(name=name, **create_kwargs)), False
|
|
2184
|
+
except (ResourceAlreadyExistsError, ResourceNameConflictError):
|
|
2185
|
+
get_sandbox = cast("Callable[[str], object]", getattr(client, "get_sandbox")) # noqa: B009
|
|
2186
|
+
return _await_if_needed(get_sandbox(name)), True
|
|
2187
|
+
|
|
2188
|
+
|
|
2362
2189
|
def _create_langsmith_sandbox(
|
|
2363
2190
|
sandbox: SandboxDefinition,
|
|
2364
2191
|
*,
|
|
@@ -2367,25 +2194,31 @@ def _create_langsmith_sandbox(
|
|
|
2367
2194
|
identity: IdentityDefinitionLike | None = None,
|
|
2368
2195
|
sandbox_mode: Literal["create", "reuse"] = "create",
|
|
2369
2196
|
scope_key: str,
|
|
2370
|
-
|
|
2197
|
+
selection_fingerprint: str | None = None,
|
|
2198
|
+
recovery_name: str | None = None,
|
|
2199
|
+
existing_sandbox: object | None = None,
|
|
2200
|
+
) -> tuple[ResolvedSandboxBackend, str | None, str | None]:
|
|
2371
2201
|
"""Build a LangSmith sandbox, optionally from the baked recipe, and wrap it."""
|
|
2372
|
-
create_kwargs = _sandbox_create_kwargs(sandbox)
|
|
2202
|
+
create_kwargs = _sandbox_create_kwargs(sandbox, selection_fingerprint)
|
|
2373
2203
|
client = _sandbox_client_for(sandbox)
|
|
2374
2204
|
deployment = _managed_deployment_name()
|
|
2375
2205
|
lookup_names = (
|
|
2376
2206
|
_managed_sandbox_lookup_names(deployment, scope_key, sandbox) if deployment else []
|
|
2377
2207
|
)
|
|
2378
|
-
sandbox_name = lookup_names[0] if lookup_names else None
|
|
2208
|
+
sandbox_name = recovery_name or (lookup_names[0] if lookup_names else None)
|
|
2379
2209
|
fallback_name: Callable[[], str] | None = None
|
|
2380
2210
|
if deployment:
|
|
2381
2211
|
fallback_name = partial(_managed_sandbox_fallback_name, deployment, scope_key)
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2212
|
+
if existing_sandbox is not None:
|
|
2213
|
+
langsmith_sandbox, adopted = existing_sandbox, True
|
|
2214
|
+
elif recovery_name:
|
|
2215
|
+
langsmith_sandbox, adopted = _create_replacement_sandbox(
|
|
2216
|
+
client, create_kwargs, recovery_name
|
|
2217
|
+
)
|
|
2218
|
+
else:
|
|
2219
|
+
langsmith_sandbox, adopted = _resolve_sandbox_instance(
|
|
2220
|
+
client, create_kwargs, sandbox_name, fallback_name, lookup_names[1:]
|
|
2221
|
+
)
|
|
2389
2222
|
host_name = _sandbox_handle_name(langsmith_sandbox) or sandbox_name
|
|
2390
2223
|
_LOG.info(
|
|
2391
2224
|
"[mda] sandbox resolve: %s name=%r id=%r scope=%r",
|
|
@@ -2412,7 +2245,7 @@ def _create_langsmith_sandbox(
|
|
|
2412
2245
|
identity=identity,
|
|
2413
2246
|
)
|
|
2414
2247
|
|
|
2415
|
-
return resolved, host_name
|
|
2248
|
+
return resolved, host_name, _sandbox_handle_id(langsmith_sandbox)
|
|
2416
2249
|
|
|
2417
2250
|
|
|
2418
2251
|
def _string_option(value: object) -> str | None:
|
{managed_deepagents-0.9.0.dev3.dist-info → managed_deepagents-0.9.1.dev2.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: managed-deepagents
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.1.dev2
|
|
4
4
|
Summary: Managed Deep Agents — the define_deep_agent authoring interface plus the CLI that compiles and deploys a code-first Deep Agent repository to a managed LangGraph runtime.
|
|
5
5
|
Author: LangChain
|
|
6
6
|
License: MIT
|
|
@@ -13,7 +13,7 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
13
13
|
Requires-Python: >=3.11
|
|
14
14
|
Description-Content-Type: text/markdown
|
|
15
15
|
License-File: LICENSE
|
|
16
|
-
Requires-Dist: pydantic>=2.
|
|
16
|
+
Requires-Dist: pydantic>=2.7.4
|
|
17
17
|
Requires-Dist: httpx<1,>=0.28.1
|
|
18
18
|
Requires-Dist: typing-extensions<5,>=4.12.2
|
|
19
19
|
Requires-Dist: deepagents<1,>=0.7.13
|
|
@@ -25,7 +25,7 @@ managed_deepagents/_managed_tools.py,sha256=a_vtJdrWo0o9UXaKKZzgY1JCl84V0SCRAwhz
|
|
|
25
25
|
managed_deepagents/_memory_instructions.py,sha256=s69Shu6vGCXbynozC-SRSJeZrpH5PNowh0sIRKH65XQ,6763
|
|
26
26
|
managed_deepagents/_run_input.py,sha256=BoEozXHd2fC1lHRu5A548pZn4v9ZGlx7TgPePI5oZjc,4430
|
|
27
27
|
managed_deepagents/_runtime_schedules.py,sha256=D_HVGD1tpZpi2QSJ9MOnkYY_EzmSUVWAlAwVYRf865U,22495
|
|
28
|
-
managed_deepagents/_sandbox_proxy.py,sha256=
|
|
28
|
+
managed_deepagents/_sandbox_proxy.py,sha256=Uce50nCI7MAO1TqRi9UAJQRBK6XzDU31PlH56s5TYjI,9054
|
|
29
29
|
managed_deepagents/_schedule_auth.py,sha256=3w22m98Fsru4WC5KJo_Iw8intRGuh8RJskvMz7WloB0,8982
|
|
30
30
|
managed_deepagents/_schedule_channel.py,sha256=2xOSy2UQcQ6z8r-JrnbOKQg1-daOu4oye7PnaNk0g-4,981
|
|
31
31
|
managed_deepagents/_schedule_time.py,sha256=uNyULRjoD0HzPVvV-W772HPb3BYCt0fwEbbT9Ec__Jc,3710
|
|
@@ -37,10 +37,10 @@ managed_deepagents/define_memory.py,sha256=0DzI9jxr83YJ6mEhqXRbIYzgWpl259-PdAMoA
|
|
|
37
37
|
managed_deepagents/namespaces.py,sha256=7jNvJ18p6xL4_FKCqW4QZ4sYVYlMd6Nuw9Zw8H_0Zb4,4896
|
|
38
38
|
managed_deepagents/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
39
39
|
managed_deepagents/run_context.py,sha256=9gzugZ5naNNQCJcXGRY_-7ZXxttY9w3jkxjR94JKgsk,3287
|
|
40
|
-
managed_deepagents/runtime.py,sha256=
|
|
40
|
+
managed_deepagents/runtime.py,sha256=atutnzqXJJPcydb3gaBAl_ZhxDlhQyWEbuCFEoIAi1k,88247
|
|
41
41
|
managed_deepagents/sandbox.py,sha256=8qaswX6F2LYJX1uGq_7XwAGHZjGOD9VQ0WISqPK_ohs,4734
|
|
42
42
|
managed_deepagents/schedules.py,sha256=qLXWdtvtv9tKyKhyULZIXUTqC8rZOxm2ZlMM7unjxZ8,5654
|
|
43
|
-
managed_deepagents/_binaries/mda.exe,sha256=
|
|
43
|
+
managed_deepagents/_binaries/mda.exe,sha256=dD1jwrJRrgXlYOhRbvrGXW0V5aJsXqBIc42ftPeiYiI,4412928
|
|
44
44
|
managed_deepagents/_channels/__init__.py,sha256=tY94zltWKNw-FIzbGjrh0cSAc2JIHCEAvcY7hzoRED0,801
|
|
45
45
|
managed_deepagents/_channels/assistant_text.py,sha256=ZLYAF1MQVE5_EN49MoPJdB8Ckf3vNPpXNBhkdA4egF0,3414
|
|
46
46
|
managed_deepagents/_channels/binding.py,sha256=IAMVozOELxTN1vb36snmFba-EcYKdxH5gHbfLqPkKJo,5144
|
|
@@ -73,8 +73,8 @@ managed_deepagents/_channels/trigger/types.py,sha256=-le2OMDOD8R39CqBWBAPIc8Fpe3
|
|
|
73
73
|
managed_deepagents/_connectors/__init__.py,sha256=Ei-DvDmA-F2Bord6WuM7UtWtnuVt3u7CRSPKFqpHFhA,537
|
|
74
74
|
managed_deepagents/_connectors/tool_selection.py,sha256=-dtrHi8o4FsXG70V4CWgzL2UVG-89P3TU1Xk8UEdyDU,3029
|
|
75
75
|
managed_deepagents/_connectors/mcp/__init__.py,sha256=GILRaVSbQNgclmJcgmXpG6R_C63R_y2gEfvyFBlSRZM,17455
|
|
76
|
-
managed_deepagents/_connectors/mcp/langsmith_url.py,sha256=
|
|
77
|
-
managed_deepagents/_connectors/mcp/load.py,sha256=
|
|
76
|
+
managed_deepagents/_connectors/mcp/langsmith_url.py,sha256=DyG4-w2zo-6WE7C8cvmMuhPP1Wr1OOV1xkkZnz5pIU0,1694
|
|
77
|
+
managed_deepagents/_connectors/mcp/load.py,sha256=RJjV5fdk1867OD4c_ZXnEEuu5Do6S1T1UgTfGyuiRPU,23158
|
|
78
78
|
managed_deepagents/_memory/__init__.py,sha256=oIba6kYsaQqOa3UeuQEbKFatb0f_ETPrLrqiTOmOsnU,311
|
|
79
79
|
managed_deepagents/_memory/async_util.py,sha256=gyN1PqRp94zSC12CZjD_daihtuf4rYTws_G7OIeW86k,1783
|
|
80
80
|
managed_deepagents/_memory/context_io.py,sha256=Ez3K0PH1tjlcHn3-s44JhyDjf1NvDnvbmcNiRd6Pqpc,1621
|
|
@@ -101,9 +101,9 @@ managed_deepagents/identity/__init__.py,sha256=YMB5p2DRyyY_82gGNVfGHjfjnUFRTtMne
|
|
|
101
101
|
managed_deepagents/identity/claims.py,sha256=prby7r_8Lww3MmoBm8PX6PsSGE3GwSHkr8mVIz_08nU,1180
|
|
102
102
|
managed_deepagents/identity/options.py,sha256=x_yMbXEFR7zXyehEjDHG2qjAlukXjrRBcQLcM6IndLM,2550
|
|
103
103
|
managed_deepagents/identity/supabase.py,sha256=8uobl3WCrQL_ieSXG8KTLf1th7Qjim9liZT50HeaJE0,6026
|
|
104
|
-
managed_deepagents-0.9.
|
|
105
|
-
managed_deepagents-0.9.
|
|
106
|
-
managed_deepagents-0.9.
|
|
107
|
-
managed_deepagents-0.9.
|
|
108
|
-
managed_deepagents-0.9.
|
|
109
|
-
managed_deepagents-0.9.
|
|
104
|
+
managed_deepagents-0.9.1.dev2.dist-info/licenses/LICENSE,sha256=WnPZQQ608ojZUkXl7BW6VbKloIAibZiGm1K6cjeZOL8,1066
|
|
105
|
+
managed_deepagents-0.9.1.dev2.dist-info/METADATA,sha256=nzOSdzLnqsDbXB6AXFLVjCZ-Hu3a2LVQzTTeLhcSf24,32563
|
|
106
|
+
managed_deepagents-0.9.1.dev2.dist-info/WHEEL,sha256=3I5VVWZdsFlU417aCS2bMRuerS8wsfvBq99MyatBV3A,97
|
|
107
|
+
managed_deepagents-0.9.1.dev2.dist-info/entry_points.txt,sha256=ziZqkKuaDO3qHCjKmBhrx9cm3ok8bZ9xcEDpUTj4unM,53
|
|
108
|
+
managed_deepagents-0.9.1.dev2.dist-info/top_level.txt,sha256=fdBo4O0Hlol_w022tTLB5ftZpamb4yJoQ3MUvjgTGfA,19
|
|
109
|
+
managed_deepagents-0.9.1.dev2.dist-info/RECORD,,
|
|
File without changes
|
{managed_deepagents-0.9.0.dev3.dist-info → managed_deepagents-0.9.1.dev2.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{managed_deepagents-0.9.0.dev3.dist-info → managed_deepagents-0.9.1.dev2.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
{managed_deepagents-0.9.0.dev3.dist-info → managed_deepagents-0.9.1.dev2.dist-info}/top_level.txt
RENAMED
|
File without changes
|