-
Notifications
You must be signed in to change notification settings - Fork 751
Skeleton PR: Agentic Environment for Tool Synthesis #2358
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
Draft
aniruddh-alt
wants to merge
23
commits into
main
Choose a base branch
from
aniruddh-alt/agent-environment-skeleton
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.
Draft
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
be38f5d
feat: add agentic tool synthesis skeleton
aniruddh-alt 2df6f03
fix: add missing docstring and apply ruff format
aniruddh-alt 6505cbc
Potential fix for pull request finding 'Unused global variable'
aniruddh-alt a628ea7
fix: suppress pre-existing ASYNC240/ASYNC230 ruff errors in MCP files
aniruddh-alt 1533244
Merge remote-tracking branch 'origin/main' into aniruddh-alt/stateful…
aniruddh-alt 1b7060b
Update tool_executor.py
aniruddh-alt 088cd5a
refactor: move environments to top-level package with typed tool hier…
aniruddh-alt 01ab23d
style: apply ruff format to environment and test files
aniruddh-alt 56efd03
fix: resolve pyright type errors in environment tests
aniruddh-alt ea2ef62
Merge branch 'main' into aniruddh-alt/agent-environment-skeleton
aniruddh-alt ace8c8e
fix: update test assertion to include environment_config parameter
aniruddh-alt e367535
Merge branch 'main' into aniruddh-alt/agent-environment-skeleton
aniruddh-alt 21ceb87
revert: remove unrelated MCP file changes from branch
aniruddh-alt ec78eb4
revert: remove unrelated datasets version bump from pyproject.toml
aniruddh-alt 4148d55
feat: refactor environments, consolidate synthetic environments
aniruddh-alt 13566fb
Merge remote-tracking branch 'origin/main' into aniruddh-alt/agent-en…
aniruddh-alt f8a4d52
Update test_tool_params.py
aniruddh-alt 6f48a8c
refactor: move ToolResult into base_tool.py and fix circular imports
aniruddh-alt 1a223d4
fix: resolve circular import without lazy loading
aniruddh-alt c5cd36d
feat: fix circular imports
aniruddh-alt 1b46762
fix: use Any annotation for environment_config field in SynthesisConfig
aniruddh-alt 5c9d096
Merge branch 'main' into aniruddh-alt/agent-environment-skeleton
aniruddh-alt 4ef5f1b
Add ToolSchema class for structured tool I/O definitions
aniruddh-alt 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
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,139 @@ | ||
| # Copyright 2025 - Oumi | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Configuration for agentic environments.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass, field | ||
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| from oumi.core.configs.base_config import BaseConfig | ||
|
|
||
| if TYPE_CHECKING: | ||
| from oumi.environments.base_environment import BaseEnvironment | ||
| from oumi.environments.base_tool import Tool | ||
|
|
||
|
|
||
| @dataclass | ||
| class EnvironmentConfig(BaseConfig): | ||
|
github-code-quality[bot] marked this conversation as resolved.
Fixed
github-code-quality[bot] marked this conversation as resolved.
Fixed
aniruddh-alt marked this conversation as resolved.
Dismissed
|
||
| """Top-level config for environment-first tool definitions.""" | ||
|
|
||
| environments: list[Any] = field(default_factory=list) | ||
|
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. This typing is a bit too weak |
||
| """Reusable environments and their owned tools.""" | ||
|
|
||
| def __post_init__(self): | ||
| """Verifies/populates params.""" | ||
| self.environments = [ | ||
| self._coerce_environment(environment) for environment in self.environments | ||
| ] | ||
|
|
||
| env_ids: set[str] = set() | ||
| tool_ids: set[str] = set() | ||
|
|
||
| for environment in self.environments: | ||
| if environment.id in env_ids: | ||
| raise ValueError( | ||
| f"EnvironmentConfig.environments contains duplicate " | ||
| f"environment id '{environment.id}'." | ||
| ) | ||
| env_ids.add(environment.id) | ||
|
|
||
| for tool in environment.tools: | ||
| if tool.id in tool_ids: | ||
| raise ValueError( | ||
| f"EnvironmentConfig.environments contains duplicate " | ||
| f"tool id '{tool.id}'." | ||
| ) | ||
| tool_ids.add(tool.id) | ||
|
|
||
| @property | ||
| def all_tools(self) -> list[Tool]: | ||
| """Flatten all tools across environments.""" | ||
| return [tool for environment in self.environments for tool in environment.tools] | ||
|
|
||
| @property | ||
| def tool_environment_map(self) -> dict[str, str]: | ||
| """Map each tool id to the environment that owns it.""" | ||
| return { | ||
| tool.id: environment.id | ||
| for environment in self.environments | ||
| for tool in environment.tools | ||
| } | ||
|
|
||
| def get_environment(self, environment_id: str) -> BaseEnvironment | None: | ||
| """Look up an environment by id.""" | ||
| for environment in self.environments: | ||
| if environment.id == environment_id: | ||
| return environment | ||
| return None | ||
|
|
||
| def get_tool(self, tool_id: str) -> Tool | None: | ||
| """Look up a tool by id.""" | ||
| for tool in self.all_tools: | ||
| if tool.id == tool_id: | ||
| return tool | ||
| return None | ||
|
|
||
| def resolve_tools( | ||
|
aniruddh-alt marked this conversation as resolved.
|
||
| self, | ||
| environment_ids: list[str] | None = None, | ||
| tool_ids: list[str] | None = None, | ||
| ) -> list[Tool]: | ||
| """Resolve tools from selected environments and optional tool ids. | ||
|
|
||
| Raises: | ||
| ValueError: If any environment_id or tool_id is not found. | ||
| """ | ||
| all_env_ids = {env.id for env in self.environments} | ||
|
|
||
| if environment_ids: | ||
| unknown_envs = set(environment_ids) - all_env_ids | ||
| if unknown_envs: | ||
| raise ValueError( | ||
| f"Unknown environment id(s): {sorted(unknown_envs)}. " | ||
| f"Defined: {sorted(all_env_ids)}" | ||
| ) | ||
| selected_environment_ids = environment_ids | ||
| else: | ||
| selected_environment_ids = list(all_env_ids) | ||
|
|
||
| selected_environments = [ | ||
| environment | ||
| for environment in self.environments | ||
| if environment.id in set(selected_environment_ids) | ||
| ] | ||
| tools = [ | ||
| tool for environment in selected_environments for tool in environment.tools | ||
| ] | ||
|
|
||
| if tool_ids: | ||
| available_tool_ids = {tool.id for tool in tools} | ||
| unknown_tools = set(tool_ids) - available_tool_ids | ||
| if unknown_tools: | ||
| raise ValueError( | ||
| f"Unknown tool id(s): {sorted(unknown_tools)}. " | ||
| f"Available in selected environments: " | ||
| f"{sorted(available_tool_ids)}" | ||
| ) | ||
| allowed_tool_ids = set(tool_ids) | ||
| tools = [tool for tool in tools if tool.id in allowed_tool_ids] | ||
|
|
||
| return tools | ||
|
|
||
| def _coerce_environment(self, environment: Any) -> BaseEnvironment: | ||
| """Coerce a raw dict or environment instance into a concrete environment.""" | ||
| from oumi.environments.base_environment import BaseEnvironment | ||
|
|
||
| return BaseEnvironment.create(environment) | ||
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.
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.
Uh oh!
There was an error while loading. Please reload this page.