diff --git a/src/bedrock_agentcore/runtime/app.py b/src/bedrock_agentcore/runtime/app.py index 9dc6aeb1..22475f01 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 05df20ab..483e6936 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()