-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function.py
More file actions
28 lines (20 loc) · 872 Bytes
/
Copy pathlambda_function.py
File metadata and controls
28 lines (20 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import json
import tools # noqa: F401 — registers tool handlers
from registry import auto_register, get_handler
auto_register(tools)
_DELIMITER = "___"
def lambda_handler(event, context):
if context.client_context is None or not getattr(context.client_context, "custom", None):
raise ValueError(
"Missing client context. This Lambda must be invoked via AgentCore Gateway "
"or with --client-context set (see make invoke)."
)
custom = context.client_context.custom
raw_tool_name = custom["bedrockAgentCoreToolName"]
tool_name = raw_tool_name[raw_tool_name.index(_DELIMITER) + len(_DELIMITER):]
print(f"Invoking tool: {tool_name!r}")
print(f"Input: {json.dumps(event)}")
handler = get_handler(tool_name)
result = handler(**event)
print(f"Result: {json.dumps(result)}")
return result