Tools for AI agents
Project description
ToolFuse
A common protocol for AI agent tools
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
ToolFuse provides a common protocol for AI agent tools, use them with your favorite agent framework or model.
Installation
pip install toolfuse
Usage
Let's define a simple weather logger tool
from toolfuse 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
@action
if they mutate the environment@observation
if 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
toolfuse-0.1.19.tar.gz
(9.8 kB
view details)
Built Distribution
File details
Details for the file toolfuse-0.1.19.tar.gz
.
File metadata
- Download URL: toolfuse-0.1.19.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.1 Darwin/22.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a2c19c418cfd3f1359174f9b092bd8a9f6b4a933605603eb890c5f3431cb0b7 |
|
MD5 | 56f18a098de8c53a4095be10a54577d6 |
|
BLAKE2b-256 | b2f90f8cc1296c88ece3535f8c74589e78efd293f600cd871a9e26685669acd4 |
File details
Details for the file toolfuse-0.1.19-py3-none-any.whl
.
File metadata
- Download URL: toolfuse-0.1.19-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.1 Darwin/22.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd5f19720b709c5e2ccd141c7596714dce2a1b99d271bea7f844f6479e827ab2 |
|
MD5 | ed622b4ee87d26d94336a549afc4ad8a |
|
BLAKE2b-256 | b2c45fb83598e3dfe44e6ab0d376d48261a06ac7be3771f3978cec21135bfd3e |