From 5818805d2a307d09579454fb49ed11cf5ad5e91f Mon Sep 17 00:00:00 2001 From: Jesse Turner Date: Tue, 12 May 2026 15:00:43 +0000 Subject: [PATCH] fix: allow bound methods in entrypoint() registration 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 --- src/bedrock_agentcore/runtime/app.py | 5 ++++- tests/bedrock_agentcore/runtime/test_app.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/bedrock_agentcore/runtime/app.py b/src/bedrock_agentcore/runtime/app.py index af11da94..3a745503 100644 --- a/src/bedrock_agentcore/runtime/app.py +++ b/src/bedrock_agentcore/runtime/app.py @@ -220,7 +220,10 @@ def entrypoint(self, func: Callable) -> Callable: The decorated function with added serve method """ self.handlers["main"] = func - func.run = lambda port=8080, host=None: self.run(port, host) + try: + func.run = lambda port=8080, host=None: self.run(port, host) + except AttributeError: + pass return func def ping(self, func: Callable) -> Callable: diff --git a/tests/bedrock_agentcore/runtime/test_app.py b/tests/bedrock_agentcore/runtime/test_app.py index 5f5d5f35..e8addcbb 100644 --- a/tests/bedrock_agentcore/runtime/test_app.py +++ b/tests/bedrock_agentcore/runtime/test_app.py @@ -61,6 +61,21 @@ def test_handler(payload): assert hasattr(test_handler, "run") assert callable(test_handler.run) + def test_entrypoint_bound_method(self): + """Test entrypoint accepts a bound method without raising AttributeError.""" + + class MyAgent: + def __init__(self): + self.app = BedrockAgentCoreApp() + self.app.entrypoint(self.handle) + + def handle(self, payload): + return {"result": "success"} + + agent = MyAgent() + assert "main" in agent.app.handlers + assert agent.app.handlers["main"] == agent.handle + def test_invocation_without_context(self): """Test handler without context parameter works correctly.""" bedrock_agentcore = BedrockAgentCoreApp()