- Define tool schemas the model can inspect
- Implement local handler functions that perform the requested work
- Wire a tool-call loop that executes model-suggested tool calls and returns results for the model to finalize a reply

- Python 3.11 (virtual environment recommended)
- OpenAI SDK installed in the environment
- Working directory:
/root/code
tool_app.py in /root/code:
- You supply the model with a
toolslist. Each tool includes:name— unique tool identifierdescription— natural-language description of the tool’s purposeparameters— a JSON Schema-like object describing expected arguments
- The model may respond with a message whose finish reason is
tool_calls. That response can include one or more tool call objects. - Your app:
- Extracts the tool name and arguments from the model’s tool call
- Executes the corresponding local function
- Appends a
role: "tool"message containing the tool output (andtool_call_idfor correlation) - Calls the model again so it can compose a natural-language final answer using the tool output
Links and further reading
- OpenAI API reference
- JSON Schema
- For building production agents, consider robust validation, authentication, retries, and logging.
Make sure your tool outputs are in a format the model can parse (for example, JSON strings or clear natural language). Also ensure
OPENAI_API_KEY is set in your environment before running the script.