Skip to content

Conversation

@jgordley
Copy link
Contributor

@jgordley jgordley commented Sep 5, 2025

Many of the LangChain/Crew/Llamaindex integrations require individual event management and listing of memory records in addition to just searching.

Features

  • Added __get_attr__ method to the Memory Client to dynamically forward the request to either the data plane or the control plane depending on the operation
  • Added a filter for methods that are supported on the memory client

Testing

Added unit tests to cover GetEvent, DeleteEvent, ListMemoryRecords, and a few other operations.

@jgordley jgordley changed the title feat(memory): Add get, delete, and list event operations feat(memory): Add get, delete, and list memory record operations Sep 5, 2025
logger.error("Failed to create blob event: %s", e)
raise

def get_event(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding these pass-through methods, a better way will be to directly have the attributes copied from the gmdp and gmcp_client into this client and definining the set of apis you want to import here. Something along these lines will give you all the methods.

You can then define a filter for the one you'd like to import in this client so that you aren't copying over methods for runtime/gateway etc. This will allow you to one shot import all the methods and not have this translation logic.

+    def __getattr__(self, name: str):
+        """Dynamically forward method calls to the appropriate boto3 client.
+
+        This method enables access to all boto3 client methods without explicitly
+        defining them. Methods are looked up in the following order:
+        1. gmdp_client (bedrock-agentcore) - for data plane operations
+        2. gmcp_client (bedrock-agentcore-control) - for control plane operations
+
+        Args:
+            name: The method name being accessed
+
+        Returns:
+            A callable method from the appropriate boto3 client
+
+        Raises:
+            AttributeError: If the method doesn't exist on either client
+
+        Example:
+            # Access any boto3 method directly
+            client = MemoryClient()
+
+            # These calls are forwarded to the appropriate boto3 client
+            response = client.list_memory_records(memoryId="mem-123", namespace="test")
+            metadata = client.get_memory_metadata(memoryId="mem-123")
+        """
+        # First try gmdp_client (data plane) as it's more commonly used
+        if hasattr(self.gmdp_client, name):
+            method = getattr(self.gmdp_client, name)
+            logger.debug("Forwarding method '%s' to gmdp_client", name)
+            return method
+
+        # Then try gmcp_client (control plane)
+        if hasattr(self.gmcp_client, name):
+            method = getattr(self.gmcp_client, name)
+            logger.debug("Forwarding method '%s' to gmcp_client", name)
+            return method
+
+        # Method not found on either client
+        raise AttributeError(
+            f"'{self.__class__.__name__}' object has no attribute '{name}'. "
+            f"Method not found on gmdp_client or gmcp_client. "
+            f"Available methods can be found in the boto3 documentation for "
+            f"'bedrock-agentcore' and 'bedrock-agentcore-control' services."
+        )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point. Although we do lose some of the advantages of doing things like pagination under the hood for list event methods and extracting the response through returning return response['event'].

Although we can't just delete the old methods since users may have already implemented agents using those methods that now require a new .get('event') call to get the object that they previously would have needed, I agree with implementing this for all the new methods going forward that are not covered. I'll update the implementation.

@jgordley jgordley requested a review from kandoin September 5, 2025 14:30
@jgordley jgordley changed the title feat(memory): Add get, delete, and list memory record operations feat(memory): Add passthrough for gmdp and gmcp operations for Memory Sep 5, 2025
Copy link

@kandoin kandoin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jona62
Copy link
Contributor

jona62 commented Sep 5, 2025

LGTM!

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 50.00000% with 6 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@00cc7ed). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/bedrock_agentcore/memory/client.py 50.00% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main      #66   +/-   ##
=======================================
  Coverage        ?   88.35%           
=======================================
  Files           ?       17           
  Lines           ?     1606           
  Branches        ?      242           
=======================================
  Hits            ?     1419           
  Misses          ?       93           
  Partials        ?       94           
Flag Coverage Δ
unittests 88.35% <50.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bergjaak
Copy link
Contributor

bergjaak commented Sep 5, 2025

confirmed that memory tests ran and passed locally. Therefore we are merging this

@bergjaak bergjaak merged commit 1a85ebe into aws:main Sep 5, 2025
20 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants