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:
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
Metadata
Release files for bedrock-tools 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bedrock-tools-0.2.1.tar.gz | 3.6 kB | Without provenance | Details for bedrock-tools-0.2.1.tar.gz |
Release files / bedrock-tools-0.2.1.tar.gz
| Download URL | bedrock-tools-0.2.1.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
14e717f49d1dc5b6de39084278bbb5d537350c7a34c3c8c2b5c222f46e59e47e
|
|
BLAKE2b-256 checksum How to use checksums |
a22fca6522346ecd818ec66cb54d7215f2ac85e4135231e215f544b0e3c299a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|
Security for bedrock-tools 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.