Skip to content

Conversation

@poshinchen
Copy link
Contributor

Description

Skip message with empty content in order to fix validation exception.

Related Issues

#514

Documentation PR

N/A

Type of Change

Bug fix

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

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

@poshinchen poshinchen marked this pull request as ready for review August 6, 2025 18:10
cleaned_messages = []

for message in messages:
if not message["content"]:
Copy link
Member

@dbschmigelski dbschmigelski Aug 6, 2025

Choose a reason for hiding this comment

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

when can content come back as None? Should this not always be getting set to an empty list when we receive the response from Bedrock earlier on?

content: List[ContentBlock]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it seems to be from other places where session manager stores empty content, and then was sent to bedrock.

Copy link
Member

@dbschmigelski dbschmigelski Aug 7, 2025

Choose a reason for hiding this comment

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

I think we should try to fix it in the session manager where we ensure we never write malformed messages and/or never restore the agent with these malformed messages. Because it seems like Bedrock is functioning correctly it was just passed something that didn't actually adhere to the class which is just possible because we are using python. Otherwise this feels like a patch over a session manager bug

@murphm8
Copy link

murphm8 commented Aug 8, 2025

I ran against your fix/514 branch and I don't see the crash, and I am still seeing the empty assistant blocks, but they are not causing the bedrock request to fail. I have debug messages from my agent printing them out. It may be possible to reproduce this on your side. I have the LLM responding to the "customer" via a tool, which it possibly causing this output to be empty?

Instructions something like:

Use the `respond_to_customer` tool to respond to the customer when you are ready to communicate with them.

Respond to customer:

    @tool
    async def respond_to_customer(self, response: str, agent: Agent):
        """Send a free form message to the customer

        Args:
            response (str): the full response to send to the end customer
            agent (Agent): The agent instance for accessing state

        Returns:
            str: The message that was sent
        """
        token = agent.state.get(SESSION_TOKEN_KEY)
        await self.websocket.send(ChatMessage(message=response, token=token).model_dump_json())
        return response

My logging code:

response = await agent_instance.invoke_async(f"<customerinput>{message_text}</customerinput>")
logger.debug(f"LLM Response: {response.message}")

Log:

DEBUG | strands.models.bedrock | invoking model
DEBUG | strands.models.bedrock | got response from model
DEBUG | strands.models.bedrock | finished streaming response from model
DEBUG | strands.agent.conversation_manager.sliding_window_conversation_manager | message_count=<4>, window_size=<40> | skipping context reduction
DEBUG | my_agent | LLM Response: {'role': 'assistant', 'content': []}

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