OpenTool
A common protocol for AI agent tools
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
OpenTool provides a common potocol for AI agent tools, use them with your favorite agent framework or model.
Installation
pip install opentool-ai
Usage
Let's define a simple weather logger tool
from opentool import Tool, action, observation
from selenium import webdriver
class WeatherLogger(Tool):
"""A simple weather logger."""
@action
def log(self, message: str) -> None:
"""Logs a message to the log file."""
with open("weather.txt", "a") as file:
file.write("***\n" + message + "\n")
@observation
def weather(self, location: str) -> str:
"""Checks the current weather from the internet using wttr.in."""
weather_api_url = f"http://wttr.in/{location}?format=%l:+%C+%t"
response = requests.get(weather_api_url)
response.raise_for_status()
return response.text
We mark the functions to be made available to the agent as
@actionif they mutate the environment@observationif they are read only.
Function Calling
Use a tool with OpenAI function calling
from openai import OpenAI
client = OpenAI()
weatherlogger = WeatherLogger()
schemas = weatherlogger.json_schema()
messages = []
messages.append({"role": "system", "content": "Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous."})
messages.append({"role": "user", "content": "What is the weather in Paris?"})
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer " + openai.api_key,
}
json_data = {"model": model, "messages": messages, "tools": schemas}
response = requests.post(
"https://api.openai.com/v1/chat/completions",
headers=headers,
json=json_data,
)
assistant_message = response.json()["choices"][0]["message"]
messages.append(assistant_message)
assistant_message
{
"role": "assistant",
"tool_calls": [
{
"id": "call_RYXaDjxpUCfWmpXU7BZEYVqS",
"type": "function",
"function": {
"name": "weather",
"arguments": "{\n \"location\": \"Paris\"}"
}
}
]
}
Then to use this action
for tool in assistant_message["tool_calls"]:
action = weatherlogger.find_action(tool["function"]["name"])
args = json.loads(tool["function"]["arguments"])
resp = weatherlogger.use(action, **args)
Available Tools
:computer: AgentDesk provides AI agents with a full GUI desktop locally or in the cloud.
Roadmap
- Integrate with langchain
- Integrate with babyagi
- Integrate with autogen
- Integrate with llamaindex
Metadata
Release files for opentool-ai 0.1.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| opentool_ai-0.1.10.tar.gz | 14.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| opentool_ai-0.1.10-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 34.6 kB
Release files / opentool_ai-0.1.10.tar.gz
| Download URL | opentool_ai-0.1.10.tar.gz |
|---|---|
| Size | 14.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1895f540b9d3bf5e7add84cd50a651b9ef3371a74380f9eb646918b8bbe4b9ca
|
|
BLAKE2b-256 checksum How to use checksums |
e8f326307c0275f340c9e0d91ac26ea8440e925be57f1dd507a2501b72429324
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.10.1 Darwin/22.6.0
|
Release files / opentool_ai-0.1.10-py3-none-any.whl
| Download URL | opentool_ai-0.1.10-py3-none-any.whl |
|---|---|
| Size | 20.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
50f6fecb0dc0eea7bb10a3793948822da79dd53bcd4cff36ee227de0c02f8300
|
|
BLAKE2b-256 checksum How to use checksums |
635443f98d9b1e59af88c09c500c07d1ee8774c7e02c0c50215caac10a30773a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.10.1 Darwin/22.6.0
|