-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Propagate agent information into LLM calls #4876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
adriangb
wants to merge
3
commits into
main
Choose a base branch
from
add-baggage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+348
−175
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Callable | ||
| from random import Random | ||
|
|
||
|
|
||
| def ulid(random: Random, ms_timestamp_generator: Callable[[], int]) -> int: | ||
| """Generate an integer ULID compatible with UUID v4. | ||
|
|
||
| ULIDs as defined by the [spec](https://github.com/ulid/spec) look like this: | ||
|
|
||
| 01AN4Z07BY 79KA1307SR9X4MV3 | ||
| |----------| |----------------| | ||
| Timestamp Randomness | ||
| 48bits 80bits | ||
|
|
||
| In the future it would be nice to make this compatible with a UUID, | ||
| e.g. v4 UUIDs by setting the version and variant bits correctly. | ||
| We can't currently do this because setting these bits would leave us with only 7 bytes of randomness, | ||
| which isn't enough for the Python SDK's sampler that currently expects 8 bytes of randomness. | ||
| In the future OTEL will probably adopt https://www.w3.org/TR/trace-context-2/#random-trace-id-flag | ||
| which relies only on the lower 7 bytes of the trace ID, then all SDKs and tooling should be updated | ||
| and leaving only 7 bytes of randomness should be fine. | ||
|
|
||
| Right now we only care about: | ||
| - Our SDK / Python SDK's in general. | ||
| - The OTEL collector. | ||
|
|
||
| And both behave properly with 8 bytes of randomness because trace IDs were originally 64 bits | ||
| so to be compatible with old trace IDs nothing in OTEL can assume >8 bytes of randomness in trace IDs | ||
| unless they generated the trace ID themselves (e.g. the Go SDK _does_ expect >8 bytes of randomness internally). | ||
| """ | ||
| # Timestamp: first 6 bytes of the ULID (48 bits) | ||
| # Note that it's not important that this timestamp is super precise or unique. | ||
| # It just needs to be roughly monotonically increasing so that the ULID is sortable, at least for our purposes. | ||
| timestamp = ms_timestamp_generator().to_bytes(6, byteorder='big') | ||
| # Randomness: next 10 bytes of the ULID (80 bits) | ||
| randomness = random.getrandbits(80).to_bytes(10, byteorder='big') | ||
| # Convert to int and return | ||
| return int.from_bytes(timestamp + randomness, byteorder='big') | ||
|
|
||
|
|
||
| def ulid_as_uuid(random: Random, ms_timestamp_generator: Callable[[], int]) -> str: | ||
| """Generate a ULID string and return it as a hex string (without dashes) that can be used as a UUID.""" | ||
| ulid_int = ulid(random, ms_timestamp_generator) | ||
| return f'{ulid_int:032x}' |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚩 run_id format change: UUID4 with dashes → ULID hex without dashes
The
run_idfield changed fromstr(uuid.uuid4())(36-char hyphenated UUID like550e8400-e29b-41d4-a716-446655440000) toulid_as_uuid(...)(32-char plain hex like0192a7b3c4d5e6f7a8b9c0d1e2f3a4b5). This is an intentional change, but it alters the format ofGraphAgentState.run_idwhich is a public field. Any downstream code (user code, observability tooling, databases) that parses or validatesrun_idas a UUID with dashes would break. This is likely acceptable sincerun_idis typed asstrwith no documented format, but worth noting as a behavioral change.Was this helpful? React with 👍 or 👎 to provide feedback.