Skip to content

[FEATURE] Allow to pass in OpenAI (or other) message formats #1541

@afarntrog

Description

@afarntrog

Problem Statement

Strands SDK currently follows the Bedrock Converse API format which is not compatible with the OpenAI Message format.
Some noticeable differences are:

  • The roles accepted. Bedrock only accepts user and assistant whereas OpenAI supports additional roles such as tool
  • The message format is different. For example the Bedrock API formats a text block with JSON "messages": [ { "role": "user", "content": [ { "text": "Hello, how are you?" } ] },. Whereas the OpenAI format is just the text set to the content field: "messages": [ { "role": "system", "content": "You are a helpful assistant." },]

This can cause issues when a developer wants to migrate their existing OpenAI conversations to work natively with Strands SDK.

Proposed Solution

We can add the following two methods to the SessionManager base class:
serialize() and deserialize(). All the SessionManagers that inherit the session manager bases class will have these methods automatically. By default - these methods will just return the current message. deserialize() will be called for each message when the session manager loads messages from it's history. serialize() will be called on each message prior to storing the message.

Customers can then implement these methods in their session managers to convert their message format to the Bedrock API format so that Strands can work with the messages as normal and they can continue to store the messages in the format of their choosing.

For example, a customer bringing messages from OpenAI can simply have the following:

class MySpecialSessionManager(S3SessionManager):

    @override
    def deserialize(msg: Message):
        return convert_from_open_ai(msg)

    @override
    def serialize(msg: Message):
        return convert_to_open_ai(msg)

This will allow us to support customers bringing over existing messages that are in formats other than the Bedrock API format and allow for seamless use with Strands SDK.

Use Case

Customers migrating conversations to Strands that they have stored in the OpenAI message format

Alternatives Solutions

We build a Convertor layer into the SDK so the SDK will be message format agnostic.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions