Skip to main content
Version: Next

OpenAITool

The OpenAITool class represents a tool that can be called by the OpenAI model during a conversation. Tools allow the AI to perform specific functions and interact with external systems or retrieve information.

See OpenAIMessage to see how to responds to a tool call.

Note: The tool calls are handled automatically when using OpenAIChatHelper with autoHandleToolCalls enabled.

Properties

Root Properties

PropertyTypeDefaultDescription
typeText"function"The type of tool. Currently supports "function", "custom", and other built-in types.
strictBooleanFalseWhether to enforce strict schema validation for function parameters.

Common Properties

PropertyTypeDescription
nameTextThe name of the tool, which works as an identifier.
descriptionTextDescription of the tool to help the LLM decide when to use it.

Function-specific Properties

PropertyTypeDescription
parametersObjectParameters definition for the function using JSON schema format.

Constructor

new()

new(object : Object) : OpenAITool

ParameterTypeDescription
objectObjectConfiguration object for the tool
ResultOpenAIToolNew instance of OpenAITool

Creates a new OpenAITool instance. The constructor accepts both simplified format and OpenAI API format.

Supported formats

Simplified format:

var $tool := cs.OpenAITool.new({ \
name: "get_weather"; \
description: "Get current weather for a location"; \
parameters: { \
type: "object"; \
properties: { \
location: {type: "string"; description: "City name"} \
}; \
required: ["location"] \
} \
})

OpenAI API format:

var $tool := cs.OpenAITool.new({ \
type: "function"; \
strict: True; \
function: { \
name: "get_weather"; \
description: "Get current weather for a location"; \
parameters: { \
type: "object"; \
properties: { \
location: {type: "string"; description: "City name"} \
}; \
required: ["location"] \
} \
} \
})

Integration with Chat Completions

Tools are typically used with the OpenAIChatCompletionsParameters.tools property:

var $parameters := cs.AIKit.OpenAIChatCompletionsParameters.new({ \
model: "gpt-4o-mini"; \
tools: [$tool1; $tool2; $tool3] \
})

Note: You can pass plain objects directly - they will be automatically converted to OpenAITool instances. There's no need to explicitly create OpenAITool objects.

See Also