-
Notifications
You must be signed in to change notification settings - Fork 26
fix(eval): trim legacy trajectory span history #1652
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
Closed
Closed
Changes from all commits
Commits
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
64 changes: 64 additions & 0 deletions
64
packages/uipath/tests/evaluators/test_legacy_trajectory_evaluator.py
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,64 @@ | ||
| import uuid | ||
|
|
||
| from opentelemetry.sdk.trace import ReadableSpan | ||
|
|
||
| from uipath.eval.evaluators import LegacyTrajectoryEvaluator | ||
| from uipath.eval.evaluators.base_legacy_evaluator import LegacyEvaluationCriteria | ||
| from uipath.eval.evaluators.legacy_trajectory_evaluator import ( | ||
| LegacyTrajectoryEvaluatorConfig, | ||
| ) | ||
| from uipath.eval.models.models import LegacyEvaluatorCategory, LegacyEvaluatorType | ||
|
|
||
|
|
||
| def _legacy_trajectory_evaluator() -> LegacyTrajectoryEvaluator: | ||
| return LegacyTrajectoryEvaluator( | ||
| id=str(uuid.uuid4()), | ||
| name="Legacy trajectory", | ||
| config_type=LegacyTrajectoryEvaluatorConfig, | ||
| evaluation_criteria_type=LegacyEvaluationCriteria, | ||
| justification_type=str, | ||
| category=LegacyEvaluatorCategory.Trajectory, | ||
| type=LegacyEvaluatorType.Trajectory, | ||
| prompt="History:\n{{AgentRunHistory}}\nExpected:\n{{ExpectedAgentBehavior}}", | ||
| createdAt="2026-05-14T00:00:00Z", | ||
| updatedAt="2026-05-14T00:00:00Z", | ||
| ) | ||
|
|
||
|
|
||
| def test_legacy_trajectory_prompt_uses_compact_tool_history() -> None: | ||
| long_prompt = "SYSTEM_PROMPT_" + ("x" * 10_000) | ||
| spans = [ | ||
| ReadableSpan( | ||
| name="agent_llm_call", | ||
| start_time=0, | ||
| end_time=1, | ||
| attributes={ | ||
| "openinference.span.kind": "LLM", | ||
| "input.value": f'{{"messages": [{{"role": "system", "content": "{long_prompt}"}}]}}', | ||
| "output.value": '{"generations": []}', | ||
| }, | ||
| ), | ||
| ReadableSpan( | ||
| name="search_profiles", | ||
| start_time=1, | ||
| end_time=2, | ||
| attributes={ | ||
| "openinference.span.kind": "TOOL", | ||
| "tool.name": "search_profiles", | ||
| "input.value": '{"query": "mentor"}', | ||
| "output.value": '{"content": "found mentor profile"}', | ||
| "metadata": f'{{"agent_prompt": "{long_prompt}"}}', | ||
| }, | ||
| ), | ||
| ] | ||
|
|
||
| prompt = _legacy_trajectory_evaluator()._create_evaluation_prompt( | ||
| expected_agent_behavior="The agent should search matching profiles.", | ||
| agent_run_history=spans, | ||
| ) | ||
|
|
||
| assert "SYSTEM_PROMPT_" not in prompt | ||
| assert "Tool: search_profiles" in prompt | ||
| assert '{"query": "mentor"}' in prompt | ||
| assert "found mentor profile" in prompt | ||
| assert "agent_llm_call" not in prompt |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
For runs whose trace contains only LLM/CHAIN spans (for example an agent answers directly without invoking any tool), this now replaces
{{AgentRunHistory}}withtrace_to_str(...), but that helper only emits spans that have atool.nameattribute and otherwise returns an empty string. The legacy trajectory evaluator prompt does not includeagent_output, so those direct-answer executions lose all observable run history compared with the previousTrajectoryEvaluationTraceconversion, making the evaluator unable to judge whether the no-tool path matched the expected behavior.Useful? React with 👍 / 👎.