Skip to main content

A small Python library that simplifies Amazon Bedrock Converse API function calling (i.e., tool use).

Project description

bedrock-tools

A small Python library that simplifies Amazon Bedrock Converse API function calling (i.e., tool use).

This library reduces the boilerplate code needed to integrate native Python functions with the Amazon Bedrock Converse API, making it easier to create powerful, tool-augmented conversational AI applications.

Usage Example

pip install bedrock-tools
from bedrock_tools import BedrockTools

# define native functions as tools (using type annotations)

def add_numbers(a: int, b: int) -> int:
    """Add two numbers together."""
    return a + b


def greet(name: str) -> str:
    """Greet a person by name."""
    return f"Hello, {name}!"


def get_weather(city: str, state: str) -> dict:
    """Get the weather for a location."""
    return {
        "city": city,
        "state": state,
        "temperature": "75°F",
        "condition": "Partly Cloudy",
    }

# setup
tools = BedrockTools()
tools.add_function(add_numbers)
tools.add_function(greet)
tools.add_function(get_weather)

# Use the config in your Bedrock Converse API call
response = bedrock.converse(
    modelId=model_id,
    toolConfig=tools.get_tool_config()
    messages=messages,
)

# When you receive a toolUse from the API, invoke the tool
if "toolUse" in content_block:
    tool_results.append(tools.invoke(content_block["toolUse"]))

message = {"role": "user", "content": tool_results}

Here's an example (from the Bedrock Converse API docs) with and without the library:

alt text

alt text

Notes

Currently supports function parameters of type:

  • scalar
    • str -> string
    • int -> integegr
    • bool -> boolean
    • float -> number
  • list
    • str -> string
    • int -> integer
    • bool -> boolean
    • float -> number
  • dict -> object

Development

 Choose a make command to run

  init      run this once to initialize a new python project
  install   install project dependencies
  start     run local project
  test      run unit tests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bedrock-tools-0.2.0.tar.gz (3.6 kB view details)

Uploaded Source

File details

Details for the file bedrock-tools-0.2.0.tar.gz.

File metadata

  • Download URL: bedrock-tools-0.2.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for bedrock-tools-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5c72fed78fd454d9c6e7075101a34a16d352bc5e5ea7fc5aec7d4b602eee0b98
MD5 1f2243927703e7fe42e01dd0d3e16cd4
BLAKE2b-256 2335e555289836f522aa9dff536220ef18956a0e38ec4aaf780e9bb9abd3eff8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page