Python: [BREAKING] changed AIFunction to FunctionTool and @ai_function to @tool#3413
Conversation
0cdd264 to
1d841e2
Compare
There was a problem hiding this comment.
Pull request overview
This PR implements a breaking change that renames AIFunction to FunctionTool and the @ai_function decorator to @tool. The changes are comprehensive and consistent across the entire codebase.
Changes:
- Renamed
AIFunctionclass toFunctionToolthroughout the codebase - Renamed
@ai_functiondecorator to@tool - Updated serialization type identifier from
"ai_function"to"function_tool" - Added default type parameters to the generic
FunctionTool[ArgsT, ReturnT]usingTypeVarWithDefaults - Fixed deepcopy issue with tools containing HTTP clients (addresses issue #3247)
- Updated all samples, tests, documentation, and package code consistently
Reviewed changes
Copilot reviewed 108 out of 109 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
python/packages/core/agent_framework/_tools.py |
Core rename from AIFunction to FunctionTool, added TypeVar defaults, updated type identifier |
python/packages/core/agent_framework/_agents.py |
Fixed deepcopy issue by shallow copying tools to avoid copying HTTP clients |
python/packages/core/agent_framework/_types.py |
Updated normalize_tools and validate_tools functions, proper variable naming to avoid shadowing |
python/packages/core/agent_framework/_serialization.py |
Updated documentation examples to use new naming |
| Various client implementations | Updated all pattern matches and type checks across OpenAI, Azure, Anthropic, Bedrock, Ollama clients |
| Test files | Comprehensive updates to all test files with consistent naming |
| Sample files | All samples updated to use new @tool decorator and FunctionTool class |
| Documentation | Updated README files and coding standards to reflect new naming |
Comments suppressed due to low confidence (1)
python/packages/azure-ai/tests/test_provider.py:491
- This class does not call MCPTool.init during initialization. (MockMCPTool.init may be missing a call to a base class init)
class MockMCPTool(MCPTool): # pyright: ignore[reportGeneralTypeIssues]
|
@eavanvalkenburg @giles17 - Regarding #3368, the issue get resolved when instrumentation is disabled. I suspect |
615e885 to
d4df88d
Compare
|
Will this be accompanied by a documentation update PR? |
aee4a53 to
8c80dd2
Compare
The @ai_function decorator was renamed to @tool in release python-1.0.0b260128 (PR microsoft#3413) as a breaking change. Line 58 of python/samples/03-workflows/README.md still referenced the old @ai_function name, causing users to hit: ImportError: cannot import name 'AIFunction' Changes made: - Fixed @ai_function to @tool on line 58 only - No formatting or whitespace changes
#5622) The @ai_function decorator was renamed to @tool in release python-1.0.0b260128 (PR #3413) as a breaking change. Line 58 of python/samples/03-workflows/README.md still referenced the old @ai_function name, causing users to hit: ImportError: cannot import name 'AIFunction' Changes made: - Fixed @ai_function to @tool on line 58 only - No formatting or whitespace changes
Motivation and Context
Updated naming of
AIFunctiontoFunctionToolAlso added a default to the generic arguments
And the decorator from
@ai_functionto@toolFixes: #3247 and #3368
Closes: #2902 (final point has a additional issue created for it)
Description
Contribution Checklist