inspect-ai 0.3.99__py3-none-any.whl → 0.3.101__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 (138) hide show
  1. inspect_ai/_cli/eval.py +2 -1
  2. inspect_ai/_display/core/config.py +11 -5
  3. inspect_ai/_display/core/panel.py +66 -2
  4. inspect_ai/_display/core/textual.py +5 -2
  5. inspect_ai/_display/plain/display.py +1 -0
  6. inspect_ai/_display/rich/display.py +2 -2
  7. inspect_ai/_display/textual/widgets/transcript.py +37 -9
  8. inspect_ai/_eval/eval.py +13 -1
  9. inspect_ai/_eval/evalset.py +3 -2
  10. inspect_ai/_eval/run.py +2 -0
  11. inspect_ai/_eval/score.py +2 -4
  12. inspect_ai/_eval/task/log.py +3 -1
  13. inspect_ai/_eval/task/run.py +59 -81
  14. inspect_ai/_util/content.py +11 -6
  15. inspect_ai/_util/interrupt.py +2 -2
  16. inspect_ai/_util/text.py +7 -0
  17. inspect_ai/_util/working.py +8 -37
  18. inspect_ai/_view/__init__.py +0 -0
  19. inspect_ai/_view/schema.py +2 -1
  20. inspect_ai/_view/www/CLAUDE.md +15 -0
  21. inspect_ai/_view/www/dist/assets/index.css +307 -171
  22. inspect_ai/_view/www/dist/assets/index.js +24733 -21641
  23. inspect_ai/_view/www/log-schema.json +77 -3
  24. inspect_ai/_view/www/package.json +9 -5
  25. inspect_ai/_view/www/src/@types/log.d.ts +9 -0
  26. inspect_ai/_view/www/src/app/App.tsx +1 -15
  27. inspect_ai/_view/www/src/app/appearance/icons.ts +4 -1
  28. inspect_ai/_view/www/src/app/content/MetaDataGrid.tsx +24 -6
  29. inspect_ai/_view/www/src/app/content/MetadataGrid.module.css +0 -5
  30. inspect_ai/_view/www/src/app/content/RenderedContent.tsx +220 -205
  31. inspect_ai/_view/www/src/app/log-view/LogViewContainer.tsx +2 -1
  32. inspect_ai/_view/www/src/app/log-view/tabs/SamplesTab.tsx +5 -0
  33. inspect_ai/_view/www/src/app/log-view/tabs/grouping.ts +4 -4
  34. inspect_ai/_view/www/src/app/routing/navigationHooks.ts +22 -25
  35. inspect_ai/_view/www/src/app/routing/url.ts +84 -4
  36. inspect_ai/_view/www/src/app/samples/InlineSampleDisplay.module.css +0 -5
  37. inspect_ai/_view/www/src/app/samples/SampleDialog.module.css +1 -1
  38. inspect_ai/_view/www/src/app/samples/SampleDisplay.module.css +7 -0
  39. inspect_ai/_view/www/src/app/samples/SampleDisplay.tsx +24 -17
  40. inspect_ai/_view/www/src/app/samples/SampleSummaryView.module.css +1 -2
  41. inspect_ai/_view/www/src/app/samples/chat/ChatMessage.tsx +8 -6
  42. inspect_ai/_view/www/src/app/samples/chat/ChatMessageRow.tsx +0 -4
  43. inspect_ai/_view/www/src/app/samples/chat/ChatViewVirtualList.tsx +3 -2
  44. inspect_ai/_view/www/src/app/samples/chat/MessageContent.tsx +2 -0
  45. inspect_ai/_view/www/src/app/samples/chat/MessageContents.tsx +2 -0
  46. inspect_ai/_view/www/src/app/samples/chat/messages.ts +1 -0
  47. inspect_ai/_view/www/src/app/samples/chat/tools/ToolCallView.tsx +1 -0
  48. inspect_ai/_view/www/src/app/samples/list/SampleList.tsx +17 -5
  49. inspect_ai/_view/www/src/app/samples/list/SampleRow.tsx +1 -1
  50. inspect_ai/_view/www/src/app/samples/transcript/ErrorEventView.tsx +1 -2
  51. inspect_ai/_view/www/src/app/samples/transcript/InfoEventView.tsx +1 -1
  52. inspect_ai/_view/www/src/app/samples/transcript/InputEventView.tsx +1 -2
  53. inspect_ai/_view/www/src/app/samples/transcript/ModelEventView.module.css +1 -1
  54. inspect_ai/_view/www/src/app/samples/transcript/ModelEventView.tsx +1 -1
  55. inspect_ai/_view/www/src/app/samples/transcript/SampleInitEventView.tsx +1 -1
  56. inspect_ai/_view/www/src/app/samples/transcript/SampleLimitEventView.tsx +3 -2
  57. inspect_ai/_view/www/src/app/samples/transcript/SandboxEventView.tsx +4 -5
  58. inspect_ai/_view/www/src/app/samples/transcript/ScoreEventView.tsx +1 -1
  59. inspect_ai/_view/www/src/app/samples/transcript/SpanEventView.tsx +1 -2
  60. inspect_ai/_view/www/src/app/samples/transcript/StepEventView.tsx +1 -3
  61. inspect_ai/_view/www/src/app/samples/transcript/SubtaskEventView.tsx +1 -2
  62. inspect_ai/_view/www/src/app/samples/transcript/ToolEventView.tsx +3 -4
  63. inspect_ai/_view/www/src/app/samples/transcript/TranscriptPanel.module.css +42 -0
  64. inspect_ai/_view/www/src/app/samples/transcript/TranscriptPanel.tsx +77 -0
  65. inspect_ai/_view/www/src/app/samples/transcript/TranscriptVirtualList.tsx +27 -71
  66. inspect_ai/_view/www/src/app/samples/transcript/TranscriptVirtualListComponent.module.css +13 -3
  67. inspect_ai/_view/www/src/app/samples/transcript/TranscriptVirtualListComponent.tsx +27 -2
  68. inspect_ai/_view/www/src/app/samples/transcript/event/EventPanel.module.css +1 -0
  69. inspect_ai/_view/www/src/app/samples/transcript/event/EventPanel.tsx +21 -22
  70. inspect_ai/_view/www/src/app/samples/transcript/outline/OutlineRow.module.css +45 -0
  71. inspect_ai/_view/www/src/app/samples/transcript/outline/OutlineRow.tsx +223 -0
  72. inspect_ai/_view/www/src/app/samples/transcript/outline/TranscriptOutline.module.css +10 -0
  73. inspect_ai/_view/www/src/app/samples/transcript/outline/TranscriptOutline.tsx +258 -0
  74. inspect_ai/_view/www/src/app/samples/transcript/outline/tree-visitors.ts +187 -0
  75. inspect_ai/_view/www/src/app/samples/transcript/state/StateEventRenderers.tsx +8 -1
  76. inspect_ai/_view/www/src/app/samples/transcript/state/StateEventView.tsx +3 -4
  77. inspect_ai/_view/www/src/app/samples/transcript/transform/hooks.ts +78 -0
  78. inspect_ai/_view/www/src/app/samples/transcript/transform/treeify.ts +340 -135
  79. inspect_ai/_view/www/src/app/samples/transcript/transform/utils.ts +3 -0
  80. inspect_ai/_view/www/src/app/samples/transcript/types.ts +2 -0
  81. inspect_ai/_view/www/src/app/types.ts +5 -1
  82. inspect_ai/_view/www/src/client/api/api-browser.ts +2 -2
  83. inspect_ai/_view/www/src/components/LiveVirtualList.tsx +6 -1
  84. inspect_ai/_view/www/src/components/MarkdownDiv.tsx +1 -1
  85. inspect_ai/_view/www/src/components/PopOver.tsx +422 -0
  86. inspect_ai/_view/www/src/components/PulsingDots.module.css +9 -9
  87. inspect_ai/_view/www/src/components/PulsingDots.tsx +4 -1
  88. inspect_ai/_view/www/src/components/StickyScroll.tsx +183 -0
  89. inspect_ai/_view/www/src/components/TabSet.tsx +4 -0
  90. inspect_ai/_view/www/src/state/hooks.ts +52 -2
  91. inspect_ai/_view/www/src/state/logSlice.ts +4 -3
  92. inspect_ai/_view/www/src/state/samplePolling.ts +8 -0
  93. inspect_ai/_view/www/src/state/sampleSlice.ts +53 -9
  94. inspect_ai/_view/www/src/state/scrolling.ts +152 -0
  95. inspect_ai/_view/www/src/utils/attachments.ts +7 -0
  96. inspect_ai/_view/www/src/utils/python.ts +18 -0
  97. inspect_ai/_view/www/yarn.lock +290 -33
  98. inspect_ai/agent/_react.py +12 -7
  99. inspect_ai/agent/_run.py +2 -3
  100. inspect_ai/analysis/beta/__init__.py +2 -0
  101. inspect_ai/analysis/beta/_dataframe/samples/table.py +19 -18
  102. inspect_ai/dataset/_sources/csv.py +2 -6
  103. inspect_ai/dataset/_sources/hf.py +2 -6
  104. inspect_ai/dataset/_sources/json.py +2 -6
  105. inspect_ai/dataset/_util.py +23 -0
  106. inspect_ai/log/_log.py +1 -1
  107. inspect_ai/log/_recorders/eval.py +4 -3
  108. inspect_ai/log/_recorders/file.py +2 -9
  109. inspect_ai/log/_recorders/json.py +1 -0
  110. inspect_ai/log/_recorders/recorder.py +1 -0
  111. inspect_ai/log/_transcript.py +1 -1
  112. inspect_ai/model/_call_tools.py +6 -2
  113. inspect_ai/model/_openai.py +1 -1
  114. inspect_ai/model/_openai_responses.py +85 -41
  115. inspect_ai/model/_openai_web_search.py +38 -0
  116. inspect_ai/model/_providers/azureai.py +72 -3
  117. inspect_ai/model/_providers/openai.py +4 -1
  118. inspect_ai/model/_providers/openai_responses.py +5 -1
  119. inspect_ai/scorer/_metric.py +1 -2
  120. inspect_ai/scorer/_reducer/reducer.py +1 -1
  121. inspect_ai/solver/_task_state.py +2 -2
  122. inspect_ai/tool/_tool.py +6 -2
  123. inspect_ai/tool/_tool_def.py +27 -4
  124. inspect_ai/tool/_tool_info.py +2 -0
  125. inspect_ai/tool/_tools/_web_search/_google.py +43 -15
  126. inspect_ai/tool/_tools/_web_search/_tavily.py +46 -13
  127. inspect_ai/tool/_tools/_web_search/_web_search.py +214 -45
  128. inspect_ai/util/__init__.py +4 -0
  129. inspect_ai/util/_json.py +3 -0
  130. inspect_ai/util/_limit.py +230 -20
  131. inspect_ai/util/_sandbox/docker/compose.py +20 -11
  132. inspect_ai/util/_span.py +1 -1
  133. {inspect_ai-0.3.99.dist-info → inspect_ai-0.3.101.dist-info}/METADATA +3 -3
  134. {inspect_ai-0.3.99.dist-info → inspect_ai-0.3.101.dist-info}/RECORD +138 -124
  135. {inspect_ai-0.3.99.dist-info → inspect_ai-0.3.101.dist-info}/WHEEL +1 -1
  136. {inspect_ai-0.3.99.dist-info → inspect_ai-0.3.101.dist-info}/entry_points.txt +0 -0
  137. {inspect_ai-0.3.99.dist-info → inspect_ai-0.3.101.dist-info}/licenses/LICENSE +0 -0
  138. {inspect_ai-0.3.99.dist-info → inspect_ai-0.3.101.dist-info}/top_level.txt +0 -0
@@ -6,7 +6,9 @@ from inspect_ai.util._limit import (
6
6
  LimitScope,
7
7
  apply_limits,
8
8
  message_limit,
9
+ time_limit,
9
10
  token_limit,
11
+ working_limit,
10
12
  )
11
13
 
12
14
  from ._collect import collect
@@ -81,6 +83,8 @@ __all__ = [
81
83
  "subtask",
82
84
  "throttle",
83
85
  "token_limit",
86
+ "time_limit",
87
+ "working_limit",
84
88
  "trace_action",
85
89
  "trace_message",
86
90
  "RegistryType",
inspect_ai/util/_json.py CHANGED
@@ -3,6 +3,7 @@ import typing
3
3
  from copy import deepcopy
4
4
  from dataclasses import is_dataclass
5
5
  from datetime import date, datetime, time
6
+ from enum import EnumMeta
6
7
  from typing import (
7
8
  Any,
8
9
  Dict,
@@ -101,6 +102,8 @@ def json_schema(t: Type[Any]) -> JSONSchema:
101
102
  or (isinstance(t, type) and issubclass(t, BaseModel))
102
103
  ):
103
104
  return cls_json_schema(t)
105
+ elif isinstance(t, EnumMeta):
106
+ return JSONSchema(enum=[item.value for item in t])
104
107
  elif t is type(None):
105
108
  return JSONSchema(type="null")
106
109
  else:
inspect_ai/util/_limit.py CHANGED
@@ -7,6 +7,7 @@ from contextvars import ContextVar
7
7
  from types import TracebackType
8
8
  from typing import TYPE_CHECKING, Generic, Iterator, Literal, TypeVar
9
9
 
10
+ import anyio
10
11
  from typing_extensions import Self
11
12
 
12
13
  from inspect_ai._util.logger import warn_once
@@ -33,22 +34,23 @@ class LimitExceededError(Exception):
33
34
  value: Value compared to.
34
35
  limit: Limit applied.
35
36
  message (str | None): Optional. Human readable message.
36
- source (Limit | None): Optional. The `Limit` instance which was responsible for
37
- raising this error.
37
+ source (Limit | None): Optional. The `Limit` instance which was responsible for raising this error.
38
38
  """
39
39
 
40
40
  def __init__(
41
41
  self,
42
42
  type: Literal["message", "time", "working", "token", "operator", "custom"],
43
43
  *,
44
- value: int,
45
- limit: int,
44
+ value: float,
45
+ limit: float,
46
46
  message: str | None = None,
47
47
  source: Limit | None = None,
48
48
  ) -> None:
49
49
  self.type = type
50
50
  self.value = value
51
+ self.value_str = self._format_float_or_int(value)
51
52
  self.limit = limit
53
+ self.limit_str = self._format_float_or_int(limit)
52
54
  self.message = f"Exceeded {type} limit: {limit:,}"
53
55
  self.source = source
54
56
  super().__init__(message)
@@ -60,6 +62,12 @@ class LimitExceededError(Exception):
60
62
  )
61
63
  return self
62
64
 
65
+ def _format_float_or_int(self, value: float | int) -> str:
66
+ if isinstance(value, int):
67
+ return f"{value:,}"
68
+ else:
69
+ return f"{value:,.2f}"
70
+
63
71
 
64
72
  class Limit(abc.ABC):
65
73
  """Base class for all limit context managers."""
@@ -80,6 +88,12 @@ class Limit(abc.ABC):
80
88
  ) -> None:
81
89
  pass
82
90
 
91
+ @property
92
+ @abc.abstractmethod
93
+ def usage(self) -> float:
94
+ """The current usage of the resource being limited."""
95
+ pass
96
+
83
97
  def _check_reuse(self) -> None:
84
98
  if self._entered:
85
99
  raise RuntimeError(
@@ -112,18 +126,20 @@ def apply_limits(
112
126
  False, all `LimitExceededError` exceptions will be allowed to propagate.
113
127
  """
114
128
  limit_scope = LimitScope()
115
- with ExitStack() as stack:
116
- for limit in limits:
117
- stack.enter_context(limit)
118
- try:
129
+ # Try scope is outside the `with ExitStack()` so that we can catch any errors raised
130
+ # when exiting it (which will be where time_limit() would raise LimitExceededError).
131
+ try:
132
+ with ExitStack() as stack:
133
+ for limit in limits:
134
+ stack.enter_context(limit)
119
135
  yield limit_scope
120
- except LimitExceededError as e:
121
- # If it was not one of the limits we applied.
122
- if e.source is None or e.source not in limits:
123
- raise
124
- limit_scope.limit_error = e
125
- if not catch_errors:
126
- raise
136
+ except LimitExceededError as e:
137
+ # If it was not one of the limits we applied.
138
+ if e.source is None or e.source not in limits:
139
+ raise
140
+ limit_scope.limit_error = e
141
+ if not catch_errors:
142
+ raise
127
143
 
128
144
 
129
145
  class LimitScope:
@@ -140,8 +156,6 @@ def token_limit(limit: int | None) -> _TokenLimit:
140
156
  """Limits the total number of tokens which can be used.
141
157
 
142
158
  The counter starts when the context manager is opened and ends when it is closed.
143
- The context manager can be opened multiple times, even in different execution
144
- contexts.
145
159
 
146
160
  These limits can be stacked.
147
161
 
@@ -186,8 +200,7 @@ def message_limit(limit: int | None) -> _MessageLimit:
186
200
  """Limits the number of messages in a conversation.
187
201
 
188
202
  The total number of messages in the conversation are compared to the limit (not just
189
- "new" messages). The context manager can be opened multiple times, even in different
190
- execution contexts.
203
+ "new" messages).
191
204
 
192
205
  These limits can be stacked.
193
206
 
@@ -220,6 +233,62 @@ def check_message_limit(count: int, raise_for_equal: bool) -> None:
220
233
  node.check(count, raise_for_equal)
221
234
 
222
235
 
236
+ def time_limit(limit: float | None) -> _TimeLimit:
237
+ """Limits the wall clock time which can elapse.
238
+
239
+ The timer starts when the context manager is opened and stops when it is closed.
240
+
241
+ These limits can be stacked.
242
+
243
+ When a limit is exceeded, the code block is cancelled and a `LimitExceededError` is
244
+ raised.
245
+
246
+ Uses anyio's cancellation scopes meaning that the operations within the context
247
+ manager block are cancelled if the limit is exceeded. The `LimitExceededError` is
248
+ therefore raised at the level that the `time_limit()` context manager was opened,
249
+ not at the level of the operation which caused the limit to be exceeded (e.g. a call
250
+ to `generate()`). Ensure you handle `LimitExceededError` at the level of opening the context manager.
251
+
252
+ Args:
253
+ limit: The maximum number of seconds that can pass while the context manager is
254
+ open. A value of None means unlimited time.
255
+ """
256
+ return _TimeLimit(limit)
257
+
258
+
259
+ def working_limit(limit: float | None) -> _WorkingLimit:
260
+ """Limits the working time which can elapse.
261
+
262
+ Working time is the wall clock time minus any waiting time e.g. waiting before
263
+ retrying in response to rate limits or waiting on a semaphore.
264
+
265
+ The timer starts when the context manager is opened and stops when it is closed.
266
+
267
+ These limits can be stacked.
268
+
269
+ When a limit is exceeded, a `LimitExceededError` is raised.
270
+
271
+ Args:
272
+ limit: The maximum number of seconds of working that can pass while the context
273
+ manager is open. A value of None means unlimited time.
274
+ """
275
+ return _WorkingLimit(limit)
276
+
277
+
278
+ def record_waiting_time(waiting_time: float) -> None:
279
+ node = working_limit_tree.get()
280
+ if node is None:
281
+ return
282
+ node.record_waiting_time(waiting_time)
283
+
284
+
285
+ def check_working_limit() -> None:
286
+ node = working_limit_tree.get()
287
+ if node is None:
288
+ return
289
+ node.check()
290
+
291
+
223
292
  class _Tree(Generic[TNode]):
224
293
  """A tree data structure of limit nodes.
225
294
 
@@ -253,6 +322,7 @@ token_limit_tree: _Tree[_TokenLimit] = _Tree("token_limit_tree")
253
322
  # Store the message limit leaf node so that we know which limit to check in
254
323
  # check_message_limit().
255
324
  message_limit_tree: _Tree[_MessageLimit] = _Tree("message_limit_tree")
325
+ working_limit_tree: _Tree[_WorkingLimit] = _Tree("working_limit_tree")
256
326
 
257
327
 
258
328
  class _Node:
@@ -296,6 +366,10 @@ class _TokenLimit(Limit, _Node):
296
366
  ) -> None:
297
367
  self._pop_and_check_identity(token_limit_tree)
298
368
 
369
+ @property
370
+ def usage(self) -> float:
371
+ return self._usage.total_tokens
372
+
299
373
  @property
300
374
  def limit(self) -> int | None:
301
375
  """Get the configured token limit value."""
@@ -312,7 +386,7 @@ class _TokenLimit(Limit, _Node):
312
386
  self._limit = value
313
387
 
314
388
  def record(self, usage: ModelUsage) -> None:
315
- """Record model usage for this node and its parent nodes."""
389
+ """Record model usage for this node and its ancestor nodes."""
316
390
  if self.parent is not None:
317
391
  self.parent.record(usage)
318
392
  self._usage += usage
@@ -369,6 +443,13 @@ class _MessageLimit(Limit, _Node):
369
443
  ) -> None:
370
444
  self._pop_and_check_identity(message_limit_tree)
371
445
 
446
+ @property
447
+ def usage(self) -> float:
448
+ raise NotImplementedError(
449
+ "Retrieving the message count from a limit is not supported. Please query "
450
+ "the messages property on the task or agent state instead."
451
+ )
452
+
372
453
  @property
373
454
  def limit(self) -> int | None:
374
455
  """Get the configured message limit value."""
@@ -414,3 +495,132 @@ class _MessageLimit(Limit, _Node):
414
495
  raise ValueError(
415
496
  f"Message limit value must be a non-negative integer or None: {value}"
416
497
  )
498
+
499
+
500
+ class _TimeLimit(Limit):
501
+ def __init__(self, limit: float | None) -> None:
502
+ super().__init__()
503
+ _validate_time_limit("Time", limit)
504
+ self._limit = limit
505
+ self._start_time: float | None = None
506
+ self._end_time: float | None = None
507
+
508
+ def __enter__(self) -> Limit:
509
+ super()._check_reuse()
510
+ # Unlike the other limits, this one is not stored in a tree. Anyio handles all
511
+ # of the state.
512
+ self._cancel_scope = anyio.move_on_after(self._limit)
513
+ self._cancel_scope.__enter__()
514
+ self._start_time = anyio.current_time()
515
+ return self
516
+
517
+ def __exit__(
518
+ self,
519
+ exc_type: type[BaseException] | None,
520
+ exc_val: BaseException | None,
521
+ exc_tb: TracebackType | None,
522
+ ) -> None:
523
+ from inspect_ai.log._transcript import SampleLimitEvent, transcript
524
+
525
+ self._cancel_scope.__exit__(exc_type, exc_val, exc_tb)
526
+ self._end_time = anyio.current_time()
527
+ if self._cancel_scope.cancel_called and self._limit is not None:
528
+ message = f"Time limit exceeded. limit: {self._limit} seconds"
529
+ assert self._start_time is not None
530
+ # Note we've measured the elapsed time independently of anyio's cancel scope
531
+ # so this is an approximation.
532
+ time_elapsed = self._end_time - self._start_time
533
+ transcript()._event(
534
+ SampleLimitEvent(type="time", message=message, limit=self._limit)
535
+ )
536
+ raise LimitExceededError(
537
+ "time",
538
+ value=time_elapsed,
539
+ limit=self._limit,
540
+ message=message,
541
+ source=self,
542
+ ) from exc_val
543
+
544
+ @property
545
+ def usage(self) -> float:
546
+ if self._start_time is None:
547
+ return 0.0
548
+ if self._end_time is None:
549
+ return anyio.current_time() - self._start_time
550
+ return self._end_time - self._start_time
551
+
552
+
553
+ class _WorkingLimit(Limit, _Node):
554
+ def __init__(self, limit: float | None) -> None:
555
+ super().__init__()
556
+ _validate_time_limit("Working time", limit)
557
+ self._limit = limit
558
+ self.parent: _WorkingLimit | None = None
559
+ self._start_time: float | None = None
560
+ self._end_time: float | None = None
561
+
562
+ def __enter__(self) -> Limit:
563
+ super()._check_reuse()
564
+ self._start_time = anyio.current_time()
565
+ self._waiting_time = 0.0
566
+ working_limit_tree.push(self)
567
+ return self
568
+
569
+ def __exit__(
570
+ self,
571
+ exc_type: type[BaseException] | None,
572
+ exc_val: BaseException | None,
573
+ exc_tb: TracebackType | None,
574
+ ) -> None:
575
+ self._end_time = anyio.current_time()
576
+ self._pop_and_check_identity(working_limit_tree)
577
+
578
+ @property
579
+ def usage(self) -> float:
580
+ if self._start_time is None:
581
+ return 0.0
582
+ if self._end_time is None:
583
+ return anyio.current_time() - self._start_time - self._waiting_time
584
+ return self._end_time - self._start_time - self._waiting_time
585
+
586
+ def record_waiting_time(self, waiting_time: float) -> None:
587
+ """Record waiting time for this node and its ancestor nodes."""
588
+ if self.parent is not None:
589
+ self.parent.record_waiting_time(waiting_time)
590
+ self._waiting_time += waiting_time
591
+
592
+ def check(self) -> None:
593
+ """Check if this working time limit or any ancestor limits have been exceeded.
594
+
595
+ The checks occur from root to leaf. This is so that if multiple limits are
596
+ simultaneously exceeded, the outermost (closest to root) one raises the error,
597
+ preventing certain sub-agent architectures from ending up in an infinite loop.
598
+ """
599
+ if self.parent is not None:
600
+ self.parent.check()
601
+ self._check_self()
602
+
603
+ def _check_self(self) -> None:
604
+ from inspect_ai.log._transcript import SampleLimitEvent, transcript
605
+
606
+ if self._limit is None:
607
+ return
608
+ if self.usage > self._limit:
609
+ message = f"Working time limit exceeded. limit: {self._limit} seconds"
610
+ transcript()._event(
611
+ SampleLimitEvent(type="working", message=message, limit=self._limit)
612
+ )
613
+ raise LimitExceededError(
614
+ "working",
615
+ value=self.usage,
616
+ limit=self._limit,
617
+ message=message,
618
+ source=self,
619
+ )
620
+
621
+
622
+ def _validate_time_limit(name: str, value: float | None) -> None:
623
+ if value is not None and value < 0:
624
+ raise ValueError(
625
+ f"{name} limit value must be a non-negative float or None: {value}"
626
+ )
@@ -10,6 +10,7 @@ from pydantic import BaseModel
10
10
 
11
11
  from inspect_ai._util.error import PrerequisiteError
12
12
  from inspect_ai._util.trace import trace_message
13
+ from inspect_ai.util._concurrency import concurrency
13
14
  from inspect_ai.util._display import display_type
14
15
  from inspect_ai.util._subprocess import ExecResult, subprocess
15
16
 
@@ -303,18 +304,26 @@ async def compose_command(
303
304
  # build final command
304
305
  compose_command = compose_command + command
305
306
 
306
- # function to run command
307
+ # set a concurrency limit for docker CLI invocations.
308
+ # this should help with running more containers in parallel while avoiding hangs on some systems
309
+ DEFAULT_CLI_CONCURRENCY = max((os.cpu_count() or 1) * 2, 4)
310
+ docker_cli_concurrency = int(
311
+ os.environ.get("INSPECT_DOCKER_CLI_CONCURRENCY", DEFAULT_CLI_CONCURRENCY)
312
+ )
313
+
314
+ # function to run command (wrapped in concurrency limiter)
307
315
  async def run_command(command_timeout: int | None) -> ExecResult[str]:
308
- result = await subprocess(
309
- compose_command,
310
- input=input,
311
- cwd=cwd,
312
- env=env,
313
- timeout=command_timeout,
314
- capture_output=capture_output,
315
- output_limit=output_limit,
316
- )
317
- return result
316
+ async with concurrency("docker-cli", docker_cli_concurrency):
317
+ result = await subprocess(
318
+ compose_command,
319
+ input=input,
320
+ cwd=cwd,
321
+ env=env,
322
+ timeout=command_timeout,
323
+ capture_output=capture_output,
324
+ output_limit=output_limit,
325
+ )
326
+ return result
318
327
 
319
328
  # we have observed underlying unreliability in docker compose in some linux
320
329
  # environments on EC2 -- this exhibits in very simple commands (e.g. compose config)
inspect_ai/util/_span.py CHANGED
@@ -35,7 +35,7 @@ async def span(name: str, *, type: str | None = None) -> AsyncIterator[None]:
35
35
  SpanBeginEvent(
36
36
  id=id,
37
37
  parent_id=parent_id,
38
- type=type,
38
+ type=type or name,
39
39
  name=name,
40
40
  )
41
41
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: inspect_ai
3
- Version: 0.3.99
3
+ Version: 0.3.101
4
4
  Summary: Framework for large language model evaluations
5
5
  Author: UK AI Security Institute
6
6
  License: MIT License
@@ -40,7 +40,7 @@ Requires-Dist: nest_asyncio
40
40
  Requires-Dist: numpy
41
41
  Requires-Dist: platformdirs>=2.3.0
42
42
  Requires-Dist: psutil
43
- Requires-Dist: pydantic>=2
43
+ Requires-Dist: pydantic>=2.11.4
44
44
  Requires-Dist: python-dotenv>=0.16.0
45
45
  Requires-Dist: pyyaml
46
46
  Requires-Dist: rich<14.0.0,>=13.3.3
@@ -66,7 +66,7 @@ Requires-Dist: markdown; extra == "dev"
66
66
  Requires-Dist: mcp; extra == "dev"
67
67
  Requires-Dist: mistralai; extra == "dev"
68
68
  Requires-Dist: moto[server]; extra == "dev"
69
- Requires-Dist: mypy; extra == "dev"
69
+ Requires-Dist: mypy>=1.16.0; extra == "dev"
70
70
  Requires-Dist: nbformat; extra == "dev"
71
71
  Requires-Dist: openai; extra == "dev"
72
72
  Requires-Dist: pandas>=2.0.0; extra == "dev"