Skip to content

Feature request: Add ToolSpec support for Bedrock #6267

Open
@brnaba-aws

Description

@brnaba-aws

Use case

Use case:
I would like to see Lambda Power Tools being able to produce the ToolSpec definition, from a method, to be then used with Bedrock.

Here is a ToolSpec example:

"toolSpec": {
            "name": "cosine",
            "description": "Calculate the cosine of x.",
            "inputSchema": {
                "json": {
                    "type": "object",
                    "properties": {
                        "x": {
                            "type": "number",
                            "description": "The number to pass to the function."
                        }
                    },
                    "required": ["x"]
                }
            }
        }

the python method would look like this:

def cosine(x:float): -> number
    return math.cos(x)

Solution/User Experience

A developer woud decorate its method like this:

tools = LambdaPowerToolsBedrockToolsResolver()


@tools.toolSpec(description="Calculate cosine of a number)
def cosine(
    x: Annotated[float, Query(description="The number to calculate cosine from")]
)

then it could use it with Converse Api like this:

response = bedrock.converse(
    modelId="anthropic.claude-3-sonnet-20240229-v1:0",
    messages=message_list,
    inferenceConfig={
        "maxTokens": 2000,
        "temperature": 0
    },
    toolConfig={
        "tools":tools.toolSpecs
    },
    system=[{"text":"what is cosine of 3.4"}]
)

Alternative solutions

None

Acknowledgment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Ideas

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions