deepagents-code 0.2.6__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.
@@ -1,3 +1,3 @@
1
1
  """Generated at build time. Do not edit or commit."""
2
2
 
3
- BUILD_COMMIT = "eeeaee9"
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.6" # 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,
@@ -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)