managed-deepagents 0.10.3.dev2__py3-none-win_amd64.whl → 0.10.3.dev4__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.
Binary file
@@ -0,0 +1,60 @@
1
+ """Authored ``routes``: Deep Agents backends mounted at path prefixes."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+ from collections.abc import Mapping
7
+
8
+ from deepagents.backends import CompositeBackend, StateBackend
9
+ from deepagents.backends.protocol import BackendProtocol
10
+
11
+ #: Prefixes MDA mounts itself; authored routes may not shadow or nest in them.
12
+ RESERVED_ROUTE_PREFIXES = ("/instructions.md/", "/skills/", "/memories/")
13
+
14
+ _ROUTE_PREFIX = re.compile(r"(/[A-Za-z0-9_][A-Za-z0-9._-]*)+/\Z")
15
+
16
+ Routes = Mapping[str, BackendProtocol]
17
+
18
+
19
+ def snapshot_routes(value: object) -> dict[str, BackendProtocol]:
20
+ """Validate authored routes and return a copy."""
21
+ if not isinstance(value, Mapping):
22
+ msg = "routes must be a mapping of path prefixes to Deep Agents backends"
23
+ raise TypeError(msg)
24
+ routes: dict[str, BackendProtocol] = {}
25
+ for prefix, backend in value.items():
26
+ if not isinstance(prefix, str) or not _ROUTE_PREFIX.match(prefix):
27
+ msg = (
28
+ f"routes key {prefix!r} must be an absolute directory prefix such as "
29
+ '"/documents/": start and end with "/", with no "." or ".." segments'
30
+ )
31
+ raise ValueError(msg)
32
+ if reserved := next(
33
+ (r for r in RESERVED_ROUTE_PREFIXES if prefix.startswith(r) or r.startswith(prefix)),
34
+ None,
35
+ ):
36
+ msg = f"routes key {prefix!r} overlaps {reserved!r}, which MDA mounts itself"
37
+ raise ValueError(msg)
38
+ if not isinstance(backend, BackendProtocol):
39
+ msg = f"routes[{prefix!r}] must be a Deep Agents backend (BackendProtocol)"
40
+ raise TypeError(msg)
41
+ routes[prefix] = backend
42
+ return routes
43
+
44
+
45
+ def mount_routes(backend: BackendProtocol | None, routes: Routes) -> BackendProtocol:
46
+ """Add authored routes to the managed backend; unmatched paths keep it.
47
+
48
+ Routes join an existing composite rather than nesting one, because a nested
49
+ composite hides the sandbox default from ``execute``.
50
+ """
51
+ if isinstance(backend, CompositeBackend):
52
+ return type(backend)(
53
+ backend.default,
54
+ {**backend.routes, **routes},
55
+ artifacts_root=backend.artifacts_root,
56
+ )
57
+ return CompositeBackend(
58
+ default=backend if backend is not None else StateBackend(),
59
+ routes=dict(routes),
60
+ )
@@ -377,8 +377,7 @@ async def authorize_schedule( # noqa: C901 - one branch per cron event check
377
377
  if access is None:
378
378
  if not (is_studio_auth_user(user) or _is_local_dev_operator(user)):
379
379
  raise ValueError("Schedule access is not permitted")
380
- await _authorize_deploy_schedule(action, data)
381
- return None
380
+ return await _authorize_studio_schedule(action, data)
382
381
  filters = {"mda_schedule_owner": access["owner"], "mda_schedule_assistant": access["assistant"]}
383
382
  if action in {"update", "delete"}:
384
383
  filters["mda_managed_by"] = "runtime"
@@ -477,30 +476,40 @@ def _is_local_dev_operator(user: object) -> bool:
477
476
  )
478
477
 
479
478
 
480
- async def _authorize_deploy_schedule(action: str, data: dict[str, object]) -> None:
481
- # Studio identity is reachable by any workspace API key: allow only a deploy-managed
482
- # create (stamped below), never an update, and leave read/search/delete unscoped so
483
- # `mda deploy` (and `mda dev` locally) can still list and tear down managed crons.
479
+ async def _authorize_studio_schedule(action: str, data: dict[str, object]) -> FilterType | None:
480
+ # Studio identity is reachable by any workspace API key. It may create a deploy-managed
481
+ # cron or an untagged one, which is stamped "api" and is the only kind it may update.
482
+ # Read/search/delete stay unscoped so `mda deploy` (and `mda dev` locally) can still
483
+ # list and tear down managed crons.
484
484
  if action == "update":
485
- raise ValueError("Schedule access is not permitted")
485
+ return _authorize_api_schedule_update(data)
486
486
  if action != "create":
487
- return
487
+ return None
488
488
  metadata = data.get("metadata")
489
489
  payload = data.get("payload")
490
+ if metadata is None:
491
+ metadata = data["metadata"] = {}
490
492
  if (
491
493
  not isinstance(metadata, dict)
492
- or metadata.get("mda_managed") is not True
493
- or metadata.get("mda_managed_by") != "deploy"
494
494
  or not isinstance(payload, dict)
495
495
  or not isinstance(payload.get("assistant_id"), str)
496
496
  ):
497
497
  raise ValueError("Schedule access is not permitted")
498
+ api = not any(map(is_managed_key, metadata))
499
+ if not api and (
500
+ metadata.get("mda_managed") is not True or metadata.get("mda_managed_by") != "deploy"
501
+ ):
502
+ raise ValueError("Schedule access is not permitted")
498
503
  assistant = payload["assistant_id"]
499
504
  try:
500
505
  UUID(assistant)
501
506
  except ValueError:
502
507
  assistant = str(uuid5(NAMESPACE_URL, assistant))
503
- metadata.update(mda_schedule_owner="agent", mda_schedule_assistant=assistant)
508
+ if api:
509
+ # Not `mda_managed`: deploy reconciliation and runtime schedule tools leave it alone.
510
+ metadata["mda_managed_by"] = "api"
511
+ else:
512
+ metadata.update(mda_schedule_owner="agent", mda_schedule_assistant=assistant)
504
513
  execution: ExecutionUser = {
505
514
  "identity": f"mda:schedule:{assistant}",
506
515
  "permissions": [],
@@ -518,8 +527,31 @@ async def _authorize_deploy_schedule(action: str, data: dict[str, object]) -> No
518
527
  "thread": str(data["thread_id"]),
519
528
  }
520
529
  )
521
- _check_context(payload, execution, "deploy")
530
+ if api:
531
+ _check_api_context(payload)
532
+ else:
533
+ _check_context(payload, execution, "deploy")
522
534
  _stamp_execution(payload, execution)
535
+ return None
536
+
537
+
538
+ def _authorize_api_schedule_update(data: dict[str, object]) -> FilterType:
539
+ """An API cron keeps its stamped assistant and principal; only its other fields change."""
540
+ metadata = data.get("metadata")
541
+ payload = data.get("payload")
542
+ if (isinstance(metadata, dict) and any(map(is_managed_key, metadata))) or (
543
+ isinstance(payload, dict) and {"assistant_id", "config"} & payload.keys()
544
+ ):
545
+ raise ValueError("Schedule access is not permitted")
546
+ _check_api_context(payload)
547
+ return {"mda_managed_by": "api"}
548
+
549
+
550
+ def _check_api_context(payload: object) -> None:
551
+ """An API cron's context is authored only: no managed schedule or channel routing."""
552
+ context = _field(payload, "context")
553
+ if context is not None and (not isinstance(context, dict) or any(map(is_managed_key, context))):
554
+ raise ValueError("Invalid schedule config")
523
555
 
524
556
 
525
557
  def _stamp_execution(payload: dict[str, object], execution: ExecutionUser) -> None:
@@ -28,6 +28,7 @@ if TYPE_CHECKING:
28
28
  FilesystemPermission,
29
29
  SubAgent,
30
30
  )
31
+ from deepagents.backends.protocol import BackendProtocol
31
32
  from langchain.agents.middleware import InterruptOnConfig
32
33
  from langchain.agents.middleware.types import AgentMiddleware
33
34
  from langchain.agents.structured_output import ResponseFormat
@@ -135,6 +136,7 @@ def define_deep_agent(
135
136
  skills: SkillSelection | Omitted | None = OMITTED,
136
137
  memory: MemoryDefinition | Omitted | None = OMITTED,
137
138
  browser: BrowserDefinition | Omitted | None = OMITTED,
139
+ routes: Mapping[str, BackendProtocol] | None = None,
138
140
  disable_memory: bool | None = None,
139
141
  metadata: Mapping[str, object] | None = None,
140
142
  **kwargs: Never,
@@ -175,6 +177,13 @@ def define_deep_agent(
175
177
  ``None`` keeps none. A sync subagent may select only servers this agent
176
178
  loads, and a sync ``"mode": "fork"`` subagent cannot set it.
177
179
 
180
+ ``routes`` mounts Deep Agents backends at path prefixes, like
181
+ ``CompositeBackend(routes=...)``: ``{"/documents/": StoreBackend(...)}``
182
+ sends ``/documents/a.md`` to that backend as ``/a.md``, and unmatched paths
183
+ keep the managed backend. Prefixes must be absolute directories and must not
184
+ overlap MDA's own mounts (``/instructions.md``, ``/skills/``, ``/memories/``).
185
+ Routes apply to file tools, not to shell commands in a sandbox.
186
+
178
187
  ``metadata`` is MDA-owned authoring config (not a ``create_deep_agent``
179
188
  kwarg): the runtime applies it via ``.with_config({"metadata": ...})`` so
180
189
  keys such as prompt provenance land on the **root** LangSmith run.
@@ -226,12 +235,22 @@ def define_deep_agent(
226
235
  config["debug"] = debug
227
236
  if metadata is not None:
228
237
  config["metadata"] = dict(metadata)
238
+ config.update(_routes_config(routes))
229
239
 
230
240
  config.update(copy_managed_selections(instructions, mcp, sandbox, skills, memory, browser))
231
241
 
232
242
  return DeepAgentDefinition(config)
233
243
 
234
244
 
245
+ def _routes_config(routes: object) -> dict[str, object]:
246
+ if routes is None:
247
+ return {}
248
+ # Imported lazily so authoring modules without routes skip loading backends.
249
+ from managed_deepagents._routes import snapshot_routes # noqa: PLC0415
250
+
251
+ return {"routes": snapshot_routes(routes)}
252
+
253
+
235
254
  _ASYNC_SUBAGENT_UNSUPPORTED_KEYS = ("runnable", "graph_id", "url", "headers")
236
255
 
237
256
 
@@ -156,6 +156,7 @@ from managed_deepagents._memory.selected_skills import (
156
156
  resolve_selected_skills,
157
157
  )
158
158
  from managed_deepagents._memory.user_memory import UserMemoryBackend
159
+ from managed_deepagents._routes import Routes, mount_routes
159
160
  from managed_deepagents._run_local import RunLocal, current_run_id
160
161
  from managed_deepagents._telemetry.metadata import detect_run_identity
161
162
  from managed_deepagents._telemetry.run import (
@@ -1459,6 +1460,7 @@ def _compile_managed_agent(
1459
1460
  selected_skills_backend,
1460
1461
  sandbox_backend=sandbox_backend,
1461
1462
  )
1463
+ _mount_authored_routes(merged)
1462
1464
 
1463
1465
  merged["system_prompt"] = timing.measure(
1464
1466
  "instructions",
@@ -1828,6 +1830,15 @@ def _mount_selected_skills(
1828
1830
  )
1829
1831
 
1830
1832
 
1833
+ def _mount_authored_routes(merged: dict[str, object]) -> None:
1834
+ """Mount ``define_deep_agent(routes=...)`` over the managed backend."""
1835
+ routes = cast("Routes | None", merged.pop("routes", None))
1836
+ if routes:
1837
+ merged["backend"] = mount_routes(
1838
+ cast("BackendProtocol | None", merged.get("backend")), routes
1839
+ )
1840
+
1841
+
1831
1842
  def _apply_managed_context(
1832
1843
  merged: dict[str, object],
1833
1844
  *,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: managed-deepagents
3
- Version: 0.10.3.dev2
3
+ Version: 0.10.3.dev4
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
@@ -289,6 +289,28 @@ The agent layer is mounted at `/memories/agent/`. The user layer requires
289
289
  overwrites existing memories. A project without `memory.py` mounts no durable
290
290
  memory.
291
291
 
292
+ ### Mounting your own backends
293
+
294
+ `routes` mounts Deep Agents backends at path prefixes, as
295
+ `CompositeBackend(routes=...)` does. A path under a prefix goes to that backend
296
+ with the prefix stripped; every other path keeps the managed backend.
297
+
298
+ ```python
299
+ from deepagents.backends import StoreBackend
300
+ from managed_deepagents import define_deep_agent
301
+
302
+ agent = define_deep_agent(
303
+ name="research-assistant",
304
+ routes={
305
+ "/documents/": StoreBackend(namespace=lambda _rt: ("documents",)),
306
+ },
307
+ )
308
+ ```
309
+
310
+ Prefixes must be absolute directories (`"/documents/"`) and cannot overlap the
311
+ paths MDA mounts itself: `/instructions.md`, `/skills/`, and `/memories/`.
312
+ Routes serve the file tools; shell commands in a sandbox do not see them.
313
+
292
314
  ## Async subagents
293
315
 
294
316
  Every Python agent can run its general-purpose subagent either way: blocking
@@ -30,11 +30,12 @@ managed_deepagents/_managed_middleware.py,sha256=xaylPReyfRGgvPZXhdw-j0qt8d9qR1Y
30
30
  managed_deepagents/_managed_thread.py,sha256=P1ogidb2WnGlWpzUyOF6gzhiJOipDEhQ8idlFRiE8hQ,6504
31
31
  managed_deepagents/_managed_tools.py,sha256=77ShVQoelQW9M5Ir1r2AiX7ItrrHTX6LzRBVa21m4i0,12997
32
32
  managed_deepagents/_memory_instructions.py,sha256=j4naanzvL_gBnDI6rwD2AbufH32-Z7g8oPdVqZPiXjA,7851
33
+ managed_deepagents/_routes.py,sha256=TeReerf8TLpUtm95nuHWoT0fK3FVl3v3nhzO-vUpsPA,2369
33
34
  managed_deepagents/_run_input.py,sha256=VdIysM5tIFx8Fjmbr3dkNIHYovcHmSC-wtwRuqYosO0,17689
34
35
  managed_deepagents/_run_local.py,sha256=pKGh_JKUW8RaTFy9EpBor893KCjBV2cCJZzsiBCeaWA,2852
35
36
  managed_deepagents/_runtime_schedules.py,sha256=EDYtFxpbj4jZjV5-1mgWZn598g86NsgvsC_pEa2rGKk,30377
36
37
  managed_deepagents/_sandbox_proxy.py,sha256=AFrcC07nTHaAQhGCDttncv3SkGL5h1JBcfxv7Psgn6c,9835
37
- managed_deepagents/_schedule_auth.py,sha256=Na2BC0JwckzwJzOqWInJ07yVG78HfhvyusmsE44QvLQ,25127
38
+ managed_deepagents/_schedule_auth.py,sha256=twu14FlXcWhs-vKgLFCE3OEva23WRZqgYpbdH246uCw,26480
38
39
  managed_deepagents/_schedule_channel.py,sha256=r0EWl4OrBJRnwKETHjKdScYIfdi0lrUEGdajX6FGIdQ,1109
39
40
  managed_deepagents/_schedule_time.py,sha256=uNyULRjoD0HzPVvV-W772HPb3BYCt0fwEbbT9Ec__Jc,3710
40
41
  managed_deepagents/_static_entry.py,sha256=QgvrnBLue6elOHSWdIFosFEfYMp4V9YDwBlZSe_NyQA,635
@@ -44,15 +45,15 @@ managed_deepagents/_validated_token.py,sha256=On96IOQTDz1KE_ZZmuTqY8IPw-cJ3J2tXk
44
45
  managed_deepagents/agent_entry.py,sha256=MnmLGuBMrueqnfHy6CKTsIZeOgaKj7BAlojGO7OBJTY,5132
45
46
  managed_deepagents/browser.py,sha256=dcUhoD8i2ZzxpcsgO7Eb-DUbrd2nHfDpg5MF1pxwqgw,60023
46
47
  managed_deepagents/define_browser.py,sha256=FQKYVVRTDqSNGqG4Pzp1H6qngAsL1h0gOhu8bYxJ140,2000
47
- managed_deepagents/define_deep_agent.py,sha256=2qAet4dOn9lUYUSGE1QhoU86LCLZV_MMemLTKayMzfc,12253
48
+ managed_deepagents/define_deep_agent.py,sha256=QWyYrjZKvMZjdE4223zINJishiDFkhOR6s7knsvEFwI,13174
48
49
  managed_deepagents/define_memory.py,sha256=0DzI9jxr83YJ6mEhqXRbIYzgWpl259-PdAMoAQRQ3pU,6465
49
50
  managed_deepagents/namespaces.py,sha256=qt41OhCK2mNEDuFwyQ0lkeT5bL0guzv9aRyK3Z-GbVg,4531
50
51
  managed_deepagents/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
51
52
  managed_deepagents/run_context.py,sha256=IayZdcpPrKVss70Hro8qI-EWtL94HZt4JKefzec9qds,3562
52
- managed_deepagents/runtime.py,sha256=OVCWZFd8fikrmO9A9YbLCAFND-jsbh2U_7MUV6JumO4,136407
53
+ managed_deepagents/runtime.py,sha256=M5-XlwkTfWV6Gyl4w9vClFFF0GvOWZEc6-_wPyxn5W0,136847
53
54
  managed_deepagents/sandbox.py,sha256=cS66-vFcARsbHR3fH5jvWd4qF-MAjiGqRe-_Kocsqtg,4693
54
55
  managed_deepagents/schedules.py,sha256=z_OlmZ7hW7LdvWLem-BiA131nHwFvUDSW_0-ObzU_G4,6039
55
- managed_deepagents/_binaries/mda.exe,sha256=6qA2rjL5OrRmORMH37oPP9y7XHg_c_hWoqdBGleUjWc,5153792
56
+ managed_deepagents/_binaries/mda.exe,sha256=73Ufn_PTM3t1noWrO2JkiiiNBfc41Io6lsFYtRSiiUQ,5153792
56
57
  managed_deepagents/_channels/__init__.py,sha256=mMgqza7EWRjhJM0lXlFd-W6wBYZrFkpLQ4_30Bpij7k,249
57
58
  managed_deepagents/_channels/actor.py,sha256=3d_1-ia6vwVjXkw7PYn5gg6BjnlPwRXW4nW2C5vAO7c,5203
58
59
  managed_deepagents/_channels/assistant_text.py,sha256=nf00-KJXNev-e_TkAK_8SBI3J9TiOis1GkGV_zT5048,8472
@@ -155,9 +156,9 @@ managed_deepagents/identity/__init__.py,sha256=uZUKDHtfBc0n-T2xoJEFMqMplmXwAK7hb
155
156
  managed_deepagents/identity/claims.py,sha256=prby7r_8Lww3MmoBm8PX6PsSGE3GwSHkr8mVIz_08nU,1180
156
157
  managed_deepagents/identity/options.py,sha256=x_yMbXEFR7zXyehEjDHG2qjAlukXjrRBcQLcM6IndLM,2550
157
158
  managed_deepagents/identity/supabase.py,sha256=8uobl3WCrQL_ieSXG8KTLf1th7Qjim9liZT50HeaJE0,6026
158
- managed_deepagents-0.10.3.dev2.dist-info/licenses/LICENSE,sha256=WnPZQQ608ojZUkXl7BW6VbKloIAibZiGm1K6cjeZOL8,1066
159
- managed_deepagents-0.10.3.dev2.dist-info/METADATA,sha256=dms0igyMia4t7UU3Jbf8o1ZDtk0fOMDXvd0pTyFcSmo,94332
160
- managed_deepagents-0.10.3.dev2.dist-info/WHEEL,sha256=bhMFZwp6VMtrbl2Ck6PlXryKaCggO1NzYn_HcFbBF1I,97
161
- managed_deepagents-0.10.3.dev2.dist-info/entry_points.txt,sha256=ziZqkKuaDO3qHCjKmBhrx9cm3ok8bZ9xcEDpUTj4unM,53
162
- managed_deepagents-0.10.3.dev2.dist-info/top_level.txt,sha256=fdBo4O0Hlol_w022tTLB5ftZpamb4yJoQ3MUvjgTGfA,19
163
- managed_deepagents-0.10.3.dev2.dist-info/RECORD,,
159
+ managed_deepagents-0.10.3.dev4.dist-info/licenses/LICENSE,sha256=WnPZQQ608ojZUkXl7BW6VbKloIAibZiGm1K6cjeZOL8,1066
160
+ managed_deepagents-0.10.3.dev4.dist-info/METADATA,sha256=5dO9XdmrWSjsIcLIDjjjhLVLHXDuW7Y2EhT12eBPm7Y,95067
161
+ managed_deepagents-0.10.3.dev4.dist-info/WHEEL,sha256=bhMFZwp6VMtrbl2Ck6PlXryKaCggO1NzYn_HcFbBF1I,97
162
+ managed_deepagents-0.10.3.dev4.dist-info/entry_points.txt,sha256=ziZqkKuaDO3qHCjKmBhrx9cm3ok8bZ9xcEDpUTj4unM,53
163
+ managed_deepagents-0.10.3.dev4.dist-info/top_level.txt,sha256=fdBo4O0Hlol_w022tTLB5ftZpamb4yJoQ3MUvjgTGfA,19
164
+ managed_deepagents-0.10.3.dev4.dist-info/RECORD,,