Skip to content

Comments

Fix: a1 agent pass empty message to AWSbedrock error#182

Open
changwn wants to merge 2 commits intosnap-stanford:mainfrom
changwn:fix-AWSbedrock-emptyMessage
Open

Fix: a1 agent pass empty message to AWSbedrock error#182
changwn wants to merge 2 commits intosnap-stanford:mainfrom
changwn:fix-AWSbedrock-emptyMessage

Conversation

@changwn
Copy link

@changwn changwn commented Sep 3, 2025

1. Problem

Had intermittent error triggered by AWS Bedrock service as a local deployment. The error, showed as the issue 172, is a bug which will trigger error by bedrock server. When auto Human Message replies Each response must include thinking process followed by either <execute> or <solution> tag. But there are no tags in the current response. Please follow the instruction, fix and regenerate the response again, the Biomni agent actually sent the empty content to bedrock API which causes error.

2. Solution:

I added a new helper function named sanitize_messages to clean the message and ensure it doesn't send empty message to bedrock. Note, I did NOT test the script on other LLM models since I only have access to AWS bedrock. It solved the error when calling AWS bedrock.

2a) Call sanitize_message in generate function:

        def generate(state: AgentState) -> AgentState:
            messages = [SystemMessage(content=self.system_prompt)] + state["messages"]
            # Sanitize messages to ensure each 'content' is a nonempty string.
            messages = sanitize_messages(messages)
            response = self.llm.invoke(messages)

3. Need attention:

Although this sanitize function may fix the bug, I found there is a logic problem in the agent (generate function in a1.py). Sometime, the Ai Message will provide <observation> xxx </observation> instead of <solution>. The example in issue 172 that let the agent to list files in current directory and the agent replied with tag <observation>. However, the logic in generate function will only end the process when the response includes <solution>. Please consider adding observation in the ifelse loop to guide the agent for next step action.

4. Note:

Fixes #172 as requested.

@changwn changwn changed the title Fix: a1 agent pass empty message to AWSbedrock by adding sanitize function Fix: a1 agent pass empty message to AWSbedrock error Sep 3, 2025
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.

local deployment, cannot generate/save a plot to local directory with intermittent error

1 participant