deepagents-code 0.2.4__py3-none-any.whl → 0.2.6__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.
- deepagents_code/_build_info.py +1 -1
- deepagents_code/_version.py +1 -1
- deepagents_code/app.py +45 -16
- deepagents_code/btw.py +2 -1
- deepagents_code/client/commands/extras.py +19 -4
- deepagents_code/client/launch/server.py +20 -4
- deepagents_code/client/remote_client.py +5 -1
- deepagents_code/config.py +14 -0
- deepagents_code/goal_state_notice.py +45 -0
- deepagents_code/goal_tools.py +9 -2
- deepagents_code/hooks/loading.py +19 -4
- deepagents_code/local_context.py +3 -2
- deepagents_code/main.py +40 -5
- deepagents_code/offload_api.py +32 -1
- deepagents_code/offload_middleware.py +48 -4
- deepagents_code/output_truncation.py +26 -3
- deepagents_code/tui/widgets/messages.py +3 -1
- deepagents_code/update_check.py +171 -60
- {deepagents_code-0.2.4.dist-info → deepagents_code-0.2.6.dist-info}/METADATA +21 -21
- {deepagents_code-0.2.4.dist-info → deepagents_code-0.2.6.dist-info}/RECORD +24 -24
- {deepagents_code-0.2.4.data → deepagents_code-0.2.6.data}/data/deepagents_code/default_agent_prompt.md +0 -0
- {deepagents_code-0.2.4.dist-info → deepagents_code-0.2.6.dist-info}/WHEEL +0 -0
- {deepagents_code-0.2.4.dist-info → deepagents_code-0.2.6.dist-info}/entry_points.txt +0 -0
- {deepagents_code-0.2.4.dist-info → deepagents_code-0.2.6.dist-info}/licenses/LICENSE +0 -0
deepagents_code/_build_info.py
CHANGED
deepagents_code/_version.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Keep the `x-release-please-version` annotation — release-please uses it to
|
|
4
4
|
# bump `__version__` in sync with `pyproject.toml` on every release PR.
|
|
5
|
-
__version__ = "0.2.
|
|
5
|
+
__version__ = "0.2.6" # x-release-please-version
|
|
6
6
|
|
|
7
7
|
DOCS_URL = "https://docs.langchain.com/oss/python/deepagents/code"
|
|
8
8
|
"""URL for `deepagents-code` documentation."""
|
deepagents_code/app.py
CHANGED
|
@@ -124,6 +124,7 @@ from deepagents_code.goal_state_limits import (
|
|
|
124
124
|
)
|
|
125
125
|
from deepagents_code.goal_state_notice import (
|
|
126
126
|
GOAL_CONTROL_MESSAGE_SOURCE,
|
|
127
|
+
anchor_summarization_event as _anchor_summarization_event,
|
|
127
128
|
build_goal_continuation,
|
|
128
129
|
build_goal_state_notice,
|
|
129
130
|
goal_notice_size_error,
|
|
@@ -760,6 +761,7 @@ def _effective_conversation(messages: list[Any], event: Any) -> list[Any]: # no
|
|
|
760
761
|
if not isinstance(event, dict):
|
|
761
762
|
_log_malformed_summarization_event(event, len(messages))
|
|
762
763
|
return list(messages)
|
|
764
|
+
event = _anchor_summarization_event(event, messages)
|
|
763
765
|
summary = event.get("summary_message")
|
|
764
766
|
cutoff = _validated_summarization_cutoff(
|
|
765
767
|
event,
|
|
@@ -6781,6 +6783,7 @@ class DeepAgentsApp(App):
|
|
|
6781
6783
|
|
|
6782
6784
|
def on_deep_agents_app_server_start_failed(self, event: ServerStartFailed) -> None:
|
|
6783
6785
|
"""Handle background server startup failure."""
|
|
6786
|
+
from deepagents_code.client.launch.server import ServerStartupTimeoutError
|
|
6784
6787
|
from deepagents_code.mcp_tools import MCPConfigError
|
|
6785
6788
|
from deepagents_code.model_config import (
|
|
6786
6789
|
MissingCredentialsError,
|
|
@@ -6854,12 +6857,23 @@ class DeepAgentsApp(App):
|
|
|
6854
6857
|
# input. Banner is set to idle above to drop the connecting spinner.
|
|
6855
6858
|
if isinstance(event.error, MissingCredentialsError):
|
|
6856
6859
|
text = f"Model setup required: {event.error}"
|
|
6860
|
+
elif isinstance(event.error, ServerStartupTimeoutError):
|
|
6861
|
+
if self._server_kwargs is None:
|
|
6862
|
+
recovery = "Check that the remote server is reachable, then reconnect."
|
|
6863
|
+
elif self._server_proc is not None:
|
|
6864
|
+
recovery = "Run `/restart` to try again."
|
|
6865
|
+
else:
|
|
6866
|
+
recovery = "Use `/model` to select a model and retry startup."
|
|
6867
|
+
text = (
|
|
6868
|
+
f"Server startup timed out. {recovery} "
|
|
6869
|
+
"Press Ctrl+\\ to inspect the startup error in the Debug Console."
|
|
6870
|
+
)
|
|
6857
6871
|
else:
|
|
6858
6872
|
text = f"Server failed to start: {self._server_startup_error}"
|
|
6859
6873
|
if had_deferred_actions:
|
|
6860
6874
|
text += (
|
|
6861
|
-
"\n\
|
|
6862
|
-
"
|
|
6875
|
+
"\n\nCommands you ran while the server was starting were "
|
|
6876
|
+
"not applied. Run them again once it is up."
|
|
6863
6877
|
)
|
|
6864
6878
|
if (
|
|
6865
6879
|
self._server_startup_missing_credentials_provider is not None
|
|
@@ -8094,22 +8108,26 @@ class DeepAgentsApp(App):
|
|
|
8094
8108
|
AppMessage("Skipped dependency refresh (debug mode)."),
|
|
8095
8109
|
)
|
|
8096
8110
|
return
|
|
8097
|
-
|
|
8111
|
+
outcome = await perform_dependency_refresh(
|
|
8098
8112
|
include_prereleases=include_prereleases,
|
|
8099
8113
|
)
|
|
8100
|
-
if
|
|
8114
|
+
if outcome.deferred:
|
|
8115
|
+
# Nothing ran; the guidance names the command to run instead.
|
|
8116
|
+
await self._mount_message(AppMessage(outcome.output))
|
|
8117
|
+
return
|
|
8118
|
+
if not outcome.success:
|
|
8101
8119
|
# Lead with the start of the output for parity with the upgrade
|
|
8102
8120
|
# failure path; uv prints the actionable summary (e.g. "No solution
|
|
8103
8121
|
# found") first. The full output is persisted to the update log.
|
|
8104
|
-
detail = f": {output[:200]}" if output else ""
|
|
8122
|
+
detail = f": {outcome.output[:200]}" if outcome.output else ""
|
|
8105
8123
|
await self._mount_message(
|
|
8106
8124
|
AppMessage(
|
|
8107
8125
|
f"Dependency refresh failed{detail}",
|
|
8108
8126
|
),
|
|
8109
8127
|
)
|
|
8110
8128
|
return
|
|
8111
|
-
changes = parse_dependency_changes(output)
|
|
8112
|
-
if output.strip() and not changes:
|
|
8129
|
+
changes = parse_dependency_changes(outcome.output)
|
|
8130
|
+
if outcome.output.strip() and not changes:
|
|
8113
8131
|
# The refresh succeeded but nothing parsed out of uv's diff. Either
|
|
8114
8132
|
# nothing moved, or uv's output format drifted past our parser. Leave
|
|
8115
8133
|
# a breadcrumb so the latter doesn't masquerade as "up to date"
|
|
@@ -8454,6 +8472,11 @@ class DeepAgentsApp(App):
|
|
|
8454
8472
|
)
|
|
8455
8473
|
return False
|
|
8456
8474
|
|
|
8475
|
+
if outcome.deferred:
|
|
8476
|
+
# Nothing ran; the guidance names the command to run instead.
|
|
8477
|
+
await self._mount_message(AppMessage(outcome.output))
|
|
8478
|
+
return False
|
|
8479
|
+
|
|
8457
8480
|
if not outcome.success:
|
|
8458
8481
|
# Tail the last 200 chars — uv resolver prints the resolved
|
|
8459
8482
|
# error at the end, not the beginning.
|
|
@@ -8662,7 +8685,7 @@ class DeepAgentsApp(App):
|
|
|
8662
8685
|
)
|
|
8663
8686
|
)
|
|
8664
8687
|
raise asyncio.CancelledError
|
|
8665
|
-
if outcome.extra_was_absent:
|
|
8688
|
+
if outcome.extra_was_absent or outcome.deferred:
|
|
8666
8689
|
await self._mount_message(AppMessage(outcome.output))
|
|
8667
8690
|
return
|
|
8668
8691
|
if not outcome.success:
|
|
@@ -8822,7 +8845,7 @@ class DeepAgentsApp(App):
|
|
|
8822
8845
|
AppMessage(f"Installing package '{package}'..."),
|
|
8823
8846
|
)
|
|
8824
8847
|
try:
|
|
8825
|
-
|
|
8848
|
+
outcome = await perform_install_package(package, log_path=log_path)
|
|
8826
8849
|
except OSError as exc:
|
|
8827
8850
|
# Let `asyncio.CancelledError` propagate: on the message pump
|
|
8828
8851
|
# swallowing it would suppress shutdown, and on the detached
|
|
@@ -8835,8 +8858,13 @@ class DeepAgentsApp(App):
|
|
|
8835
8858
|
)
|
|
8836
8859
|
return
|
|
8837
8860
|
|
|
8838
|
-
if
|
|
8839
|
-
|
|
8861
|
+
if outcome.deferred:
|
|
8862
|
+
# Nothing ran; the guidance names the command to run instead.
|
|
8863
|
+
await self._mount_message(AppMessage(outcome.output))
|
|
8864
|
+
return
|
|
8865
|
+
|
|
8866
|
+
if not outcome.success:
|
|
8867
|
+
detail = f": {outcome.output[-200:]}" if outcome.output else ""
|
|
8840
8868
|
await self._mount_message(
|
|
8841
8869
|
ErrorMessage(
|
|
8842
8870
|
f"Install failed{detail}\nLog: {log_path}",
|
|
@@ -14951,7 +14979,7 @@ class DeepAgentsApp(App):
|
|
|
14951
14979
|
try:
|
|
14952
14980
|
import httpx
|
|
14953
14981
|
|
|
14954
|
-
async with httpx.AsyncClient(timeout=2.0) as client:
|
|
14982
|
+
async with httpx.AsyncClient(timeout=2.0, trust_env=False) as client:
|
|
14955
14983
|
response = await client.get(f"{self._server_proc.url}/extensions")
|
|
14956
14984
|
response.raise_for_status()
|
|
14957
14985
|
payload = response.json()
|
|
@@ -15268,7 +15296,9 @@ class DeepAgentsApp(App):
|
|
|
15268
15296
|
latest = latest_goal_state_notice(messages)
|
|
15269
15297
|
latest_candidate = latest_goal_state_message_index(messages)
|
|
15270
15298
|
fingerprint = goal_state_fingerprint(desired_state)
|
|
15271
|
-
event =
|
|
15299
|
+
event = _anchor_summarization_event(
|
|
15300
|
+
state_values.get("_summarization_event"), messages
|
|
15301
|
+
)
|
|
15272
15302
|
validated_cutoff = _validated_summarization_cutoff(
|
|
15273
15303
|
event,
|
|
15274
15304
|
message_count=len(messages),
|
|
@@ -19049,6 +19079,7 @@ class DeepAgentsApp(App):
|
|
|
19049
19079
|
config=config,
|
|
19050
19080
|
context=self._offload_context(self._lc_thread_id),
|
|
19051
19081
|
fulfill_hook=self._hooks.fulfill_interrupt,
|
|
19082
|
+
offload_trigger="idle" if automatic else "manual",
|
|
19052
19083
|
)
|
|
19053
19084
|
await self._sync_session_cost_from_checkpoint()
|
|
19054
19085
|
|
|
@@ -28061,9 +28092,7 @@ class DeepAgentsApp(App):
|
|
|
28061
28092
|
return
|
|
28062
28093
|
self._notice_registry.remove(entry.key)
|
|
28063
28094
|
if deferred:
|
|
28064
|
-
logger.info(
|
|
28065
|
-
"Deferred the Python migration for v%s", payload.latest
|
|
28066
|
-
)
|
|
28095
|
+
logger.info("Deferred the update to v%s", payload.latest)
|
|
28067
28096
|
screen.mark_warning("Update deferred. See details.")
|
|
28068
28097
|
return
|
|
28069
28098
|
logger.warning(
|
deepagents_code/btw.py
CHANGED
|
@@ -43,6 +43,7 @@ from langgraph.runtime import Runtime
|
|
|
43
43
|
from langgraph.types import Command
|
|
44
44
|
|
|
45
45
|
from deepagents_code._tool_free import tool_free_model, tool_free_settings
|
|
46
|
+
from deepagents_code.goal_state_notice import anchor_summarization_event
|
|
46
47
|
|
|
47
48
|
if TYPE_CHECKING:
|
|
48
49
|
from collections.abc import AsyncGenerator, Awaitable, Callable, Sequence
|
|
@@ -310,7 +311,7 @@ def _conversation(state: Mapping[str, object]) -> list[AnyMessage]:
|
|
|
310
311
|
if isinstance(raw, list)
|
|
311
312
|
else []
|
|
312
313
|
)
|
|
313
|
-
event = state.get("_summarization_event")
|
|
314
|
+
event = anchor_summarization_event(state.get("_summarization_event"), messages)
|
|
314
315
|
if isinstance(event, dict):
|
|
315
316
|
cutoff = event.get("cutoff_index")
|
|
316
317
|
summary = event.get("summary_message")
|
|
@@ -123,6 +123,10 @@ def run_uninstall_request(*, name: str) -> int:
|
|
|
123
123
|
if outcome.extra_was_absent:
|
|
124
124
|
console.print(escape(outcome.output), highlight=False)
|
|
125
125
|
return 0
|
|
126
|
+
if outcome.deferred:
|
|
127
|
+
# Nothing ran. `soft_wrap` keeps the command on one line to paste.
|
|
128
|
+
console.print(outcome.output, markup=False, highlight=False, soft_wrap=True)
|
|
129
|
+
return 1
|
|
126
130
|
if outcome.success:
|
|
127
131
|
console.print(
|
|
128
132
|
f"[green]Uninstalled extra '{name}'.[/green] Its packages are already "
|
|
@@ -260,15 +264,22 @@ def _run_install_package(*, name: str, yes: bool) -> int:
|
|
|
260
264
|
highlight=False,
|
|
261
265
|
markup=False,
|
|
262
266
|
)
|
|
263
|
-
|
|
264
|
-
perform_install_package(
|
|
267
|
+
outcome = asyncio.run(
|
|
268
|
+
perform_install_package(
|
|
269
|
+
package,
|
|
270
|
+
log_path=pkg_log_path,
|
|
271
|
+
)
|
|
265
272
|
)
|
|
266
|
-
if success:
|
|
273
|
+
if outcome.success:
|
|
267
274
|
console.print(f"[green]Installed package '{package}'.[/green]")
|
|
268
275
|
return 0
|
|
276
|
+
if outcome.deferred:
|
|
277
|
+
# Nothing ran. `soft_wrap` keeps the command on one line to paste.
|
|
278
|
+
console.print(outcome.output, markup=False, highlight=False, soft_wrap=True)
|
|
279
|
+
return 1
|
|
269
280
|
# Tail the last 200 chars — uv prints the resolved error at the end.
|
|
270
281
|
# The full output is in the log.
|
|
271
|
-
detail = f": {output[-200:]}" if output else ""
|
|
282
|
+
detail = f": {outcome.output[-200:]}" if outcome.output else ""
|
|
272
283
|
console.print(
|
|
273
284
|
f"[bold red]Install failed[/bold red]{escape(detail)}\nLog: {pkg_log_path}",
|
|
274
285
|
markup=True,
|
|
@@ -376,6 +387,10 @@ def _run_install_extra(*, name: str, yes: bool) -> int:
|
|
|
376
387
|
if outcome.success:
|
|
377
388
|
console.print(f"[green]Installed extra '{extra}'.[/green]")
|
|
378
389
|
return 0
|
|
390
|
+
if outcome.deferred:
|
|
391
|
+
# Nothing ran. `soft_wrap` keeps the command on one line to paste.
|
|
392
|
+
console.print(outcome.output, markup=False, highlight=False, soft_wrap=True)
|
|
393
|
+
return 1
|
|
379
394
|
# Tail the last 200 chars — uv resolver prints the resolved error at
|
|
380
395
|
# the end, not the beginning.
|
|
381
396
|
detail = f": {outcome.output[-200:]}" if outcome.output else ""
|
|
@@ -312,6 +312,10 @@ def _scoped_env_overrides(
|
|
|
312
312
|
# ---------------------------------------------------------------------------
|
|
313
313
|
|
|
314
314
|
|
|
315
|
+
class ServerStartupTimeoutError(RuntimeError):
|
|
316
|
+
"""The server did not finish starting before the health-check deadline."""
|
|
317
|
+
|
|
318
|
+
|
|
315
319
|
async def wait_for_server_healthy(
|
|
316
320
|
url: str,
|
|
317
321
|
*,
|
|
@@ -329,7 +333,7 @@ async def wait_for_server_healthy(
|
|
|
329
333
|
we fail fast instead of waiting for the timeout.
|
|
330
334
|
read_log: Optional callable returning log file contents (for
|
|
331
335
|
error messages on early exit).
|
|
332
|
-
local:
|
|
336
|
+
local: Connect directly and use a shorter poll interval for local servers.
|
|
333
337
|
|
|
334
338
|
Raises:
|
|
335
339
|
ModelConfigError: If startup reports missing credentials or a provider package.
|
|
@@ -345,7 +349,7 @@ async def wait_for_server_healthy(
|
|
|
345
349
|
last_status: int | None = None
|
|
346
350
|
last_exc: Exception | None = None
|
|
347
351
|
|
|
348
|
-
async with httpx.AsyncClient() as client:
|
|
352
|
+
async with httpx.AsyncClient(trust_env=not local) as client:
|
|
349
353
|
while time.monotonic() < deadline:
|
|
350
354
|
if process and process.poll() is not None:
|
|
351
355
|
output = read_log() if read_log else ""
|
|
@@ -376,7 +380,16 @@ async def wait_for_server_healthy(
|
|
|
376
380
|
msg += f" (last status: {last_status})"
|
|
377
381
|
elif last_exc is not None:
|
|
378
382
|
msg += f" (last error: {last_exc})"
|
|
379
|
-
|
|
383
|
+
output = read_log() if read_log else ""
|
|
384
|
+
summary = _extract_startup_error_marker(output)
|
|
385
|
+
if summary:
|
|
386
|
+
msg = f"{msg}: {summary}"
|
|
387
|
+
if output:
|
|
388
|
+
msg += f"\n{output[-_LOG_TAIL_CHARS:]}"
|
|
389
|
+
error = startup_error_from_output(output, msg)
|
|
390
|
+
if type(error) is RuntimeError:
|
|
391
|
+
error = ServerStartupTimeoutError(msg)
|
|
392
|
+
raise error
|
|
380
393
|
|
|
381
394
|
|
|
382
395
|
# ---------------------------------------------------------------------------
|
|
@@ -432,6 +445,9 @@ def _build_server_env() -> dict[str, str]:
|
|
|
432
445
|
# dcode pins `langgraph-api`, so the PyPI upgrade check only costs a network
|
|
433
446
|
# fetch at startup and logs a `pip install -U` hint users cannot act on.
|
|
434
447
|
env["LANGGRAPH_NO_VERSION_CHECK"] = "1"
|
|
448
|
+
# Server output only goes to the log file, and colored logs on Windows need
|
|
449
|
+
# colorama, which a fresh install no longer pulls in.
|
|
450
|
+
env["LOG_COLOR"] = "false"
|
|
435
451
|
env[INVOKED_AS] = invoked_name()
|
|
436
452
|
|
|
437
453
|
# Capture a launch-time PYTHONPATH before stripping it. Never trust inherited
|
|
@@ -1126,7 +1142,7 @@ class ServerProcess:
|
|
|
1126
1142
|
graph_url = f"{self.url}/assistants/{quote(graph_name, safe='')}/graph"
|
|
1127
1143
|
deadline = time.monotonic() + timeout
|
|
1128
1144
|
|
|
1129
|
-
async with httpx.AsyncClient() as client:
|
|
1145
|
+
async with httpx.AsyncClient(trust_env=False) as client:
|
|
1130
1146
|
while time.monotonic() < deadline:
|
|
1131
1147
|
if self._process.poll() is not None:
|
|
1132
1148
|
msg = f"Server process exited with code {self._process.returncode}"
|
|
@@ -12,7 +12,7 @@ import asyncio
|
|
|
12
12
|
import logging
|
|
13
13
|
from collections.abc import Mapping
|
|
14
14
|
from contextlib import aclosing
|
|
15
|
-
from typing import TYPE_CHECKING, Any, cast
|
|
15
|
+
from typing import TYPE_CHECKING, Any, Literal, cast
|
|
16
16
|
|
|
17
17
|
from deepagents_code.client.session_cost import SessionCostTracker
|
|
18
18
|
|
|
@@ -705,6 +705,7 @@ class RemoteAgent:
|
|
|
705
705
|
context: Mapping[str, Any],
|
|
706
706
|
fulfill_hook: Callable[[object], Awaitable[dict[str, object]]],
|
|
707
707
|
handoff: bool = False,
|
|
708
|
+
offload_trigger: Literal["manual", "idle"] = "manual",
|
|
708
709
|
) -> OffloadResult:
|
|
709
710
|
"""Request server-owned offload and fulfill its hook callbacks.
|
|
710
711
|
|
|
@@ -714,6 +715,8 @@ class RemoteAgent:
|
|
|
714
715
|
fulfill_hook: Client hook executor for server requests.
|
|
715
716
|
handoff: Summarize every message for a new thread without
|
|
716
717
|
compacting the source thread.
|
|
718
|
+
offload_trigger: Why this offload runs, recorded in the
|
|
719
|
+
summarizer's trace metadata as `dcode_offload_trigger`.
|
|
717
720
|
|
|
718
721
|
Returns:
|
|
719
722
|
Typed offload result from the server operation.
|
|
@@ -742,6 +745,7 @@ class RemoteAgent:
|
|
|
742
745
|
self._ownership_headers(self._prepare_mutation(config))
|
|
743
746
|
)
|
|
744
747
|
operation_context["workspace"] = workspace
|
|
748
|
+
operation_context["offload_trigger"] = offload_trigger
|
|
745
749
|
# The operation reads and writes thread state over HTTP, so the thread's
|
|
746
750
|
# live row must exist first. Checkpoint persistence and registration are
|
|
747
751
|
# separate on the dev server (see `aensure_thread`), so a resumed thread
|
deepagents_code/config.py
CHANGED
|
@@ -2823,6 +2823,10 @@ def build_stream_config(
|
|
|
2823
2823
|
metadata. This is a diagnostic key, not the contract-scoped `approval_policy`
|
|
2824
2824
|
key (see above), so it is safe to stamp trace-wide.
|
|
2825
2825
|
|
|
2826
|
+
Also records `dcode_idle_compaction` and `dcode_idle_compaction_tokens` from
|
|
2827
|
+
the resolved history setting so traces can be filtered by whether idle
|
|
2828
|
+
compaction is configured, independently of whether it actually runs.
|
|
2829
|
+
|
|
2826
2830
|
Also records `dcode_term_program` from `TERM_PROGRAM` when that is non-empty
|
|
2827
2831
|
after stripping, so traces are groupable by launch environment (e.g.
|
|
2828
2832
|
"iTerm.app", "vscode", "Apple_Terminal"). Blank values are treated as unset
|
|
@@ -2879,6 +2883,16 @@ def build_stream_config(
|
|
|
2879
2883
|
if auto_approve:
|
|
2880
2884
|
metadata["dcode_auto_approve"] = True
|
|
2881
2885
|
|
|
2886
|
+
from deepagents_code.config_manifest import get_option
|
|
2887
|
+
from deepagents_code.configuration.resolver import get_config_resolver
|
|
2888
|
+
|
|
2889
|
+
idle_option = get_option("history.idle_compaction_tokens")
|
|
2890
|
+
idle_threshold = get_config_resolver().get(idle_option).value if idle_option else 0
|
|
2891
|
+
metadata["dcode_idle_compaction"] = (
|
|
2892
|
+
isinstance(idle_threshold, int) and idle_threshold > 0
|
|
2893
|
+
)
|
|
2894
|
+
metadata["dcode_idle_compaction_tokens"] = idle_threshold
|
|
2895
|
+
|
|
2882
2896
|
if skill_name:
|
|
2883
2897
|
metadata["ls_skill_name"] = skill_name
|
|
2884
2898
|
|
|
@@ -352,6 +352,51 @@ def build_goal_continuation(
|
|
|
352
352
|
)
|
|
353
353
|
|
|
354
354
|
|
|
355
|
+
def anchor_summarization_event[EventT](
|
|
356
|
+
event: EventT, messages: Sequence[object]
|
|
357
|
+
) -> EventT:
|
|
358
|
+
"""Return `event` with `cutoff_index` moved to where `cutoff_message_id` now sits.
|
|
359
|
+
|
|
360
|
+
Removing or re-adding messages before the cutoff shifts the stored index but
|
|
361
|
+
not the id. Rewriting the index here lets every index-based reader, including
|
|
362
|
+
SDK releases that predate `cutoff_message_id`, agree on the same cutoff.
|
|
363
|
+
|
|
364
|
+
Args:
|
|
365
|
+
event: A `_summarization_event` mapping as persisted in state, or `None`.
|
|
366
|
+
messages: Full persisted message list, as objects or serialized dicts.
|
|
367
|
+
|
|
368
|
+
Returns:
|
|
369
|
+
An anchored copy of `event`, or `event` unchanged when it has no
|
|
370
|
+
resolvable id.
|
|
371
|
+
"""
|
|
372
|
+
if not isinstance(event, Mapping):
|
|
373
|
+
return event
|
|
374
|
+
cutoff_id = event.get("cutoff_message_id")
|
|
375
|
+
stored = event.get("cutoff_index")
|
|
376
|
+
if not cutoff_id or not isinstance(stored, int) or isinstance(stored, bool):
|
|
377
|
+
return event
|
|
378
|
+
index = next(
|
|
379
|
+
(
|
|
380
|
+
i
|
|
381
|
+
for i, message in enumerate(messages)
|
|
382
|
+
if (
|
|
383
|
+
message.get("id")
|
|
384
|
+
if isinstance(message, Mapping)
|
|
385
|
+
else getattr(message, "id", None)
|
|
386
|
+
)
|
|
387
|
+
== cutoff_id
|
|
388
|
+
),
|
|
389
|
+
None,
|
|
390
|
+
)
|
|
391
|
+
if index is None or index == stored:
|
|
392
|
+
return event
|
|
393
|
+
anchored = {**event, "cutoff_index": index}
|
|
394
|
+
created_at = event.get("created_at_index")
|
|
395
|
+
if isinstance(created_at, int) and not isinstance(created_at, bool):
|
|
396
|
+
anchored["created_at_index"] = created_at + index - stored
|
|
397
|
+
return cast("EventT", anchored)
|
|
398
|
+
|
|
399
|
+
|
|
355
400
|
def validated_summarization_cutoff(
|
|
356
401
|
event: object,
|
|
357
402
|
*,
|
deepagents_code/goal_tools.py
CHANGED
|
@@ -36,6 +36,7 @@ from deepagents_code.goal_state_limits import (
|
|
|
36
36
|
validate_goal_status_note,
|
|
37
37
|
)
|
|
38
38
|
from deepagents_code.goal_state_notice import (
|
|
39
|
+
anchor_summarization_event,
|
|
39
40
|
build_goal_state_notice,
|
|
40
41
|
goal_notice_size_error,
|
|
41
42
|
goal_state_fingerprint,
|
|
@@ -381,7 +382,7 @@ class GoalToolsMiddleware(AgentMiddleware[GoalToolState, ContextT]):
|
|
|
381
382
|
# predicate in `app.py`. A malformed event diverges deliberately: `app.py`
|
|
382
383
|
# collapses it to `0`, while here it forces a fresh notice and clears the
|
|
383
384
|
# event.
|
|
384
|
-
event = values.get("_summarization_event")
|
|
385
|
+
event = anchor_summarization_event(values.get("_summarization_event"), messages)
|
|
385
386
|
cutoff = validated_summarization_cutoff(
|
|
386
387
|
event,
|
|
387
388
|
message_count=len(messages),
|
|
@@ -489,7 +490,13 @@ class GoalToolsMiddleware(AgentMiddleware[GoalToolState, ContextT]):
|
|
|
489
490
|
`_summarization_event` — a state override nulling that event.
|
|
490
491
|
"""
|
|
491
492
|
values = cast("dict[str, Any]", request.state)
|
|
492
|
-
|
|
493
|
+
raw_event = values.get("_summarization_event")
|
|
494
|
+
event = anchor_summarization_event(raw_event, request.messages)
|
|
495
|
+
if event is not raw_event:
|
|
496
|
+
# Inner SDK releases without `cutoff_message_id` slice by the
|
|
497
|
+
# stored index, so hand them the anchored event.
|
|
498
|
+
values = {**values, "_summarization_event": event}
|
|
499
|
+
request = request.override(state=cast("AgentState[Any]", values))
|
|
493
500
|
cutoff = validated_summarization_cutoff(
|
|
494
501
|
event,
|
|
495
502
|
message_count=len(request.messages),
|
deepagents_code/hooks/loading.py
CHANGED
|
@@ -391,6 +391,22 @@ def _read_hooks_document(
|
|
|
391
391
|
if not decoded:
|
|
392
392
|
return None, read_diagnostics, None
|
|
393
393
|
|
|
394
|
+
document, diagnostics = parse_hooks_document(data, path)
|
|
395
|
+
return document, diagnostics, fingerprint
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
def parse_hooks_document(
|
|
399
|
+
data: object, path: Path
|
|
400
|
+
) -> tuple[HooksConfig | None, tuple[HookDiagnostic, ...]]:
|
|
401
|
+
"""Validate decoded file configuration, including legacy migration.
|
|
402
|
+
|
|
403
|
+
Args:
|
|
404
|
+
data: Decoded file document.
|
|
405
|
+
path: Source location for diagnostics.
|
|
406
|
+
|
|
407
|
+
Returns:
|
|
408
|
+
Validated configuration and diagnostics.
|
|
409
|
+
"""
|
|
394
410
|
if is_legacy_hooks_document(data):
|
|
395
411
|
hooks = data.get("hooks", []) if isinstance(data, dict) else []
|
|
396
412
|
if not isinstance(hooks, list):
|
|
@@ -402,7 +418,7 @@ def _read_hooks_document(
|
|
|
402
418
|
field=str(path),
|
|
403
419
|
),
|
|
404
420
|
)
|
|
405
|
-
return None, diagnostics
|
|
421
|
+
return None, diagnostics
|
|
406
422
|
legacy_entries: list[dict[str, object]] = [
|
|
407
423
|
{str(key): value for key, value in item.items()}
|
|
408
424
|
for item in hooks
|
|
@@ -435,10 +451,9 @@ def _read_hooks_document(
|
|
|
435
451
|
field=str(path),
|
|
436
452
|
),
|
|
437
453
|
)
|
|
438
|
-
return migrated, diagnostics
|
|
454
|
+
return migrated, diagnostics
|
|
439
455
|
|
|
440
|
-
|
|
441
|
-
return document, diagnostics, fingerprint
|
|
456
|
+
return _validate_hooks_document(data, path)
|
|
442
457
|
|
|
443
458
|
|
|
444
459
|
def _validate_hooks_document(
|
deepagents_code/local_context.py
CHANGED
|
@@ -41,6 +41,7 @@ from deepagents_code._constants import (
|
|
|
41
41
|
LOCAL_CONTEXT_MESSAGE_SOURCE,
|
|
42
42
|
SYSTEM_MESSAGE_PREFIX,
|
|
43
43
|
)
|
|
44
|
+
from deepagents_code.goal_state_notice import anchor_summarization_event
|
|
44
45
|
from deepagents_code.unicode_security import sanitize_control_chars
|
|
45
46
|
|
|
46
47
|
if TYPE_CHECKING:
|
|
@@ -957,9 +958,9 @@ class LocalContextMiddleware(AgentMiddleware):
|
|
|
957
958
|
raw_event = state.get("_summarization_event")
|
|
958
959
|
if raw_event is None:
|
|
959
960
|
return None
|
|
960
|
-
event: SummarizationEvent = raw_event
|
|
961
|
-
cutoff = event.get("cutoff_index")
|
|
962
961
|
messages = state.get("messages", [])
|
|
962
|
+
event: SummarizationEvent = anchor_summarization_event(raw_event, messages)
|
|
963
|
+
cutoff = event.get("cutoff_index")
|
|
963
964
|
if (
|
|
964
965
|
not isinstance(cutoff, int)
|
|
965
966
|
or isinstance(cutoff, bool)
|
deepagents_code/main.py
CHANGED
|
@@ -616,6 +616,7 @@ def _run_startup_auto_update(console: Console) -> None:
|
|
|
616
616
|
from deepagents_code._version import __version__ as cli_version
|
|
617
617
|
from deepagents_code.config import _is_editable_install
|
|
618
618
|
from deepagents_code.update_check import (
|
|
619
|
+
_is_windows,
|
|
619
620
|
clear_startup_auto_update_failure,
|
|
620
621
|
create_update_log_file,
|
|
621
622
|
detect_shadowed_dcode_safe,
|
|
@@ -764,7 +765,9 @@ def _run_startup_auto_update(console: Console) -> None:
|
|
|
764
765
|
from deepagents_code._session_lock import is_sole_session
|
|
765
766
|
|
|
766
767
|
sole_session = is_sole_session()
|
|
767
|
-
|
|
768
|
+
# Windows defers every uv install, not only migrations, so there
|
|
769
|
+
# `perform_upgrade` picks which deferral guidance to repeat.
|
|
770
|
+
if retrying_deferral and not sole_session and not _is_windows():
|
|
768
771
|
# Repeat the deferral without re-fetching the release's Python
|
|
769
772
|
# requirement or announcing an update that will not happen.
|
|
770
773
|
console.print(
|
|
@@ -797,7 +800,8 @@ def _run_startup_auto_update(console: Console) -> None:
|
|
|
797
800
|
|
|
798
801
|
def show_notice(message: str) -> None:
|
|
799
802
|
notices.append(message)
|
|
800
|
-
|
|
803
|
+
# A notice can name a command to paste, so keep it on one line.
|
|
804
|
+
console.print(message, markup=False, highlight=False, soft_wrap=True)
|
|
801
805
|
|
|
802
806
|
success, output, _installed = asyncio.run(
|
|
803
807
|
perform_upgrade(
|
|
@@ -866,7 +870,7 @@ def _run_startup_auto_update(console: Console) -> None:
|
|
|
866
870
|
if unverified:
|
|
867
871
|
_exit_after_unverified_update(console, persisted=persisted)
|
|
868
872
|
if deferred:
|
|
869
|
-
# Nothing failed: the notice above explains how to
|
|
873
|
+
# Nothing failed: the notice above explains how to update.
|
|
870
874
|
note = escape(_session_lock_unavailable_note())
|
|
871
875
|
message = f"{note}Continuing with v{cli_version}."
|
|
872
876
|
elif notices:
|
|
@@ -3873,6 +3877,29 @@ async def _run_acp_cli_async(
|
|
|
3873
3877
|
return exit_code
|
|
3874
3878
|
|
|
3875
3879
|
|
|
3880
|
+
def _is_session_launch(args: argparse.Namespace) -> bool:
|
|
3881
|
+
"""Return whether these arguments start an agent session.
|
|
3882
|
+
|
|
3883
|
+
Subcommands and the management flags (`--update`, `--install`,
|
|
3884
|
+
`--default-model` and the rest) exit without one, so piped stdin is their
|
|
3885
|
+
input rather than a prompt. A new flag that exits before the session starts
|
|
3886
|
+
belongs here too.
|
|
3887
|
+
|
|
3888
|
+
Returns:
|
|
3889
|
+
`True` for interactive and headless launches.
|
|
3890
|
+
"""
|
|
3891
|
+
if getattr(args, "command", None) is not None:
|
|
3892
|
+
return False
|
|
3893
|
+
return not (
|
|
3894
|
+
args.update
|
|
3895
|
+
or args.install
|
|
3896
|
+
or args.uninstall is not None
|
|
3897
|
+
or args.auto_update
|
|
3898
|
+
or args.clear_default_model
|
|
3899
|
+
or args.default_model is not None
|
|
3900
|
+
)
|
|
3901
|
+
|
|
3902
|
+
|
|
3876
3903
|
def apply_stdin_pipe(args: argparse.Namespace) -> None:
|
|
3877
3904
|
r"""Read piped stdin and merge it into the parsed CLI arguments.
|
|
3878
3905
|
|
|
@@ -5799,7 +5826,11 @@ def cli_main() -> None:
|
|
|
5799
5826
|
)
|
|
5800
5827
|
sys.exit(exit_code)
|
|
5801
5828
|
|
|
5802
|
-
|
|
5829
|
+
# Only a session takes piped stdin as its prompt. Everything else leaves
|
|
5830
|
+
# it alone, so a pipe that stays open cannot stall a subcommand and a
|
|
5831
|
+
# subcommand's own prompt reads the piped answer.
|
|
5832
|
+
if _is_session_launch(args):
|
|
5833
|
+
apply_stdin_pipe(args)
|
|
5803
5834
|
if args.non_interactive_message:
|
|
5804
5835
|
# Piped stdin turned this launch headless. It gets no prewarm
|
|
5805
5836
|
# thread, so install the redacting client now, as bootstrap would.
|
|
@@ -6198,7 +6229,11 @@ def cli_main() -> None:
|
|
|
6198
6229
|
|
|
6199
6230
|
def show_notice(message: str) -> None:
|
|
6200
6231
|
notices.append(message)
|
|
6201
|
-
|
|
6232
|
+
# A notice can name a command to paste, so keep it on
|
|
6233
|
+
# one line.
|
|
6234
|
+
console.print(
|
|
6235
|
+
message, markup=False, highlight=False, soft_wrap=True
|
|
6236
|
+
)
|
|
6202
6237
|
|
|
6203
6238
|
success, output, _installed = asyncio.run(
|
|
6204
6239
|
perform_upgrade(
|
deepagents_code/offload_api.py
CHANGED
|
@@ -686,6 +686,34 @@ def _validate_context(context: dict[str, Any]) -> None:
|
|
|
686
686
|
raise TypeError(msg)
|
|
687
687
|
|
|
688
688
|
|
|
689
|
+
_OFFLOAD_TRIGGERS = frozenset({"manual", "idle"})
|
|
690
|
+
"""Values a client may send as `context.offload_trigger`."""
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
def _offload_trigger(context: Mapping[str, object], *, handoff: bool) -> str:
|
|
694
|
+
"""Label why this offload ran, for the summarizer's trace metadata.
|
|
695
|
+
|
|
696
|
+
Lets traces separate idle compaction from a user's `/offload` so the
|
|
697
|
+
feature's cost effect can be measured. Telemetry only: an absent or
|
|
698
|
+
unrecognized value is recorded as `manual` rather than rejected.
|
|
699
|
+
|
|
700
|
+
Args:
|
|
701
|
+
context: The request's runtime context.
|
|
702
|
+
handoff: Whether this is a handoff summary for a new thread.
|
|
703
|
+
|
|
704
|
+
Returns:
|
|
705
|
+
`handoff`, `idle`, or `manual`.
|
|
706
|
+
"""
|
|
707
|
+
if handoff:
|
|
708
|
+
return "handoff"
|
|
709
|
+
trigger = context.get("offload_trigger")
|
|
710
|
+
return (
|
|
711
|
+
trigger
|
|
712
|
+
if isinstance(trigger, str) and trigger in _OFFLOAD_TRIGGERS
|
|
713
|
+
else "manual"
|
|
714
|
+
)
|
|
715
|
+
|
|
716
|
+
|
|
689
717
|
def _checkpoint_id(state: Mapping[str, object]) -> str:
|
|
690
718
|
checkpoint = state.get("checkpoint")
|
|
691
719
|
value = checkpoint.get("checkpoint_id") if isinstance(checkpoint, Mapping) else None
|
|
@@ -1186,7 +1214,10 @@ async def _execute_offload(
|
|
|
1186
1214
|
"checkpoint_id": checkpoint_id,
|
|
1187
1215
|
"checkpoint_ns": namespace,
|
|
1188
1216
|
"run_id": operation_id,
|
|
1189
|
-
}
|
|
1217
|
+
},
|
|
1218
|
+
"metadata": {
|
|
1219
|
+
"dcode_offload_trigger": _offload_trigger(context, handoff=handoff)
|
|
1220
|
+
},
|
|
1190
1221
|
},
|
|
1191
1222
|
)
|
|
1192
1223
|
token = var_child_runnable_config.set(config)
|