# bedrock-tools
A small Python library that simplifies [Amazon Bedrock Converse API function calling](https://docs.aws.amazon.com/bedrock/latest/userguide/tool-use.html) (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
```sh
pip install bedrock-tools
```
```python
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](https://docs.aws.amazon.com/bedrock/latest/userguide/tool-use-examples.html)) with and without the library:
![alt text](img/image.png)
![alt text](img/image-2.png)
## 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
```
Raw data
{
"_id": null,
"home_page": "https://github.com/jritsema/bedrock-tools",
"name": "bedrock-tools",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "ai genai bedrock tools function-calling",
"author": "John Ritsema",
"author_email": "john_ritsema@yahoo.com",
"download_url": "https://files.pythonhosted.org/packages/a2/2f/ca6522346ecd818ec66cb54d7215f2ac85e4135231e215f544b0e3c299a5/bedrock-tools-0.2.1.tar.gz",
"platform": null,
"description": "# bedrock-tools\n\nA small Python library that simplifies [Amazon Bedrock Converse API function calling](https://docs.aws.amazon.com/bedrock/latest/userguide/tool-use.html) (i.e., tool use).\n\nThis 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.\n\n\n### Usage Example\n\n```sh\npip install bedrock-tools\n```\n\n```python\nfrom bedrock_tools import BedrockTools\n\n# define native functions as tools (using type annotations)\n\ndef add_numbers(a: int, b: int) -> int:\n \"\"\"Add two numbers together.\"\"\"\n return a + b\n\n\ndef greet(name: str) -> str:\n \"\"\"Greet a person by name.\"\"\"\n return f\"Hello, {name}!\"\n\n\ndef get_weather(city: str, state: str) -> dict:\n \"\"\"Get the weather for a location.\"\"\"\n return {\n \"city\": city,\n \"state\": state,\n \"temperature\": \"75\u00b0F\",\n \"condition\": \"Partly Cloudy\",\n }\n\n# setup\ntools = BedrockTools()\ntools.add_function(add_numbers)\ntools.add_function(greet)\ntools.add_function(get_weather)\n\n# Use the config in your Bedrock Converse API call\nresponse = bedrock.converse(\n modelId=model_id,\n toolConfig=tools.get_tool_config()\n messages=messages,\n)\n\n# When you receive a toolUse from the API, invoke the tool\nif \"toolUse\" in content_block:\n tool_results.append(tools.invoke(content_block[\"toolUse\"]))\n\nmessage = {\"role\": \"user\", \"content\": tool_results}\n```\n\n\nHere's an example (from the [Bedrock Converse API docs](https://docs.aws.amazon.com/bedrock/latest/userguide/tool-use-examples.html)) with and without the library:\n\n![alt text](img/image.png)\n\n![alt text](img/image-2.png)\n\n\n## Notes\n\nCurrently supports function parameters of type:\n\n- scalar\n - str -> string\n - int -> integegr\n - bool -> boolean\n - float -> number\n- list\n - str -> string\n - int -> integer\n - bool -> boolean\n - float -> number\n- dict -> object\n\n\n## Development\n\n```\n Choose a make command to run\n\n init run this once to initialize a new python project\n install install project dependencies\n start run local project\n test run unit tests\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "A small Python library that simplifies Amazon Bedrock Converse API function calling (i.e., tool use).",
"version": "0.2.1",
"project_urls": {
"Homepage": "https://github.com/jritsema/bedrock-tools"
},
"split_keywords": [
"ai",
"genai",
"bedrock",
"tools",
"function-calling"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a22fca6522346ecd818ec66cb54d7215f2ac85e4135231e215f544b0e3c299a5",
"md5": "966e06717e978c5fc321787b1126142a",
"sha256": "14e717f49d1dc5b6de39084278bbb5d537350c7a34c3c8c2b5c222f46e59e47e"
},
"downloads": -1,
"filename": "bedrock-tools-0.2.1.tar.gz",
"has_sig": false,
"md5_digest": "966e06717e978c5fc321787b1126142a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 3641,
"upload_time": "2024-12-18T22:51:11",
"upload_time_iso_8601": "2024-12-18T22:51:11.414959Z",
"url": "https://files.pythonhosted.org/packages/a2/2f/ca6522346ecd818ec66cb54d7215f2ac85e4135231e215f544b0e3c299a5/bedrock-tools-0.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-18 22:51:11",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jritsema",
"github_project": "bedrock-tools",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "boto3",
"specs": []
},
{
"name": "pydantic",
"specs": []
},
{
"name": "twine",
"specs": []
}
],
"lcname": "bedrock-tools"
}