deepagents-code 0.2.5__py3-none-any.whl → 0.2.7__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.
Files changed (33) hide show
  1. deepagents_code/_build_info.py +1 -1
  2. deepagents_code/_env_vars.py +10 -0
  3. deepagents_code/_session_stats.py +19 -2
  4. deepagents_code/_version.py +1 -1
  5. deepagents_code/agent.py +8 -3
  6. deepagents_code/app.py +21 -4
  7. deepagents_code/btw.py +2 -1
  8. deepagents_code/client/launch/server.py +20 -4
  9. deepagents_code/client/non_interactive.py +17 -2
  10. deepagents_code/client/remote_client.py +5 -1
  11. deepagents_code/completion.py +987 -0
  12. deepagents_code/config.py +32 -0
  13. deepagents_code/config_manifest.py +13 -0
  14. deepagents_code/cost_tracking.py +26 -1
  15. deepagents_code/editor.py +22 -0
  16. deepagents_code/git_evidence.py +60 -55
  17. deepagents_code/git_trace.py +198 -30
  18. deepagents_code/goal_state_notice.py +45 -0
  19. deepagents_code/goal_tools.py +9 -2
  20. deepagents_code/hooks/loading.py +19 -4
  21. deepagents_code/local_context.py +3 -2
  22. deepagents_code/main.py +78 -7
  23. deepagents_code/offload_api.py +32 -1
  24. deepagents_code/offload_middleware.py +11 -2
  25. deepagents_code/tui/textual_adapter.py +9 -1
  26. deepagents_code/tui/widgets/messages.py +3 -1
  27. deepagents_code/ui.py +44 -0
  28. {deepagents_code-0.2.5.dist-info → deepagents_code-0.2.7.dist-info}/METADATA +11 -11
  29. {deepagents_code-0.2.5.dist-info → deepagents_code-0.2.7.dist-info}/RECORD +33 -32
  30. {deepagents_code-0.2.5.data → deepagents_code-0.2.7.data}/data/deepagents_code/default_agent_prompt.md +0 -0
  31. {deepagents_code-0.2.5.dist-info → deepagents_code-0.2.7.dist-info}/WHEEL +0 -0
  32. {deepagents_code-0.2.5.dist-info → deepagents_code-0.2.7.dist-info}/entry_points.txt +0 -0
  33. {deepagents_code-0.2.5.dist-info → deepagents_code-0.2.7.dist-info}/licenses/LICENSE +0 -0
@@ -1,3 +1,3 @@
1
1
  """Generated at build time. Do not edit or commit."""
2
2
 
3
- BUILD_COMMIT = "efa9f53"
3
+ BUILD_COMMIT = "6a8d452"
@@ -318,6 +318,16 @@ Set only through the launching shell or global `~/.deepagents/.env`; a project
318
318
  `.env` cannot set it.
319
319
  """
320
320
 
321
+ GIT_ATTRIBUTION = "DEEPAGENTS_CODE_GIT_ATTRIBUTION"
322
+ """Toggle git attribution of LangSmith traces (defaults to on).
323
+
324
+ When enabled and tracing is active, dcode runs bounded, read-only `git`
325
+ inspections around tools that can change a checkout, so traces record the
326
+ repository and branch the agent actually worked on. Set to a falsy value (`0`,
327
+ `false`, `no`, `off`, or empty) to skip these inspections entirely, for example
328
+ in very large repositories. Also configurable as `[tracing].git_attribution`.
329
+ """
330
+
321
331
  GOAL_AUTO_ACCEPT_CRITERIA = "DEEPAGENTS_CODE_GOAL_AUTO_ACCEPT_CRITERIA"
322
332
  """Apply generated goal criteria automatically in Auto mode.
323
333
 
@@ -1237,6 +1237,23 @@ def is_model_usage_event(data: object) -> bool:
1237
1237
  return isinstance(data, Mapping) and data.get("type") == MODEL_USAGE_EVENT_TYPE
1238
1238
 
1239
1239
 
1240
+ def is_summarization_started_event(data: object) -> bool:
1241
+ """Report whether a custom-stream payload marks a summarization call starting.
1242
+
1243
+ Args:
1244
+ data: A `custom` stream payload.
1245
+
1246
+ Returns:
1247
+ `True` when the payload is a summarization start event.
1248
+ """
1249
+ from deepagents_code.cost_tracking import SUMMARIZATION_STARTED_EVENT_TYPE
1250
+
1251
+ return (
1252
+ isinstance(data, Mapping)
1253
+ and data.get("type") == SUMMARIZATION_STARTED_EVENT_TYPE
1254
+ )
1255
+
1256
+
1240
1257
  def record_model_usage_event(
1241
1258
  stats: SessionStats,
1242
1259
  data: object,
@@ -1288,7 +1305,7 @@ def record_model_usage_event(
1288
1305
  or not isinstance(thread_id, str)
1289
1306
  or not thread_id
1290
1307
  or not isinstance(scope, str)
1291
- or not scope
1308
+ or (not scope and data.get("lc_source") != "summarization")
1292
1309
  or not isinstance(usage, Mapping)
1293
1310
  or not usage
1294
1311
  or not isinstance(model_name, str)
@@ -1319,7 +1336,7 @@ def record_model_usage_event(
1319
1336
  message,
1320
1337
  fallback_model=fallback_model,
1321
1338
  fallback_provider=fallback_provider,
1322
- kind="subagent",
1339
+ kind="subagent" if scope else "offload",
1323
1340
  recorded_requests=recorded_requests,
1324
1341
  attempt_scope=attempt_scope,
1325
1342
  invocation_id=invocation_id or None,
@@ -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" # x-release-please-version
5
+ __version__ = "0.2.7" # 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/agent.py CHANGED
@@ -115,6 +115,7 @@ from deepagents_code.config import (
115
115
  get_default_coding_instructions,
116
116
  get_glyphs,
117
117
  get_langsmith_project_name,
118
+ is_git_attribution_enabled,
118
119
  restore_user_langsmith_env,
119
120
  runtime_state,
120
121
  )
@@ -2832,7 +2833,11 @@ def create_cli_agent(
2832
2833
  if effective_cwd is not None
2833
2834
  else ""
2834
2835
  )
2835
- git_trace = GitTraceMiddleware(lambda: backend, trace_cwd)
2836
+ git_trace: list[AgentMiddleware[Any, Any]] = (
2837
+ [GitTraceMiddleware(lambda: backend, trace_cwd)]
2838
+ if is_git_attribution_enabled()
2839
+ else []
2840
+ )
2836
2841
 
2837
2842
  # Setup agent directory for persistent memory (if enabled)
2838
2843
  if enable_memory or enable_skills:
@@ -2893,7 +2898,7 @@ def create_cli_agent(
2893
2898
  ) -> list[AgentMiddleware[Any, Any]]:
2894
2899
  from deepagents_code.cost_tracking import CostTrackingMiddleware
2895
2900
 
2896
- middleware: list[AgentMiddleware[Any, Any]] = [git_trace]
2901
+ middleware: list[AgentMiddleware[Any, Any]] = [*git_trace]
2897
2902
  if resolved_interrupt_on is not None:
2898
2903
  middleware.append(AsyncApprovalHITLMiddleware(resolved_interrupt_on))
2899
2904
  if not has_explicit_model:
@@ -3074,7 +3079,7 @@ def create_cli_agent(
3074
3079
 
3075
3080
  # Build middleware stack based on enabled features
3076
3081
  agent_middleware: list[AgentMiddleware[Any, Any]] = [
3077
- git_trace,
3082
+ *git_trace,
3078
3083
  ConfigurableModelMiddleware(
3079
3084
  cli_max_retries=cli_max_retries,
3080
3085
  environ=environment,
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\nQueued changes were not applied. "
6862
- "Reissue those commands to try again."
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
@@ -14965,7 +14979,7 @@ class DeepAgentsApp(App):
14965
14979
  try:
14966
14980
  import httpx
14967
14981
 
14968
- async with httpx.AsyncClient(timeout=2.0) as client:
14982
+ async with httpx.AsyncClient(timeout=2.0, trust_env=False) as client:
14969
14983
  response = await client.get(f"{self._server_proc.url}/extensions")
14970
14984
  response.raise_for_status()
14971
14985
  payload = response.json()
@@ -15282,7 +15296,9 @@ class DeepAgentsApp(App):
15282
15296
  latest = latest_goal_state_notice(messages)
15283
15297
  latest_candidate = latest_goal_state_message_index(messages)
15284
15298
  fingerprint = goal_state_fingerprint(desired_state)
15285
- event = state_values.get("_summarization_event")
15299
+ event = _anchor_summarization_event(
15300
+ state_values.get("_summarization_event"), messages
15301
+ )
15286
15302
  validated_cutoff = _validated_summarization_cutoff(
15287
15303
  event,
15288
15304
  message_count=len(messages),
@@ -19063,6 +19079,7 @@ class DeepAgentsApp(App):
19063
19079
  config=config,
19064
19080
  context=self._offload_context(self._lc_thread_id),
19065
19081
  fulfill_hook=self._hooks.fulfill_interrupt,
19082
+ offload_trigger="idle" if automatic else "manual",
19066
19083
  )
19067
19084
  await self._sync_session_cost_from_checkpoint()
19068
19085
 
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")
@@ -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: Use a shorter poll interval for local servers.
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
- raise RuntimeError(msg)
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}"
@@ -48,6 +48,8 @@ from deepagents_code._session_stats import (
48
48
  UsageLedgerKey,
49
49
  classify_usage_kind,
50
50
  finalize_recorded_requests,
51
+ is_model_usage_event,
52
+ is_summarization_started_event,
51
53
  print_usage_table,
52
54
  record_message_usage,
53
55
  record_model_usage_event,
@@ -1669,7 +1671,16 @@ def _process_stream_chunk(
1669
1671
  if stream_mode == "updates" and isinstance(data, dict) and "__interrupt__" in data:
1670
1672
  _process_interrupts(cast("dict[str, list[Interrupt]]", data), state, console)
1671
1673
  elif stream_mode == "custom" and isinstance(data, dict):
1672
- if data.get("type") == "model_retry":
1674
+ if is_model_usage_event(data):
1675
+ record_model_usage_event(
1676
+ state.stats,
1677
+ data,
1678
+ active_thread_id=state.thread_id,
1679
+ fallback_model=runtime_state.model_name or "",
1680
+ fallback_provider=runtime_state.model_provider or "",
1681
+ recorded_requests=state.recorded_usage_requests,
1682
+ )
1683
+ elif data.get("type") == "model_retry":
1673
1684
  correlation = model_retry_from_event(data)
1674
1685
  if correlation is not None:
1675
1686
  _process_retry_lifecycle(
@@ -1965,7 +1976,9 @@ async def _stream_agent(
1965
1976
  ):
1966
1977
  summarization = _summarization_stream_status(chunk)
1967
1978
  compaction_id = _compaction_result_id(chunk)
1968
- if summarization is False and state.summarization_observed:
1979
+ if summarization:
1980
+ state.summarization_observed = True
1981
+ elif summarization is False and state.summarization_observed:
1969
1982
  if compaction_id is not None:
1970
1983
  state.completed_compaction_ids.add(compaction_id)
1971
1984
  await _after_headless_compact(state)
@@ -1996,6 +2009,8 @@ def _summarization_stream_status(chunk: object) -> bool | None:
1996
2009
  namespace, stream_mode, data = chunk
1997
2010
  if namespace:
1998
2011
  return None
2012
+ if stream_mode == "custom":
2013
+ return True if is_summarization_started_event(data) else None
1999
2014
  if (
2000
2015
  stream_mode != "messages"
2001
2016
  or not isinstance(data, tuple)
@@ -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