-
Notifications
You must be signed in to change notification settings - Fork 278
Add JSON Schema Definition for gen_ai.tool.definitions #2942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # Use this changelog template to create an entry for release notes. | ||
| # | ||
| # If your change doesn't affect end users you should instead start | ||
| # your pull request title with [chore] or use the "Skip Changelog" label. | ||
|
|
||
| # One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
| change_type: enhancement | ||
|
|
||
| # The name of the area of concern in the attributes-registry, (e.g. http, cloud, db) | ||
| component: gen-ai | ||
|
|
||
| # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
| note: Enhance the definition of `gen_ai.tool.definitions` attribute. | ||
|
|
||
| # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
| # The values here must be integers. | ||
| issues: [2721, 1835] | ||
|
|
||
| # (Optional) One or more lines of additional information to render under the primary note. | ||
| # These lines will be padded with 2 spaces and then inserted directly into the document. | ||
| # Use pipe (|) for multiline entries. | ||
| subtext: | | ||
| The schema of `gen_ai.tool.definitions` attribute is now enhanced to: | ||
| - Add JSON schema of `gen_ai.tool.definitions` attribute. | ||
| - Document the behavior of capturing tool definitions. | ||
| - Capture the tool definitions in a simplified format if the content capturing is disabled. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| { | ||
| "$defs": { | ||
| "ToolDefinition": { | ||
| "additionalProperties": true, | ||
| "description": "Represents a tool definition.", | ||
| "properties": { | ||
| "type": { | ||
| "anyOf": [ | ||
| { | ||
| "$ref": "#/$defs/ToolType" | ||
| }, | ||
| { | ||
| "type": "string" | ||
| } | ||
| ], | ||
| "description": "Type of the tool.", | ||
| "title": "Type" | ||
| }, | ||
| "name": { | ||
| "description": "Name of the tool.", | ||
| "title": "Name", | ||
| "type": "string" | ||
| }, | ||
| "description": { | ||
| "default": null, | ||
| "description": "Description of the tool.", | ||
| "title": "Description", | ||
| "type": "string" | ||
| }, | ||
| "parameters": { | ||
| "default": null, | ||
| "description": "Schema that defines the parameters accepted by the tool. The RECOMMENDED format is JSON Schema.", | ||
| "title": "Parameters" | ||
| }, | ||
| "response": { | ||
| "default": null, | ||
| "description": "Schema that defines the response returned by the tool. The RECOMMENDED format is JSON Schema.", | ||
| "title": "Response" | ||
| } | ||
| }, | ||
| "required": [ | ||
Cirilla-zmh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "type", | ||
| "name" | ||
| ], | ||
| "title": "ToolDefinition", | ||
| "type": "object" | ||
| }, | ||
| "ToolType": { | ||
| "enum": [ | ||
| "function", | ||
| "custom" | ||
| ], | ||
| "title": "ToolType", | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "description": "Represents the list of tool definitions available to the GenAI agent or model.", | ||
| "items": { | ||
| "$ref": "#/$defs/ToolDefinition" | ||
| }, | ||
| "title": "ToolDefinitions", | ||
| "type": "array" | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lmolkova I feel like this should just be a python script with comments and docstrings, reviewing this notebook format in github is annoying
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for a python script here.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe a markdown file also works here, embedding the code in the markdown file and and also with the output . python code |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,7 @@ | |
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 1, | ||
| "execution_count": null, | ||
| "id": "5124fe15", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
|
|
@@ -68,7 +68,7 @@ | |
| " type: Literal[\"tool_call\"] = Field(description=\"The type of the content captured in this part.\")\n", | ||
| " id: Optional[str] = Field(default=None, description=\"Unique identifier for the tool call.\")\n", | ||
| " name: str = Field(description=\"Name of the tool.\")\n", | ||
| " arguments: Any = Field(None, description=\"Arguments for the tool call.\")\n", | ||
| " arguments: Any = Field(default=None, description=\"Arguments for the tool call.\")\n", | ||
| "\n", | ||
| " class Config:\n", | ||
| " extra = \"allow\"\n", | ||
|
|
@@ -222,6 +222,63 @@ | |
| "# Print the JSON schema for the SystemInstructions model\n", | ||
| "print(json.dumps(SystemInstructions.model_json_schema(), indent=4))" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "f019c33a", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## `gen_ai.tool.definitions` model\n", | ||
| "\n", | ||
| "Corresponding attribute: [`gen_ai.tool.definitions`](/docs/registry/attributes/gen-ai.md#gen-ai-tool-definitions).\n", | ||
| "JSON schema: [`gen_ai-tool-definitions.json`](../gen-ai-tool-definitions.json)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "a9e84726", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "class ToolType(str, Enum):\n", | ||
| " FUNCTION = \"function\"\n", | ||
| " CUSTOM = \"custom\"\n", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bringing @alexmojaki 's comment here https://github.com/open-telemetry/semantic-conventions/pull/2793/files#r2369871417 Custom tools are only supported by OpenAI Chat API and are not even available in the Responses API - https://platform.openai.com/docs/api-reference/responses/create#responses-create-tools
|
||
| "\n", | ||
| "class ToolDefinition(BaseModel):\n", | ||
| " \"\"\"\n", | ||
| " Represents a tool definition.\n", | ||
| " \"\"\"\n", | ||
| " type: Union[ToolType, str] = Field(description=\"Type of the tool.\")\n", | ||
| " name: str = Field(description=\"Name of the tool.\")\n", | ||
| " description: str = Field(None, description=\"Description of the tool.\")\n", | ||
| " parameters: Any = Field(\n", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see comment above - parameters and response are specific to functions and don't necessarily work for non-function tools (e.g. file search) |
||
| " default=None,\n", | ||
| " description=(\n", | ||
| " \"Schema that defines the parameters accepted by the tool. \"\n", | ||
| " \"The RECOMMENDED format is JSON Schema.\"\n", | ||
| " )\n", | ||
| " )\n", | ||
| " response: Any = Field(\n", | ||
| " default=None,\n", | ||
| " description=(\n", | ||
| " \"Schema that defines the response returned by the tool. \"\n", | ||
| " \"The RECOMMENDED format is JSON Schema.\"\n", | ||
| " )\n", | ||
| " )\n", | ||
| "\n", | ||
| " class Config:\n", | ||
| " extra = \"allow\"\n", | ||
| "\n", | ||
| "class ToolDefinitions(RootModel[List[ToolDefinition]]):\n", | ||
| " \"\"\"\n", | ||
| " Represents the list of tool definitions available to the GenAI agent or model.\n", | ||
| " \"\"\"\n", | ||
| " pass\n", | ||
| "\n", | ||
| "# Print the JSON schema for the ToolDefinitions model\n", | ||
| "print(json.dumps(ToolDefinitions.model_json_schema(), indent=4))" | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
|
|
@@ -240,7 +297,7 @@ | |
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython3", | ||
| "version": "3.13.5" | ||
| "version": "3.13.7" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whether we need to capture 'name' & 'type' by default, considering they are important informations and have no sensitive/huge content? cc @ShipraJain01 @lmolkova
Here is a prototype from spring-ai instrumentation: