{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "#/components/schemas/CodeTool",
"title": "CodeTool",
"type": "object",
"properties": {
"messages": {
"type": "array",
"description": "These are the messages that will be spoken to the user as the tool is running.\n\nFor some tools, this is auto-filled based on special fields like `tool.destinations`. For others like the function tool, these can be custom configured.",
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/ToolMessageStart",
"title": "ToolMessageStart"
},
{
"$ref": "#/components/schemas/ToolMessageComplete",
"title": "ToolMessageComplete"
},
{
"$ref": "#/components/schemas/ToolMessageFailed",
"title": "ToolMessageFailed"
},
{
"$ref": "#/components/schemas/ToolMessageDelayed",
"title": "ToolMessageDelayed"
}
]
}
},
"type": {
"type": "string",
"enum": [
"code"
],
"description": "The type of tool. \"code\" for Code tool."
},
"async": {
"type": "boolean",
"example": false,
"description": "This determines if the tool is async.\n\n If async, the assistant will move forward without waiting for your server to respond. This is useful if you just want to trigger something on your server.\n\n If sync, the assistant will wait for your server to respond. This is useful if want assistant to respond with the result from your server.\n\n Defaults to synchronous (`false`)."
},
"server": {
"description": "\n This is the server where a `tool-calls` webhook will be sent.\n\n Notes:\n - Webhook is sent to this server when a tool call is made.\n - Webhook contains the call, assistant, and phone number objects.\n - Webhook contains the variables set on the assistant.\n - Webhook is sent to the first available URL in this order: {{tool.server.url}}, {{assistant.server.url}}, {{phoneNumber.server.url}}, {{org.server.url}}.\n - Webhook expects a response with tool call result.",
"allOf": [
{
"$ref": "#/components/schemas/Server"
}
]
},
"code": {
"type": "string",
"description": "TypeScript code to execute when the tool is called",
"maxLength": 50000
},
"environmentVariables": {
"description": "Environment variables available in code via `env` object",
"type": "array",
"items": {
"$ref": "#/components/schemas/CodeToolEnvironmentVariable"
}
},
"timeoutSeconds": {
"type": "number",
"description": "This is the timeout in seconds for the code execution. Defaults to 10 seconds.\nMaximum is 30 seconds to prevent abuse.\n\n@default 10",
"minimum": 1,
"maximum": 30,
"example": 10
},
"credentialId": {
"type": "string",
"description": "Credential ID containing the Val Town API key",
"example": "550e8400-e29b-41d4-a716-446655440000"
},
"variableExtractionPlan": {
"description": "Plan to extract variables from the tool response",
"allOf": [
{
"$ref": "#/components/schemas/VariableExtractionPlan"
}
]
},
"id": {
"type": "string",
"description": "This is the unique identifier for the tool."
},
"orgId": {
"type": "string",
"description": "This is the unique identifier for the organization that this tool belongs to."
},
"createdAt": {
"format": "date-time",
"type": "string",
"description": "This is the ISO 8601 date-time string of when the tool was created."
},
"updatedAt": {
"format": "date-time",
"type": "string",
"description": "This is the ISO 8601 date-time string of when the tool was last updated."
},
"rejectionPlan": {
"description": "This is the plan to reject a tool call based on the conversation state.\n\n// Example 1: Reject endCall if user didn't say goodbye\n```json\n{\n conditions: [{\n type: 'regex',\n regex: '(?i)\\\\b(bye|goodbye|farewell|see you later|take care)\\\\b',\n target: { position: -1, role: 'user' },\n negate: true // Reject if pattern does NOT match\n }]\n}\n```\n\n// Example 2: Reject transfer if user is actually asking a question\n```json\n{\n conditions: [{\n type: 'regex',\n regex: '\\\\?',\n target: { position: -1, role: 'user' }\n }]\n}\n```\n\n// Example 3: Reject transfer if user didn't mention transfer recently\n```json\n{\n conditions: [{\n type: 'liquid',\n liquid: `{% assign recentMessages = messages | last: 5 %}\n{% assign userMessages = recentMessages | where: 'role', 'user' %}\n{% assign mentioned = false %}\n{% for msg in userMessages %}\n {% if msg.content contains 'transfer' or msg.content contains 'connect' or msg.content contains 'speak to' %}\n {% assign mentioned = true %}\n {% break %}\n {% endif %}\n{% endfor %}\n{% if mentioned %}\n false\n{% else %}\n true\n{% endif %}`\n }]\n}\n```\n\n// Example 4: Reject endCall if the bot is looping and trying to exit\n```json\n{\n conditions: [{\n type: 'liquid',\n liquid: `{% assign recentMessages = messages | last: 6 %}\n{% assign userMessages = recentMessages | where: 'role', 'user' | reverse %}\n{% if userMessages.size < 3 %}\n false\n{% else %}\n {% assign msg1 = userMessages[0].content | downcase %}\n {% assign msg2 = userMessages[1].content | downcase %}\n {% assign msg3 = userMessages[2].content | downcase %}\n {% comment %} Check for repetitive messages {% endcomment %}\n {% if msg1 == msg2 or msg1 == msg3 or msg2 == msg3 %}\n true\n {% comment %} Check for common loop phrases {% endcomment %}\n {% elsif msg1 contains 'cool thanks' or msg2 contains 'cool thanks' or msg3 contains 'cool thanks' %}\n true\n {% elsif msg1 contains 'okay thanks' or msg2 contains 'okay thanks' or msg3 contains 'okay thanks' %}\n true\n {% elsif msg1 contains 'got it' or msg2 contains 'got it' or msg3 contains 'got it' %}\n true\n {% else %}\n false\n {% endif %}\n{% endif %}`\n }]\n}\n```",
"allOf": [
{
"$ref": "#/components/schemas/ToolRejectionPlan"
}
]
},
"function": {
"description": "This is the function definition of the tool.\n\nFor the Code tool, this defines the name, description, and parameters that the model\nwill use to understand when and how to call this tool.",
"allOf": [
{
"$ref": "#/components/schemas/OpenAIFunction"
}
]
}
},
"required": [
"type",
"code",
"id",
"orgId",
"createdAt",
"updatedAt"
]
}