11from __future__ import annotations
22
33import importlib .metadata
4- import uuid
54from collections .abc import Iterator
65from contextlib import contextmanager
76from contextvars import ContextVar
1312from ..configuration import StepExecutorConfiguration , StepExecutorConfigurationPatch
1413from ..errors import NighthawkError
1514from ..tools .registry import tool_scope
15+ from ..ulid import generate_ulid
1616
1717if TYPE_CHECKING :
1818 from .step_executor import AgentStepExecutor , StepExecutor
@@ -53,9 +53,6 @@ def span(span_name: str, /, **attributes: Any) -> Iterator[Span]:
5353 yield current_span
5454
5555
56- def _generate_id () -> str :
57- return uuid .uuid4 ().hex
58-
5956
6057_step_executor_var : ContextVar [StepExecutor | None ] = ContextVar (
6158 "nighthawk_step_executor" ,
@@ -172,7 +169,7 @@ def run(
172169
173170 Args:
174171 step_executor: The step executor to use for Natural block execution.
175- run_id: Optional identifier for the run. If not provided, a UUID is
172+ run_id: Optional identifier for the run. If not provided, a ULID is
176173 generated automatically.
177174
178175 Yields:
@@ -188,8 +185,8 @@ def run(
188185 ```
189186 """
190187 execution_context = ExecutionContext (
191- run_id = run_id or _generate_id (),
192- scope_id = _generate_id (),
188+ run_id = run_id or generate_ulid (),
189+ scope_id = generate_ulid (),
193190 )
194191
195192 with tool_scope ():
@@ -282,7 +279,7 @@ def scope(
282279
283280 next_execution_context = replace (
284281 current_execution_context ,
285- scope_id = _generate_id (),
282+ scope_id = generate_ulid (),
286283 )
287284
288285 next_system_fragments = _system_prompt_suffix_fragments_var .get ()
0 commit comments