-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat: add tool decorator alias #3920
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
+61
−0
Merged
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| """Public decorators for defining Agents SDK components. | ||
|
|
||
| `tool` is an alias for `function_tool`. | ||
| """ | ||
|
|
||
| from .guardrail import input_guardrail, output_guardrail | ||
| from .tool import function_tool | ||
| from .tool_guardrails import tool_input_guardrail, tool_output_guardrail | ||
|
|
||
| tool = function_tool | ||
|
|
||
| __all__ = [ | ||
| "function_tool", | ||
| "input_guardrail", | ||
| "output_guardrail", | ||
| "tool", | ||
| "tool_input_guardrail", | ||
| "tool_output_guardrail", | ||
| ] | ||
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,42 @@ | ||
| import types | ||
|
|
||
| from typing_extensions import assert_type | ||
|
|
||
| import agents.decorators as decorators_module | ||
| import agents.tool as tool_module | ||
| from agents import ( | ||
| FunctionTool, | ||
| function_tool, | ||
| input_guardrail, | ||
| output_guardrail, | ||
| tool_input_guardrail, | ||
| tool_output_guardrail, | ||
| ) | ||
| from agents.decorators import function_tool as decorators_function_tool, tool | ||
|
|
||
|
|
||
| def test_decorator_module_preserves_existing_imports_and_identities() -> None: | ||
| assert isinstance(decorators_module, types.ModuleType) | ||
| assert isinstance(tool_module, types.ModuleType) | ||
| assert decorators_function_tool is function_tool | ||
| assert tool is function_tool | ||
| assert decorators_module.input_guardrail is input_guardrail | ||
| assert decorators_module.output_guardrail is output_guardrail | ||
| assert decorators_module.tool_input_guardrail is tool_input_guardrail | ||
| assert decorators_module.tool_output_guardrail is tool_output_guardrail | ||
| assert tool_module.function_tool is function_tool | ||
|
|
||
|
|
||
| def test_tool_alias_supports_bare_and_configured_decorator_forms() -> None: | ||
| @tool | ||
| def bare_alias() -> str: | ||
| return "bare" | ||
|
|
||
| @tool(name_override="configured_alias") | ||
| async def configured_alias() -> str: | ||
| return "configured" | ||
|
|
||
| assert_type(bare_alias, FunctionTool) | ||
| assert_type(configured_alias, FunctionTool) | ||
| assert bare_alias.name == "bare_alias" | ||
| assert configured_alias.name == "configured_alias" |
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.