Name | toolfuse JSON |
Version |
0.1.25
JSON |
| download |
home_page | None |
Summary | Tools for AI agents |
upload_time | 2024-05-27 19:16:12 |
maintainer | None |
docs_url | None |
author | Patrick Barker |
requires_python | <4.0,>=3.10 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<!-- PROJECT LOGO -->
<br />
<p align="center">
<!-- <a href="https://github.com/agentsea/skillpacks">
<img src="https://project-logo.png" alt="Logo" width="80">
</a> -->
<h1 align="center">ToolFuse</h1>
<p align="center">
A common protocol for AI agent tools
<br />
<a href="https://github.com/agentsea/toolfuse"><strong>Explore the docs »</strong></a>
<br />
<br />
<a href="https://github.com/agentsea/toolfuse">View Demo</a>
·
<a href="https://github.com/agentsea/toolfuse/issues">Report Bug</a>
·
<a href="https://github.com/agentsea/toolfuse/issues">Request Feature</a>
</p>
<br>
</p>
ToolFuse provides a common protocol for AI agent tools, use them with your favorite agent framework or model.
## Installation
```
pip install toolfuse
```
## Usage
A simple weather logger tool
```python
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
```
The functions to be made available to the agent as
- `@action` if they mutate the environment
- `@observation` if they are read only.
Use the tool in a prompt
```python
weather_logger = WeatherLogger()
msg = f"Please select the appropriate action from {weather_logger.json_schema()}"
```
Create a tool from an existing class
```python
from toolfuse import tool
class Foo:
def echo(self, txt: str) -> str:
return txt
foo_tool = tool(Foo())
```
Create a tool from an existing function
```python
from toolfuse import tool
def echo(txt: str) -> str:
return txt
echo_tool = tool(echo)
```
### Function Calling
Use a tool with OpenAI function calling
```python
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
```
```json
{
"role": "assistant",
"tool_calls": [
{
"id": "call_RYXaDjxpUCfWmpXU7BZEYVqS",
"type": "function",
"function": {
"name": "weather",
"arguments": "{\n \"location\": \"Paris\"}"
}
}
]
}
```
Then to use this action
```python
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)
```
## MultiTool
Combine tools with MultiTool
```python
from toolfuse import Tool, MultiTool
class Chat(Tool):
"""A simple chat tool"""
@action
def send_message(self, message: str) -> None:
"""Logs a message to the log file."""
with open("chat.txt", "a") as file:
file.write("***\n" + message + "\n")
multitool = MultiTool(tools=[WeatherLogger(), Chat()])
multitool.json_schema()
```
Merge one tools actions into another
```python
chat_tool = Chat()
chat_tool.merge(WeatherLogger())
```
Add an action to a tool
```python
def echo(txt: str) -> str:
return txt
weather_tool = WeatherLogger()
weather_tool.add_action(echo)
```
## Available Tools
:computer: [AgentDesk](https://github.com/agentsea/agentdesk) provides AI agents with a full GUI desktop locally or in the cloud.
:wrench: [AgentUtils](https://github.com/agentsea/toolfuse/blob/main/toolfuse/util.py) provides some basic utilities for agentic tool use
## Roadmap
- [ ] Integrate with langchain
- [ ] Integrate with babyagi
- [ ] Integrate with autogen
- [ ] Integrate with llamaindex
Raw data
{
"_id": null,
"home_page": null,
"name": "toolfuse",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": null,
"author": "Patrick Barker",
"author_email": "patrickbarkerco@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/0d/5f/cc186b5a6f7d21219c7e10cc9b36dc57dd64f9e885f332c1e4c33d53eb2f/toolfuse-0.1.25.tar.gz",
"platform": null,
"description": "<!-- PROJECT LOGO -->\n<br />\n<p align=\"center\">\n <!-- <a href=\"https://github.com/agentsea/skillpacks\">\n <img src=\"https://project-logo.png\" alt=\"Logo\" width=\"80\">\n </a> -->\n\n <h1 align=\"center\">ToolFuse</h1>\n\n <p align=\"center\">\n A common protocol for AI agent tools\n <br />\n <a href=\"https://github.com/agentsea/toolfuse\"><strong>Explore the docs \u00bb</strong></a>\n <br />\n <br />\n <a href=\"https://github.com/agentsea/toolfuse\">View Demo</a>\n \u00b7\n <a href=\"https://github.com/agentsea/toolfuse/issues\">Report Bug</a>\n \u00b7\n <a href=\"https://github.com/agentsea/toolfuse/issues\">Request Feature</a>\n </p>\n <br>\n</p>\n\nToolFuse provides a common protocol for AI agent tools, use them with your favorite agent framework or model.\n\n## Installation\n\n```\npip install toolfuse\n```\n\n## Usage\n\nA simple weather logger tool\n\n```python\nfrom toolfuse import Tool, action, observation\nfrom selenium import webdriver\n\n\nclass WeatherLogger(Tool):\n \"\"\"A simple weather logger.\"\"\"\n\n @action\n def log(self, message: str) -> None:\n \"\"\"Logs a message to the log file.\"\"\"\n\n with open(\"weather.txt\", \"a\") as file:\n file.write(\"***\\n\" + message + \"\\n\")\n\n @observation\n def weather(self, location: str) -> str:\n \"\"\"Checks the current weather from the internet using wttr.in.\"\"\"\n\n weather_api_url = f\"http://wttr.in/{location}?format=%l:+%C+%t\"\n response = requests.get(weather_api_url)\n response.raise_for_status()\n return response.text\n\n```\n\nThe functions to be made available to the agent as\n\n- `@action` if they mutate the environment\n- `@observation` if they are read only.\n\nUse the tool in a prompt\n\n```python\nweather_logger = WeatherLogger()\n\nmsg = f\"Please select the appropriate action from {weather_logger.json_schema()}\"\n```\n\nCreate a tool from an existing class\n\n```python\nfrom toolfuse import tool\n\nclass Foo:\n def echo(self, txt: str) -> str:\n return txt\n\n\nfoo_tool = tool(Foo())\n```\n\nCreate a tool from an existing function\n\n```python\nfrom toolfuse import tool\n\ndef echo(txt: str) -> str:\n return txt\n\necho_tool = tool(echo)\n```\n\n### Function Calling\n\nUse a tool with OpenAI function calling\n\n```python\nfrom openai import OpenAI\n\nclient = OpenAI()\n\nweatherlogger = WeatherLogger()\nschemas = weatherlogger.json_schema()\n\nmessages = []\nmessages.append({\"role\": \"system\", \"content\": \"Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous.\"})\nmessages.append({\"role\": \"user\", \"content\": \"What is the weather in Paris?\"})\n\nheaders = {\n \"Content-Type\": \"application/json\",\n \"Authorization\": \"Bearer \" + openai.api_key,\n}\njson_data = {\"model\": model, \"messages\": messages, \"tools\": schemas}\nresponse = requests.post(\n \"https://api.openai.com/v1/chat/completions\",\n headers=headers,\n json=json_data,\n)\n\nassistant_message = response.json()[\"choices\"][0][\"message\"]\nmessages.append(assistant_message)\nassistant_message\n```\n\n```json\n{\n \"role\": \"assistant\",\n \"tool_calls\": [\n {\n \"id\": \"call_RYXaDjxpUCfWmpXU7BZEYVqS\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"weather\",\n \"arguments\": \"{\\n \\\"location\\\": \\\"Paris\\\"}\"\n }\n }\n ]\n}\n```\n\nThen to use this action\n\n```python\nfor tool in assistant_message[\"tool_calls\"]:\n action = weatherlogger.find_action(tool[\"function\"][\"name\"])\n args = json.loads(tool[\"function\"][\"arguments\"])\n resp = weatherlogger.use(action, **args)\n```\n\n## MultiTool\n\nCombine tools with MultiTool\n\n```python\nfrom toolfuse import Tool, MultiTool\n\nclass Chat(Tool):\n \"\"\"A simple chat tool\"\"\"\n\n @action\n def send_message(self, message: str) -> None:\n \"\"\"Logs a message to the log file.\"\"\"\n\n with open(\"chat.txt\", \"a\") as file:\n file.write(\"***\\n\" + message + \"\\n\")\n\n\nmultitool = MultiTool(tools=[WeatherLogger(), Chat()])\nmultitool.json_schema()\n```\n\nMerge one tools actions into another\n\n```python\nchat_tool = Chat()\nchat_tool.merge(WeatherLogger())\n```\n\nAdd an action to a tool\n\n```python\ndef echo(txt: str) -> str:\n return txt\n\nweather_tool = WeatherLogger()\nweather_tool.add_action(echo)\n```\n\n## Available Tools\n\n:computer: [AgentDesk](https://github.com/agentsea/agentdesk) provides AI agents with a full GUI desktop locally or in the cloud.\n\n:wrench: [AgentUtils](https://github.com/agentsea/toolfuse/blob/main/toolfuse/util.py) provides some basic utilities for agentic tool use\n\n## Roadmap\n\n- [ ] Integrate with langchain\n- [ ] Integrate with babyagi\n- [ ] Integrate with autogen\n- [ ] Integrate with llamaindex\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Tools for AI agents",
"version": "0.1.25",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d7b209bc7b58930e0ea7a6e66e358a7af0bac0b2b261667ee513f2b146cff85c",
"md5": "693e1d268f6ae5a6eaac8c2ca230eaf6",
"sha256": "144d6b97441cb93cf9ca33c405732fdeba33cb2441dc1f8978e7c2e450497aee"
},
"downloads": -1,
"filename": "toolfuse-0.1.25-py3-none-any.whl",
"has_sig": false,
"md5_digest": "693e1d268f6ae5a6eaac8c2ca230eaf6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 11930,
"upload_time": "2024-05-27T19:16:10",
"upload_time_iso_8601": "2024-05-27T19:16:10.853827Z",
"url": "https://files.pythonhosted.org/packages/d7/b2/09bc7b58930e0ea7a6e66e358a7af0bac0b2b261667ee513f2b146cff85c/toolfuse-0.1.25-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0d5fcc186b5a6f7d21219c7e10cc9b36dc57dd64f9e885f332c1e4c33d53eb2f",
"md5": "6f85ae395c8e83c330dccea12848495d",
"sha256": "54948d6b4faf2fd2837e33534629db8fc3bcd1fbeb2d643ceb691b6b776dad59"
},
"downloads": -1,
"filename": "toolfuse-0.1.25.tar.gz",
"has_sig": false,
"md5_digest": "6f85ae395c8e83c330dccea12848495d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 12267,
"upload_time": "2024-05-27T19:16:12",
"upload_time_iso_8601": "2024-05-27T19:16:12.490269Z",
"url": "https://files.pythonhosted.org/packages/0d/5f/cc186b5a6f7d21219c7e10cc9b36dc57dd64f9e885f332c1e4c33d53eb2f/toolfuse-0.1.25.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-27 19:16:12",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "toolfuse"
}