-
Notifications
You must be signed in to change notification settings - Fork 14.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create_react_agent incompatible with AWS Bedrock input validation due to hard coded ['\nObservation:'] stop sequence #16840
Comments
🤖 It's great to see that you've identified a potential issue and even provided a suggested fix for the problem. Your understanding of the code and the specific changes needed is very helpful. If you're interested, you could consider creating a pull request with your proposed solution. This would allow the maintainers to review and potentially merge your changes into the repository. Thank you for your contribution! This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
I dont have access to bedrock. But, i think if you modify line 499 of langchain-community/langchain_community/llms/bedrock.py in the function _prepare_input_and_invoke_stream, it should work. if stop:
Can you try and let me know? |
@sudranga it looks like your formatting got messed up, but here's what I think you were trying to suggest: if stop:
if provider not in self.provider_stop_sequence_key_name_map:
raise ValueError(
f"Stop sequence key name for {provider} is not supported."
)
if provider == "amazon":
_model_kwargs["textGenerationConfig"]["stopSequences"] = stop
else:
# stop sequence from _generate() overrides
# stop sequences in the class attribute
_model_kwargs[self.provider_stop_sequence_key_name_map.get(provider)] = stop here is the error when I tried that: _model_kwargs["textGenerationConfig"]["stopSequences"] = stop |
sorry, it should be _model_kwargs["textGenerationConfig"] = {"stopSequences": stop} |
@manwithaplandy Were you able to give it a try? |
This has been confirmed as a bug on the AWS side per issue boto/boto3#3993. AWS documentation has been clarified and hopefully a bug fix will be implemented to allow more stop sequences. |
Ok, i believe you still need the langchain changes i proposed for it to work. The exact format of stopSequences seems to be under question. |
If AWS allows for arbitrary strings to be stop sequences, then the Langchain code shouldn't need to be changed at all. The code was passing the stop sequence to AWS correctly, but it was being rejected by AWS due to their validation bug. |
HI all,
Here is my prompt following langchain official doc
I passed
Here is my completed code
any suggestion on this? |
Checked other resources
Example Code
The following code:
Error Message and Stack Trace (if applicable)
Description
The function 'create_react_agent' in langchain/agent/react/agent.py binds the stop sequence ["\nObservation"] to the runnable, making it incompatible with Bedrock's validation regex: ^(|+|User:)$
When line 103 is changed from
to
the call to invoke the model is successful as part of the agent executor chain because "User:" is one of the allowed stop sequences according to AWS. I think these limitations on the stop sequences allowed are a bit nonsensical, and this may be a bug with AWS itself. However, hard coding the stop sequence into the react agent constructor prevents this from being fixed without modifying the Langchain code.
System Info
System Information
Package Information
The text was updated successfully, but these errors were encountered: