-
Notifications
You must be signed in to change notification settings - Fork 863
fix(evals): evals API supports input + config, generate mbt functions #3534
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
31abd4c
added tool
nina-kollman 38511d3
generate
nina-kollman 9b15bec
added example
nina-kollman 747845b
lint
nina-kollman 6af89b2
fix
nina-kollman 403dbbf
fix comm
nina-kollman c35518b
definition
nina-kollman 6f9cd16
comm
nina-kollman f628e5e
rename
nina-kollman a27c7eb
rename
nina-kollman acabf5e
rename
nina-kollman 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
85 changes: 85 additions & 0 deletions
85
packages/sample-app/sample_app/experiment/made_by_traceloop/agent_tool_trajectory.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,85 @@ | ||
| """ | ||
| Agent Tool Trajectory Experiment | ||
|
|
||
| This example demonstrates Traceloop's agent tool trajectory evaluator: | ||
| - Agent Tool Trajectory: Validates the agent tool trajectory | ||
|
|
||
| This evaluator helps ensure your AI agents perform optimally and follow the expected tool trajectory. | ||
| """ | ||
|
|
||
| import asyncio | ||
| from traceloop.sdk import Traceloop | ||
| from traceloop.sdk.evaluator import EvaluatorMadeByTraceloop | ||
|
|
||
| # Initialize Traceloop | ||
| client = Traceloop.init() | ||
|
|
||
|
|
||
| def agent_evaluators_task(row): | ||
| executed_tool_calls = row.get("actual", "") | ||
| default_expected = ( | ||
| "[{'name': 'search', 'input': {'query': 'weather'}}, " | ||
| "{'name': 'book_flight', 'input': {'flight': 'NYC to Paris'}}, " | ||
| "{'name': 'get_confirmation', 'input': {'confirmation': 'flight booked'}}]" | ||
| ) | ||
| expected_tool_calls = row.get("expected", default_expected) | ||
|
|
||
| return { | ||
| "executed_tool_calls": executed_tool_calls, | ||
| "expected_tool_calls": expected_tool_calls, | ||
| } | ||
|
|
||
|
|
||
| async def run_agent_tool_trajectory_experiment(): | ||
| print("\n" + "="*80) | ||
| print("AGENT TOOL TRAJECTORY EXPERIMENT") | ||
| print("="*80 + "\n") | ||
| print("This experiment will test the agent tool trajectory with the agent tool trajectory evaluator:\n") | ||
| print("1. Agent Tool Trajectory - Validates the agent tool trajectory") | ||
| print("\n" + "-"*80 + "\n") | ||
|
|
||
| # Configure agent evaluators | ||
| evaluators = [ | ||
| EvaluatorMadeByTraceloop.agent_tool_trajectory( | ||
| input_params_sensitive=True, | ||
| mismatch_sensitive=False, | ||
| order_sensitive=False, | ||
| threshold=0.7, | ||
| ), | ||
| ] | ||
|
|
||
| print("Running experiment with evaluators:") | ||
| for evaluator in evaluators: | ||
| print(f" - {evaluator.slug}") | ||
|
|
||
| print("\n" + "-"*80 + "\n") | ||
|
|
||
| # Run the experiment | ||
| # Note: You'll need to create a dataset with appropriate test cases for agents | ||
| results, errors = await client.experiment.run( | ||
| dataset_slug="agent-tool-trajectory", # Set a dataset slug that exists in the traceloop platform | ||
| dataset_version="v1", | ||
| task=agent_evaluators_task, | ||
| evaluators=evaluators, | ||
| experiment_slug="agent-tool-trajectory-exp", | ||
| stop_on_error=False, | ||
| wait_for_results=True, | ||
| ) | ||
nina-kollman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| print("\n" + "="*80) | ||
| print("Agent tool trajectory experiment completed!") | ||
| print("="*80 + "\n") | ||
|
|
||
| print("Results summary:") | ||
| print(f" - Total rows processed: {len(results) if results else 0}") | ||
| print(f" - Errors encountered: {len(errors) if errors else 0}") | ||
|
|
||
| if errors: | ||
| print("\nErrors:") | ||
| for error in errors: | ||
| print(f" - {error}") | ||
|
|
||
| if __name__ == "__main__": | ||
| print("\nAgent Tool Trajectory Experiment\n") | ||
|
|
||
| asyncio.run(run_agent_tool_trajectory_experiment()) | ||
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 |
|---|---|---|
| @@ -1,10 +1,9 @@ | ||
| from .evaluator import Evaluator | ||
| from .config import EvaluatorDetails | ||
| from .evaluators_made_by_traceloop import EvaluatorMadeByTraceloop, create_evaluator | ||
| from ..generated.evaluators.definitions import EvaluatorMadeByTraceloop | ||
|
|
||
| __all__ = [ | ||
| "Evaluator", | ||
| "EvaluatorDetails", | ||
| "EvaluatorMadeByTraceloop", | ||
| "create_evaluator", | ||
| ] |
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
120 changes: 0 additions & 120 deletions
120
packages/traceloop-sdk/traceloop/sdk/evaluator/evaluators_made_by_traceloop.py
This file was deleted.
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.
🧩 Analysis chain
🏁 Script executed:
rg -n -A5 -B5 "tool_calls" --type=pyRepository: traceloop/openllmetry
Length of output: 50378
🏁 Script executed:
Repository: traceloop/openllmetry
Length of output: 3431
🏁 Script executed:
Repository: traceloop/openllmetry
Length of output: 6137
🏁 Script executed:
Repository: traceloop/openllmetry
Length of output: 6133
🏁 Script executed:
Repository: traceloop/openllmetry
Length of output: 47
🏁 Script executed:
Repository: traceloop/openllmetry
Length of output: 5601
🏁 Script executed:
Repository: traceloop/openllmetry
Length of output: 12825
🏁 Script executed:
Repository: traceloop/openllmetry
Length of output: 416
🏁 Script executed:
# Check the request.py to see AgentToolTrajectoryRequest structure cat packages/traceloop-sdk/traceloop/sdk/generated/evaluators/request.pyRepository: traceloop/openllmetry
Length of output: 13294
🏁 Script executed:
Repository: traceloop/openllmetry
Length of output: 47
Fix JSON string format for tool calls to use valid JSON syntax.
Lines 20-24 define
default_expectedas a string, which is correct. However, the string uses single quotes instead of double quotes, creating invalid JSON that will fail parsing. Update to proper JSON format:Corrected code
The agent-tool-trajectory evaluator expects both
executed_tool_callsandexpected_tool_callsas JSON strings (not Python lists).🤖 Prompt for AI Agents