{"record":{"id":"e66118fdc581158a","repo":"agentscope-ai/agentscope","slug":"the-field-key-already-exists-in-the-original-f","errorCode":null,"errorMessage":"The field `{key}` already exists in the original function schema of `{self.tool.name}`. Try to use a different name.","messagePattern":"The field `(.+?)` already exists in the original function schema of `(.+?)`\\. Try to use a different name\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/tool/_types.py","lineNumber":100,"sourceCode":"                \"description\": self.tool.description,\n                \"parameters\": input_schema,\n            },\n        }\n\n        extended_model = extended_model or self.extended_model\n\n        if extended_model is None:\n            return function_schema\n\n        # Merge the extended model with the original JSON schema\n        extended_schema = extended_model.model_json_schema()\n\n        _remove_title_field(extended_schema)\n\n        # Merge properties from extended schema\n        for key, value in extended_schema[\"properties\"].items():\n            if key in function_schema[\"function\"][\"parameters\"][\"properties\"]:\n                raise ValueError(\n                    f\"The field `{key}` already exists in the original \"\n                    f\"function schema of `{self.tool.name}`. Try to use a \"\n                    \"different name.\",\n                )\n\n            function_schema[\"function\"][\"parameters\"][\"properties\"][\n                key\n            ] = value\n\n            if key in extended_schema.get(\"required\", []):\n                if \"required\" not in function_schema[\"function\"][\"parameters\"]:\n                    function_schema[\"function\"][\"parameters\"][\"required\"] = []\n                function_schema[\"function\"][\"parameters\"][\"required\"].append(\n                    key,\n                )\n\n        # Merge $defs from extended schema to support nested models\n        if \"$defs\" in extended_schema:","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/tool/_types.py#L82-L118","documentation":"Raised in ToolMetadata.get_tool_schema when merging an extended model's schema into the tool's original function schema and a property name collides with one already defined on the original function parameters. Extended models are meant to add new fields, not redefine existing ones.","triggerScenarios":"Calling get_tool_schema(extended_model=SomeModel) where SomeModel has a field whose name matches a parameter of the wrapped function, e.g. the function has an 'offset' parameter and the extended model also defines 'offset'.","commonSituations":"Adding metadata fields (session_id, user_id, memory) via an extended BaseModel whose field names clash with existing function args; reusing a generic Context model across multiple tools.","solutions":["Rename the conflicting field on the extended BaseModel to something not used by the function signature","Strip/alias the overlapping function parameter or the model field","Audit field names: set(model.model_fields) vs the function's parameter names before merging"],"exampleFix":"# before\nclass Ext(BaseModel):\n    query: str  # collides with function arg `query`\ntool_meta.get_tool_schema(extended_model=Ext)\n# after\nclass Ext(BaseModel):\n    context_query: str\ntool_meta.get_tool_schema(extended_model=Ext)","handlingStrategy":"validation","validationCode":"import inspect\nfn_params = set(inspect.signature(func).parameters)\ncollisions = fn_params & set(ExtendedModel.model_fields)\nassert not collisions, f'field name collisions: {collisions}'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Namespace extended-model fields with a prefix (ctx_, user_) to avoid collisions","Add a CI check comparing function params against extended model fields"],"tags":["schema","merge","conflict","pydantic","tool"],"backgroundTag":"schema-field-conflict","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}