Anthropic tools
The anthropic-tools library simplifies the usage of Anthropics’s tool use feature. It abstracts away the complexity of parsing function signatures and docstrings by providing developers with a clean and intuitive interface. It's a near-clone of my openai-functions library that does the same with OpenAI.
Installation
You can install anthropic-tools from PyPI using pip:
pip install anthropic-tools
Usage
- Import the necessary modules and provide your API key:
import enum
import anthropic
from anthropic_tools import Conversation
client = anthropic.Anthropic(
api_key="<YOUR_API_KEY>",
)
- Create a
Conversationinstance:
conversation = Conversation(client)
- Define your tools using the
@conversation.add_tooldecorator:
class Unit(enum.Enum):
FAHRENHEIT = "fahrenheit"
CELSIUS = "celsius"
@conversation.add_tool()
def get_current_weather(location: str, unit: Unit = Unit.FAHRENHEIT) -> dict:
"""Get the current weather in a given location.
Args:
location (str): The city and state, e.g., San Francisco, CA
unit (Unit): The unit to use, e.g., fahrenheit or celsius
"""
return {
"location": location,
"temperature": "72",
"unit": unit.value,
"forecast": ["sunny", "windy"],
}
- Ask the AI a question:
response = conversation.ask("What's the weather in San Francisco?")
# Should return three messages, the last one's content being something like:
# The current weather in San Francisco is 72 degrees Fahrenheit and it is sunny and windy.
You can read more about how to use Conversation here.
More barebones use - just schema generation and result parsing:
from anthropic_tools import ToolWrapper
wrapper = ToolWrapper(get_current_weather)
schema = wrapper.schema
result = wrapper({"location": "San Francisco, CA"})
Or you could use skills.
How it Works
anthropic-tools takes care of the following tasks:
- Parsing the function signatures (with type annotations) and docstrings.
- Sending the conversation and tool descriptions to Anthropic Claude.
- Deciding whether to call a tool based on the model's response.
- Calling the appropriate function with the provided arguments.
- Updating the conversation with the tool response.
- Repeating the process until the model generates a user-facing message.
This abstraction allows developers to focus on defining their functions and adding user messages without worrying about the details of tool use.
Note
Please note that anthropic-tools is an unofficial project not maintained by Anthropic. Use it at your discretion.
Metadata
Release files for anthropic-tools 1.0.7
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 |
|---|---|---|---|---|
| anthropic_tools-1.0.7.tar.gz | 16.0 kB | Without provenance | Details for anthropic_tools-1.0.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| anthropic_tools-1.0.7-py3-none-any.whl | Python 3 | none | any | Details for anthropic_tools-1.0.7-py3-none-any.whl |
Total release size: 39.9 kB
Release files / anthropic_tools-1.0.7.tar.gz
| Download URL | anthropic_tools-1.0.7.tar.gz |
|---|---|
| Size | 16.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c594f7f405ee208f4a32ffaede098fb00efbddc8d714dc601dceddfd7ca51c4b
|
|
BLAKE2b-256 checksum How to use checksums |
8c66a10d6859ecd7d4ee2caebf61b930dd7016d887002df630ce480843b88187
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.2 CPython/3.11.8 Linux/6.8.2-zen2-1-zen
|
Release files / anthropic_tools-1.0.7-py3-none-any.whl
| Download URL | anthropic_tools-1.0.7-py3-none-any.whl |
|---|---|
| Size | 23.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5144d9a93c583870c2b6d7744b4b79e105da5cd1e5b9975ee1e8d56f378134b5
|
|
BLAKE2b-256 checksum How to use checksums |
fc511101eb20e442b54e015c1f324f897b20db7bdc7c428030caadc7da38e866
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.2 CPython/3.11.8 Linux/6.8.2-zen2-1-zen
|
Security for anthropic-tools 1.0.7
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.