Assistants API: When tools are used?

I’m wondering when tools are used, does the Assistants API decide by itself when to choose a specific tool with an internal prompt/loop?

e.g. for example:


curl https://api.openai.com/v1/threads/THREAD_ID/runs \
  -H 'Authorization: Bearer $OPENAI_API_KEY' \
  -H 'Content-Type: application/json' \
  -H 'OpenAI-Beta: assistants=v1' \
  -d '{
    "assistant_id": "ASSISTANT_ID",
    "model": "gpt-4-1106-preview",
    "instructions": "Predict the weather",
    "tools": [{"type": "code_interpreter"}, {"type": "retrieval"}]
  }'

And provide some document about today’s weather and ask “what’s the purpose of life?” does it check internally if it has to use tools or not?

Any clarification on how tools are picked during the Assistants API workflow appreciated

Assistant instructions are the permanent behavior of the AI, such as “you are a brief and curt chatbot”, or “you label product descriptions as fruit or vegetable”. Predicting the weather isn’t a language model skill…yet.

If someone asks a brief chatbot about a weather forecast, it will need an external tool.

Tools are the AI then writing special language to trigger the API write the response in a different manner: with a “function_call” instead of a “contents” of what the AI said.

AI is always provided the tool specification (unless you manually don’t). You tell the AI about the available API tools you’ve coded with a specification, giving description, names, types of calling data to supply.

The use and applicability is AI-decided by the current user input and how well the tool (function) would seem to service the need. The AI will most respond to either a question needing more information best-served from a tool, or a request needing external action performed by a tool.

Then you call the AI again, but providing the answer or status. It gives the user the AI answer.

2 Likes