Tools
TaskingAI allows the integration of multiple tools into an assistant, expanding its capabilities to perform various actions and utilize the results in the assistant's responses. This guide demonstrates how to integrate tools into an assistant and utilize them effectively.
Create an Action
Before integrating tools into an assistant, you need to create actions for each tool. Actions are predefined functionalities that the assistant can execute. You can create actions either through the TaskingAI dashboard (UI) or using the Python SDK.
See Creating an Action for more information.
Create an Assistant with Tools
Once you have created the necessary tools, you can proceed to create an assistant and bind these actions as tools.
Let’s say we have two tools: one for providing weather updates (weather_tool
) and another for currency exchange rates (currency_exchange_tool
).
You can get plugin_id
as shown below:
First, create an assistant and include these tools:
import taskingai
from taskingai.assistant import Assistant
assistant: Assistant = taskingai.assistant.create_assistant(
model_id="YOUR_MODEL_ID",
name="My Multifunctional Assistant",
description="An assistant capable of providing weather updates and currency exchange rates.",
system_prompt_template=[
"You provide the latest weather updates.",
"You also offer current currency exchange rates."
],
tools=[
{"type": "plugin", "id": "open_weather/get_current_weather"},
{"type": "plugin", "id": "exchangerate_api/get_exchange_rate"},
],
memory={"type": "naive"},
)
print(f"created assistant: {assistant}\n")
Testing the Assistant
To test the assistant’s capabilities with the integrated tools, create a chat session and generate assistant messages using the generate_message method.
Testing Weather Tool:
# Create a chat session
chat = taskingai.assistant.create_chat(
assistant_id=assistant.assistant_id,
)
# User asks for weather updates
taskingai.assistant.create_message(
assistant_id=assistant.assistant_id,
chat_id=chat.chat_id,
text="What is the weather like in New York today?"
)
# Generate assistant response for weather
assistant_message_weather = taskingai.assistant.generate_message(
assistant_id=assistant.assistant_id,
chat_id=chat.chat_id,
)
print(f"Assistant: {assistant_message_weather.content.text}")
Testing Currency Exchange Tool:
# User asks for currency exchange rates
taskingai.assistant.create_message(
assistant_id=assistant.assistant_id,
chat_id=chat.chat_id,
text="What is the exchange rate for USD to EUR?"
)
# Generate assistant response for currency exchange
assistant_message_currency = taskingai.assistant.generate_message(
assistant_id=assistant.assistant_id,
chat_id=chat.chat_id,
)
print(f"Assistant: {assistant_message_currency.content.text}")