Skip to content

Commit 932db42

Browse files
fix: allow bound methods in entrypoint() registration (#474)
entrypoint() assigned a .run attribute to the registered callable, which fails on bound methods (no writable __dict__). Guard with try/except so class-based agent patterns work. Fixes #473
1 parent 2e8a50a commit 932db42

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/bedrock_agentcore/runtime/app.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,10 @@ def entrypoint(self, func: Callable) -> Callable:
220220
The decorated function with added serve method
221221
"""
222222
self.handlers["main"] = func
223-
func.run = lambda port=8080, host=None: self.run(port, host)
223+
try:
224+
func.run = lambda port=8080, host=None: self.run(port, host)
225+
except AttributeError:
226+
pass
224227
return func
225228

226229
def ping(self, func: Callable) -> Callable:

tests/bedrock_agentcore/runtime/test_app.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,21 @@ def test_handler(payload):
6161
assert hasattr(test_handler, "run")
6262
assert callable(test_handler.run)
6363

64+
def test_entrypoint_bound_method(self):
65+
"""Test entrypoint accepts a bound method without raising AttributeError."""
66+
67+
class MyAgent:
68+
def __init__(self):
69+
self.app = BedrockAgentCoreApp()
70+
self.app.entrypoint(self.handle)
71+
72+
def handle(self, payload):
73+
return {"result": "success"}
74+
75+
agent = MyAgent()
76+
assert "main" in agent.app.handlers
77+
assert agent.app.handlers["main"] == agent.handle
78+
6479
def test_invocation_without_context(self):
6580
"""Test handler without context parameter works correctly."""
6681
bedrock_agentcore = BedrockAgentCoreApp()

0 commit comments

Comments
 (0)