Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(openai-agents): preserve array item schemas (#3819)

Gautam Sharmacb84856a1668
diff --git a/python/providers/openai_agents/composio_openai_agents/provider.py b/python/providers/openai_agents/composio_openai_agents/provider.py
index 3642c678b..0cb9ab818 100644
--- a/python/providers/openai_agents/composio_openai_agents/provider.py
+++ b/python/providers/openai_agents/composio_openai_agents/provider.py
@@ -13,11 +13,15 @@ from composio.utils.pydantic import parse_pydantic_error
from composio.utils.shared import normalize_tool_arguments
-# Recursively remove 'examples' keys from the schema properties
+# Recursively remove unsupported annotation/validation keys from schema properties.
def _remove_examples_from_schema(schema_obj: t.Dict[str, t.Any]) -> None:
"""
Remove 'examples', 'pattern', and 'default' keys from all properties in the
- schema, including nested ones. Also ensure that any 'items' object has a 'type' key.
+ schema, including nested ones.
+
+ Array item schemas are otherwise preserved verbatim. JSON Schema permits
+ ``items`` to use combiners, references, object keywords, or an empty schema
+ without declaring a direct ``type``.
"""
# Handle properties directly
if "properties" in schema_obj and isinstance(schema_obj["properties"], dict):
@@ -31,12 +35,6 @@ def _remove_examples_from_schema(schema_obj: t.Dict[str, t.Any]) -> None:
if "default" in prop_value:
del prop_value["default"]
- # Ensure 'items' has a 'type' key
- if "items" in prop_value and isinstance(prop_value["items"], dict):
- if "type" not in prop_value["items"]:
- # Default to string type for items if not specified
- prop_value["items"]["type"] = "string"
-
# Recursively process nested properties
_remove_examples_from_schema(prop_value)
@@ -48,9 +46,6 @@ def _remove_examples_from_schema(schema_obj: t.Dict[str, t.Any]) -> None:
del schema_obj["items"]["pattern"]
if "default" in schema_obj["items"]:
del schema_obj["items"]["default"]
- # Ensure items has a type
- if "type" not in schema_obj["items"]:
- schema_obj["items"]["type"] = "string"
_remove_examples_from_schema(schema_obj["items"])
# Handle any other nested object properties
diff --git a/python/providers/openai_agents/tests/test_provider.py b/python/providers/openai_agents/tests/test_provider.py
index 768e735fd..c7af13249 100644
--- a/python/providers/openai_agents/tests/test_provider.py
+++ b/python/providers/openai_agents/tests/test_provider.py
@@ -3,6 +3,8 @@
import copy
from unittest.mock import MagicMock
+import pytest
+
from composio_openai_agents.provider import OpenAIAgentsProvider
@@ -49,3 +51,62 @@ def test_wrap_tool_does_not_mutate_input_parameters():
"required": ["owner"],
"additionalProperties": False,
}
+
+
+ "items_schema",
+ [
+ {
+ "anyOf": [
+ {
+ "type": "object",
+ "properties": {"id": {"type": "string"}},
+ "required": ["id"],
+ },
+ {"type": "null"},
+ ]
+ },
+ {
+ "oneOf": [
+ {"type": "integer"},
+ {"type": "object", "additionalProperties": True},
+ ]
+ },
+ {"$ref": "#/$defs/Entry"},
+ {
+ "properties": {"name": {"type": "string"}},
+ "required": ["name"],
+ },
+ {},
+ ],
+ ids=["nullable-any-of", "one-of", "ref", "object-keywords", "empty-schema"],
+)
+def test_wrap_tool_preserves_array_item_schemas(items_schema):
+ """Valid item schemas must not be intersected with an invented string type."""
+ tool = MagicMock(
+ slug="PROCESS_RECORDS",
+ description="Process records",
+ input_parameters={
+ "type": "object",
+ "$defs": {
+ "Entry": {
+ "type": "object",
+ "properties": {"id": {"type": "string"}},
+ }
+ },
+ "properties": {
+ "records": {
+ "type": "array",
+ "items": copy.deepcopy(items_schema),
+ }
+ },
+ "required": ["records"],
+ },
+ )
+
+ wrapped_tool = OpenAIAgentsProvider().wrap_tool(tool, lambda **kwargs: {})
+
+ assert (
+ wrapped_tool.params_json_schema["properties"]["records"]["items"]
+ == items_schema
+ )