File tree Expand file tree Collapse file tree 2 files changed +35
-3
lines changed
aws_lambda_powertools/event_handler
tests/functional/event_handler/required_dependencies Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -80,14 +80,26 @@ def __init__(self) -> None:
80
80
self .current_event : BedrockAgentFunctionEvent | None = None
81
81
self ._response_builder_class = BedrockFunctionsResponseBuilder
82
82
83
- def tool (self , description : str | None = None ) -> Callable :
84
- """Decorator to register a tool function"""
83
+ def tool (
84
+ self ,
85
+ description : str | None = None ,
86
+ name : str | None = None ,
87
+ ) -> Callable :
88
+ """Decorator to register a tool function
89
+
90
+ Parameters
91
+ ----------
92
+ description : str | None
93
+ Description of what the tool does
94
+ name : str | None
95
+ Custom name for the tool. If not provided, uses the function name
96
+ """
85
97
86
98
def decorator (func : Callable ) -> Callable :
87
99
if not description :
88
100
raise ValueError ("Tool description is required" )
89
101
90
- function_name = func .__name__
102
+ function_name = name or func .__name__
91
103
if function_name in self ._tools :
92
104
raise ValueError (f"Tool '{ function_name } ' already registered" )
93
105
Original file line number Diff line number Diff line change @@ -128,3 +128,23 @@ def test_bedrock_agent_function_invalid_event():
128
128
# THEN raise ValueError
129
129
with pytest .raises (ValueError , match = "Missing required field" ):
130
130
app .resolve ({}, {})
131
+
132
+
133
+ def test_bedrock_agent_function_with_custom_name ():
134
+ # GIVEN a Bedrock Agent Function resolver
135
+ app = BedrockAgentFunctionResolver ()
136
+
137
+ @app .tool (name = "customName" , description = "Function with custom name" )
138
+ def test_function ():
139
+ return "Hello from custom named function"
140
+
141
+ # WHEN calling the event handler
142
+ raw_event = load_event ("bedrockAgentFunctionEvent.json" )
143
+ raw_event ["function" ] = "customName" # Use custom name instead of function name
144
+ result = app .resolve (raw_event , {})
145
+
146
+ # THEN process event correctly
147
+ assert result ["messageVersion" ] == "1.0"
148
+ assert result ["response" ]["actionGroup" ] == raw_event ["actionGroup" ]
149
+ assert result ["response" ]["function" ] == "customName"
150
+ assert result ["response" ]["functionResponse" ]["responseBody" ]["TEXT" ]["body" ] == "Hello from custom named function"
You can’t perform that action at this time.
0 commit comments