-
Notifications
You must be signed in to change notification settings - Fork 1
feat(sdk): add BenchmarkRun and AsyncBenchmarkRun classes #712
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
5 commits
Select commit
Hold shift + click to select a range
db486de
update requirements-dev
sid-rl 3a88bc3
pyproject formatting nit
sid-rl 4650641
feat(sdk): add BenchmarkRun and AsyncBenchmarkRun classes
sid-rl 3dbc3ab
fixed smoketests
sid-rl 24b5387
`list_scenario_runs()` now returns a list of ScenarioRun/AsyncScenari…
sid-rl 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
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,127 @@ | ||
| """AsyncBenchmarkRun resource class for asynchronous operations.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import List | ||
| from typing_extensions import Unpack, override | ||
|
|
||
| from ..types import BenchmarkRunView | ||
| from ._types import BaseRequestOptions, LongRequestOptions, SDKBenchmarkRunListScenarioRunsParams | ||
| from .._client import AsyncRunloop | ||
| from .async_scenario_run import AsyncScenarioRun | ||
|
|
||
|
|
||
| class AsyncBenchmarkRun: | ||
| """A benchmark run for evaluating agent performance across scenarios (async). | ||
|
|
||
| Provides async methods for monitoring run status, managing the run lifecycle, | ||
| and accessing scenario run results. Obtain instances via | ||
| ``benchmark.run()`` or ``benchmark.list_runs()``. | ||
|
|
||
| Example: | ||
| >>> benchmark = runloop.benchmark.from_id("bench-xxx") | ||
| >>> run = await benchmark.run(run_name="evaluation-v1") | ||
| >>> info = await run.get_info() | ||
| >>> scenario_runs = await run.list_scenario_runs() | ||
| """ | ||
|
|
||
| def __init__(self, client: AsyncRunloop, run_id: str, benchmark_id: str) -> None: | ||
| """Create an AsyncBenchmarkRun instance. | ||
|
|
||
| :param client: AsyncRunloop client instance | ||
| :type client: AsyncRunloop | ||
| :param run_id: Benchmark run ID | ||
| :type run_id: str | ||
| :param benchmark_id: Parent benchmark ID | ||
| :type benchmark_id: str | ||
| """ | ||
| self._client = client | ||
| self._id = run_id | ||
| self._benchmark_id = benchmark_id | ||
|
|
||
| @override | ||
| def __repr__(self) -> str: | ||
| return f"<AsyncBenchmarkRun id={self._id!r}>" | ||
|
|
||
| @property | ||
| def id(self) -> str: | ||
| """Return the benchmark run ID. | ||
|
|
||
| :return: Unique benchmark run ID | ||
| :rtype: str | ||
| """ | ||
| return self._id | ||
|
|
||
| @property | ||
| def benchmark_id(self) -> str: | ||
| """Return the parent benchmark ID. | ||
|
|
||
| :return: Parent benchmark ID | ||
| :rtype: str | ||
| """ | ||
| return self._benchmark_id | ||
|
|
||
| async def get_info( | ||
| self, | ||
| **options: Unpack[BaseRequestOptions], | ||
| ) -> BenchmarkRunView: | ||
|
Comment on lines
+64
to
+67
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we call this something else instead? |
||
| """Retrieve current benchmark run status and metadata. | ||
|
|
||
| :param options: See :typeddict:`~runloop_api_client.sdk._types.BaseRequestOptions` for available options | ||
| :return: Current benchmark run state info | ||
| :rtype: BenchmarkRunView | ||
| """ | ||
| return await self._client.benchmarks.runs.retrieve( | ||
| self._id, | ||
| **options, | ||
| ) | ||
|
|
||
| async def cancel( | ||
| self, | ||
| **options: Unpack[LongRequestOptions], | ||
| ) -> BenchmarkRunView: | ||
| """Cancel the benchmark run. | ||
|
|
||
| Stops all running scenarios and marks the run as canceled. | ||
|
|
||
| :param options: See :typeddict:`~runloop_api_client.sdk._types.LongRequestOptions` for available options | ||
| :return: Updated benchmark run state | ||
| :rtype: BenchmarkRunView | ||
| """ | ||
| return await self._client.benchmarks.runs.cancel( | ||
| self._id, | ||
| **options, | ||
| ) | ||
|
|
||
| async def complete( | ||
| self, | ||
| **options: Unpack[LongRequestOptions], | ||
| ) -> BenchmarkRunView: | ||
| """Complete the benchmark run. | ||
|
|
||
| Marks the run as completed. Call this after all scenarios have finished. | ||
|
|
||
| :param options: See :typeddict:`~runloop_api_client.sdk._types.LongRequestOptions` for available options | ||
| :return: Completed benchmark run state | ||
| :rtype: BenchmarkRunView | ||
| """ | ||
| return await self._client.benchmarks.runs.complete( | ||
| self._id, | ||
| **options, | ||
| ) | ||
|
|
||
| async def list_scenario_runs( | ||
| self, | ||
| **params: Unpack[SDKBenchmarkRunListScenarioRunsParams], | ||
| ) -> List[AsyncScenarioRun]: | ||
| """List all scenario runs for this benchmark run. | ||
|
|
||
| :param params: See :typeddict:`~runloop_api_client.sdk._types.SDKBenchmarkRunListScenarioRunsParams` for available parameters | ||
| :return: List of async scenario run objects | ||
| :rtype: List[AsyncScenarioRun] | ||
| """ | ||
| page = await self._client.benchmarks.runs.list_scenario_runs( | ||
| self._id, | ||
| **params, | ||
| ) | ||
| return [AsyncScenarioRun(self._client, run.id, run.devbox_id) for run in page.runs] | ||
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,127 @@ | ||
| """BenchmarkRun resource class for synchronous operations.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import List | ||
| from typing_extensions import Unpack, override | ||
|
|
||
| from ..types import BenchmarkRunView | ||
| from ._types import BaseRequestOptions, LongRequestOptions, SDKBenchmarkRunListScenarioRunsParams | ||
| from .._client import Runloop | ||
| from .scenario_run import ScenarioRun | ||
|
|
||
|
|
||
| class BenchmarkRun: | ||
| """A benchmark run for evaluating agent performance across scenarios. | ||
|
|
||
| Provides methods for monitoring run status, managing the run lifecycle, | ||
| and accessing scenario run results. Obtain instances via | ||
| ``benchmark.run()`` or ``benchmark.list_runs()``. | ||
|
|
||
| Example: | ||
| >>> benchmark = runloop.benchmark.from_id("bench-xxx") | ||
| >>> run = benchmark.run(run_name="evaluation-v1") | ||
| >>> info = run.get_info() | ||
| >>> scenario_runs = run.list_scenario_runs() | ||
| """ | ||
|
|
||
| def __init__(self, client: Runloop, run_id: str, benchmark_id: str) -> None: | ||
| """Create a BenchmarkRun instance. | ||
|
|
||
| :param client: Runloop client instance | ||
| :type client: Runloop | ||
| :param run_id: Benchmark run ID | ||
| :type run_id: str | ||
| :param benchmark_id: Parent benchmark ID | ||
| :type benchmark_id: str | ||
| """ | ||
| self._client = client | ||
| self._id = run_id | ||
| self._benchmark_id = benchmark_id | ||
|
|
||
| @override | ||
| def __repr__(self) -> str: | ||
| return f"<BenchmarkRun id={self._id!r}>" | ||
|
Comment on lines
+42
to
+44
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same thing here |
||
|
|
||
| @property | ||
| def id(self) -> str: | ||
| """Return the benchmark run ID. | ||
|
|
||
| :return: Unique benchmark run ID | ||
| :rtype: str | ||
| """ | ||
| return self._id | ||
|
|
||
| @property | ||
| def benchmark_id(self) -> str: | ||
| """Return the parent benchmark ID. | ||
|
|
||
| :return: Parent benchmark ID | ||
| :rtype: str | ||
| """ | ||
| return self._benchmark_id | ||
|
|
||
| def get_info( | ||
| self, | ||
| **options: Unpack[BaseRequestOptions], | ||
| ) -> BenchmarkRunView: | ||
| """Retrieve current benchmark run status and metadata. | ||
|
|
||
| :param options: See :typeddict:`~runloop_api_client.sdk._types.BaseRequestOptions` for available options | ||
| :return: Current benchmark run state info | ||
| :rtype: BenchmarkRunView | ||
| """ | ||
| return self._client.benchmarks.runs.retrieve( | ||
| self._id, | ||
| **options, | ||
| ) | ||
|
|
||
| def cancel( | ||
| self, | ||
| **options: Unpack[LongRequestOptions], | ||
| ) -> BenchmarkRunView: | ||
| """Cancel the benchmark run. | ||
|
|
||
| Stops all running scenarios and marks the run as canceled. | ||
|
|
||
| :param options: See :typeddict:`~runloop_api_client.sdk._types.LongRequestOptions` for available options | ||
| :return: Updated benchmark run state | ||
| :rtype: BenchmarkRunView | ||
| """ | ||
| return self._client.benchmarks.runs.cancel( | ||
| self._id, | ||
| **options, | ||
| ) | ||
|
|
||
| def complete( | ||
| self, | ||
| **options: Unpack[LongRequestOptions], | ||
| ) -> BenchmarkRunView: | ||
| """Complete the benchmark run. | ||
|
|
||
| Marks the run as completed. Call this after all scenarios have finished. | ||
|
|
||
| :param options: See :typeddict:`~runloop_api_client.sdk._types.LongRequestOptions` for available options | ||
| :return: Completed benchmark run state | ||
| :rtype: BenchmarkRunView | ||
| """ | ||
| return self._client.benchmarks.runs.complete( | ||
| self._id, | ||
| **options, | ||
| ) | ||
|
|
||
| def list_scenario_runs( | ||
| self, | ||
| **params: Unpack[SDKBenchmarkRunListScenarioRunsParams], | ||
| ) -> List[ScenarioRun]: | ||
| """List all scenario runs for this benchmark run. | ||
|
|
||
| :param params: See :typeddict:`~runloop_api_client.sdk._types.SDKBenchmarkRunListScenarioRunsParams` for available parameters | ||
| :return: List of scenario run objects | ||
| :rtype: List[ScenarioRun] | ||
| """ | ||
| page = self._client.benchmarks.runs.list_scenario_runs( | ||
| self._id, | ||
| **params, | ||
| ) | ||
| return [ScenarioRun(self._client, run.id, run.devbox_id) for run in page.runs] | ||
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
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.
I don't think you want
@overridewithout a base class