BMTools Save

Project README


BMTools is an open-source repository that extends language models using tools and serves as a platform for the community to build and share tools. In this repository, you can (1) easily build a plugin by writing python functions (2) use external ChatGPT-Plugins.

This project is inspired by the open-source project LangChain and optimized for the usage of open-sourced tools like ChatGPT-Plugins, striving to achieve the open-source academic version of ChatGPT-Plugins.

Current version of BMTools is far from perfect, we will continue to improve it.

1. Setup

git clone [email protected]:OpenBMB/BMTools.git
python develop

2. Use existing tools

2.1 Set up tools

2.1.1 Local tools

Add your api keys to, then start the local tools


Then use set the url of plugin to{tool_name}/ (Remember the tailing /).

2.1.2 Use online ChatGPT-Plugins

Just loaded it with the URL pointed to the .well-known/ai-plugin.json For example, Set the url to, where is a valid configuration.

2.2 Use a single tool

from bmtools.agent.singletool import load_single_tools, STQuestionAnswerer

tool_name, tool_url = 'klarna',  ''
tool_name, tool_config = load_single_tools(tool_name, tool_url)
print(tool_name, tool_config)
stqa =  STQuestionAnswerer()

agent = stqa.load_tools(tool_name, tool_config)
agent("{Your Question}")

2.3 Use multiple tools

We can use multiple tools at the same time. Basically, the language model will do it recursively. It will treat the whole tool as an API, send questions to it, and the tool calls its sub-APIs to solve the question and send it back to parent tools. This functionality will be useful in the upcoming Chat mode.

Try this functionality using scripts like:

from bmtools.agent.tools_controller import load_valid_tools, MTQuestionAnswerer
tools_mappings = {
    "klarna": "",
    "chemical-prop": "",
    "wolframalpha": "",

tools = load_valid_tools(tools_mappings)

qa =  MTQuestionAnswerer(openai_api_key='', all_tools=tools)

agent = qa.build_runner()

agent("How many benzene rings are there in 9H-Carbazole-3-carboxaldehyde? and what is sin(x)*exp(x)'s plot, what is it integrated from 0 to 1? ")

2.4 Use the web demo

  1. Add your plugin to the mappings at beginning of

  2. Start the webdemo


3. Use customized tools

3.1 Develop a tool locally

To develop a tool locally, you need to write a python function to build the tool and register it to the registry.

For example, you can write a tool that can execute python code and return the result. The following is a sample code:

from import Tool
from pydantic import BaseModel

class ExecutionQuery(BaseModel):
    code: str

class ExecutionResult(BaseModel):
    result: str

def build_python_tool(config) -> Tool:
    tool = Tool(
        "A plugin that can execute python code",
        description_for_model="A plugin that can execute python code",
        contact_email="[email protected]",
    def execute_python_code(query : ExecutionQuery) -> ExecutionResult:
        return ExecutionResult(
    return tool

Then you need to register the tool to the registry using the following code:

from import register

def register_python_tool():
    return build_python_tool

Here we register the tool with the name python.

3.2 Contributing to BMTools

After you have developed a tool, you can contribute it to BMTools by following the steps below:

  1. Fork this repository
  2. Create a folder in bmtools/tools/{tool_name}
  3. Add an to the folder: bmtools/tools/{tool_name}/ and a to the folder: bmtools/tools/{tool_name}/
  4. Register the tool in the file you created in step 3 using the code in section 3.1
  5. Import your tool in the file under bmtools/tools
  6. Add a to test your tool automatically
  7. Add a in your folder containing a brief introduction, contributor information, or anything you want to let others know.

4. Optimize your tool's prompt

The functions you wrote will be converted into an interface compatible with the OpenAI plugin. The AI models will read the name, description of the tools, and the name, descriptions of the APIs of that tools. You can adjust the following aspect to make your API better understood by AI models.

  • (1) name_for_model (tells the model what the tool is)
  • (2) description_for_model (this will be displayed to the model before the tool is called, and you can include information on how to use the APIs)
  • (3) The function name for each API function, as well as the name in @tool.get(). It's best if these two names match, as the name plays an important role in the model's API selection.
  • (4) The function's doc string (can suggest to the model whether to use this API or not)
  • (5) The function's return value, which can provide the model with error messages to guide its next steps, such as retrying or indicating a preferred next step
  • (6) Reduce the errors in your API function.

A simple example to refer to is the Wolfram Alpha API.

Open Source Agenda is not affiliated with "BMTools" Project. README Source: OpenBMB/BMTools
Open Issues
Last Commit
2 months ago

Open Source Agenda Badge

Open Source Agenda Rating