-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationduplicateThis issue or pull request already existsThis issue or pull request already exists
Description
This issue proposes enhancing the documentation by adding clear code examples for each parameter of the @function_tool
decorator.
Currently, the documentation could be improved by providing specific examples for how to use each of the following parameters:
name_override
: An example showing how to explicitly set a tool's name.description_override
: An example demonstrating how to provide a custom description for a tool.docstring_style
: An example of how to use a specific docstring style to parse tool information.use_docstring_info
: An example that shows when and how to control whether docstring information is used.failure_error_function
: A clear example demonstrating how to use a custom function for handling tool errors.strict_mode
: An example that explains the behavior when strict mode is enabled or disabled.is_enabled
: An example that shows how to dynamically enable or disable a tool based on a condition.
Adding these examples will provide developers with a comprehensive and easy-to-understand guide for configuring their tools, making the SDK more accessible and user-friendly.
Here is a code example for the failure_error_function
parameter:
from agents import function_tool, RunContextWrapper
from typing import Any
def my_custom_error_function(context: RunContextWrapper[Any], error: Exception) -> str:
"""A custom function to provide a user-friendly error message."""
print(f"A tool call failed with the following error: {error}")
return "An internal server error occurred. Please try again later."
@function_tool(failure_error_function=my_custom_error_function)
def get_user_profile(user_id: str) -> str:
"""Fetches a user profile from a mock API.
This function demonstrates a "flaky" or failing API call.
"""
if user_id == "user_123":
return "User profile for user_123 successfully retrieved."
else:
raise ValueError(f"Could not retrieve profile for user_id: {user_id}. API returned an error.")
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationduplicateThis issue or pull request already existsThis issue or pull request already exists