microsoft / autogen

A programming framework for agentic AI 🤖
https://microsoft.github.io/autogen/
Creative Commons Attribution 4.0 International
30.71k stars 4.47k forks source link

[Bug]: Bedrock support not working #3295

Closed billdoors closed 2 weeks ago

billdoors commented 1 month ago

Describe the bug

https://github.com/microsoft/autogen/pull/3210

Steps to reproduce

  1. I verified that my aws_access_key, aws_secret_key, and aws_session_token are working fine using the following code:
from anthropic import AnthropicBedrock
client = AnthropicBedrock(
       aws_access_key="xxx",
       aws_secret_key="xxx",
       aws_session_token= "xxx"
        aws_region="us-east-1",
)

message = client.messages.create(
    model="anthropic.claude-3-sonnet-20240229-v1:0",
    max_tokens=256,
    messages=[{"role": "user", "content": "Hello, world. tell me a joke"}]
)

2.

import autogen

config_list = {
        "model": "anthropic.claude-3-5-sonnet-20240620-v1:0",
        "aws_access_key":"xxx",
        "aws_secret_key":"xxx",
        "aws_session_token": "xxx",
        "aws_region":"us-east-1",
        "api_type": "anthropic",
    }
assistant = autogen.AssistantAgent("assistant", llm_config=config_list)

support_request = {
        "content": "I am unable to install the latest update of the software.",
        "role": "user"
    }

assistant.generate_reply(messages=[support_request])

I got error message: PermissionDeniedError: Error code: 403 - {'message': 'The security token included in the request is invalid.'}

Model Used

No response

Expected Behavior

No response

Screenshots and logs

No response

Additional Information

No response

Varun2101 commented 1 month ago

Facing the same issue.

Appears to be related to https://github.com/microsoft/autogen/pull/3210/commits/f0548409eb7d55c762369df0e308289d8a68fe1a where the aws_session_token was removed from required_keys. It's not optional if you're working with session access to AWS Bedrock (eg. for developing/testing code locally). It should get added to openai_config if it's not None.

billdoors commented 1 month ago

@Varun2101 you are right. If I create an IAM user and provide the aws_access_key and aws_secret_key, it works.

PrashantSaikia commented 1 month ago

How do we make Autogen work with Bedrock? I am trying the following code with a Mistral model:

from autogen import AssistantAgent, UserProxyAgent
from dotenv import load_dotenv
import os

load_dotenv()

config_list = [
    {
        "model": "mistral.mixtral-8x7b-instruct-v0:1",
        "aws_access_key":os.getenv('aws_access_key_id'),
        "aws_secret_key":os.getenv('aws_secret_access_key'),
        "aws_region":"us-west-2",
        "aws_session_token":"none",
        "api_type": "mistral",
        "api_key": "none"
    }
]

assistant = AssistantAgent("assistant", llm_config={"config_list": config_list})

# Create a UserProxyAgent that can execute code
user_proxy = UserProxyAgent("user_proxy", code_execution_config={"use_docker": False})

# Initiate a chat between the user proxy and the assistant
message = f'''<s>[INST]
Enter your prompt here
[/INST]'''

user_proxy.initiate_chat(assistant, message=message)

It gives me the following error:

MistralAPIException: Status: 401. Message: {
  "message":"Unauthorized",
  "request_id":"02fb534ea9da864a9db3646dbc4cf16b"
}
makkzone commented 1 month ago

As of now, it supports only anthropic.

Bedrock client is being added to Autogen through #3232 .

makkzone commented 1 month ago

@billdoors This was fixed. Please close this if you are good.