Skip to content

fix: add missing agentId metadata to batched agent state flush#331

Merged
Hweinstock merged 1 commit into
aws:mainfrom
Hweinstock:fix/batched-agent-state-missing-agentid-metadata
Mar 12, 2026
Merged

fix: add missing agentId metadata to batched agent state flush#331
Hweinstock merged 1 commit into
aws:mainfrom
Hweinstock:fix/batched-agent-state-missing-agentid-metadata

Conversation

@Hweinstock

@Hweinstock Hweinstock commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

Issue #, if available: N/A

Description of changes:

Problem

FAILED tests_integ/memory/integrations/test_session_manager.py::TestAgentCoreMemorySessionManager::test_agent_conversation_with_context_manager - assert 'Bob' in "I don't have access to information about your name. You haven't introduced yourself or shared your name with me in our conversation. Would you like to tell me your name?"

The integ test is failing in CI defined here.

The test uses batch_size=10 so agent state is not sent immediately and is instead only sent by flushing on session closure. The code to send the state immediately includes the AGENT_ID:

event = self.memory_client.gmdp_client.create_event(
memoryId=self.config.memory_id,
actorId=self.config.actor_id,
sessionId=self.session_id,
payload=[
{"blob": json.dumps(session_agent.to_dict())},
],
eventTimestamp=self._get_monotonic_timestamp(),
metadata={
STATE_TYPE_KEY: {"stringValue": StateType.AGENT.value},
AGENT_ID_KEY: {"stringValue": session_agent.agent_id},
},
)

However, the code to flush the agent state does not include it:

event = self.memory_client.gmdp_client.create_event(
memoryId=self.config.memory_id,
actorId=self.config.actor_id,
sessionId=self.config.session_id,
payload=agent_state_payloads,
eventTimestamp=self._get_monotonic_timestamp(),
metadata={
STATE_TYPE_KEY: {"stringValue": StateType.AGENT.value},
},
)

This causes an issue when we try to read the session information back for that agent since we query on agentId being in the metadata.

event_metadata = [
EventMetadataFilter.build_expression(
left_operand=LeftExpression.build(STATE_TYPE_KEY),
operator=OperatorType.EQUALS_TO,
right_operand=RightExpression.build(StateType.AGENT.value),
),
EventMetadataFilter.build_expression(
left_operand=LeftExpression.build(AGENT_ID_KEY),
operator=OperatorType.EQUALS_TO,
right_operand=RightExpression.build(agent_id),
),
]
events = self.memory_client.list_events(
memory_id=self.config.memory_id,
actor_id=self.config.actor_id,
session_id=session_id,
event_metadata=event_metadata,
max_results=1,
)
.

Solution

  • batch the events by agentId and send with the proper metadata.

Testing

  • ran the integ tests in my dev account with the fix.
  • integ tests ran in CI on the PR.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov-commenter

codecov-commenter commented Mar 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@66c8488). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #331   +/-   ##
=======================================
  Coverage        ?   90.85%           
=======================================
  Files           ?       42           
  Lines           ?     4046           
  Branches        ?      624           
=======================================
  Hits            ?     3676           
  Misses          ?      203           
  Partials        ?      167           
Flag Coverage Δ
unittests 90.85% <100.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.

@Hweinstock Hweinstock force-pushed the fix/batched-agent-state-missing-agentid-metadata branch from a119d16 to ba7a5d4 Compare March 12, 2026 16:19
@Hweinstock Hweinstock force-pushed the fix/batched-agent-state-missing-agentid-metadata branch from ba7a5d4 to 933922e Compare March 12, 2026 16:47
@Hweinstock Hweinstock marked this pull request as ready for review March 12, 2026 16:59
@Hweinstock Hweinstock requested a review from a team March 12, 2026 16:59
@Hweinstock Hweinstock merged commit 11e2ac5 into aws:main Mar 12, 2026
20 checks passed
@Hweinstock Hweinstock deleted the fix/batched-agent-state-missing-agentid-metadata branch March 12, 2026 17:10
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.

3 participants