Skip to main content

A protocol for AI agent tools

Project description


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

  • @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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opentool_ai-0.1.8.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

opentool_ai-0.1.8-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file opentool_ai-0.1.8.tar.gz.

File metadata

  • Download URL: opentool_ai-0.1.8.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.1 Darwin/22.6.0

File hashes

Hashes for opentool_ai-0.1.8.tar.gz
Algorithm Hash digest
SHA256 654ddbaae2db47b6fa814c9ac3be309079cd24803c65fc61c19b49505c9742ea
MD5 f6782621fe971870c1c2e743508e64f4
BLAKE2b-256 5d3edabd63205a92fe8388d0b352ff7a061e5c2a261d15d1406b44b3e6335434

See more details on using hashes here.

File details

Details for the file opentool_ai-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: opentool_ai-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 19.0 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

Hashes for opentool_ai-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 b4f50fb14fca76fb3a2a542ce41fb11c772844a0997a16a0937822a42a8ab5d1
MD5 85dd5b509e74ee24611b382fe3777395
BLAKE2b-256 d9584ea4a292150bf848a768d7b00997a62de7a3827b9c1d5eee991f1c218a0e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page