Skip to content

Conversation

@Light2Dark
Copy link
Contributor

@Light2Dark Light2Dark commented Nov 20, 2025

📝 Summary

The motivation to clean up the edit notebook tool is that discriminated unions are more verbose in context size:

tool schema parameters with discriminated union
            "properties": {
                "edit": {
                    "anyOf": [
                        {
                            "type": "object",
                            "properties": {
                                "type": {
                                    "type": "string",
                                    "const": "update_cell",
                                },
                                "cellId": {"type": "string"},
                                "code": {"type": "string"},
                            },
                            "required": ["type", "cellId", "code"],
                            "additionalProperties": False,
                        },
                        {
                            "type": "object",
                            "properties": {
                                "type": {
                                    "type": "string",
                                    "const": "add_cell",
                                },
                                "position": {
                                    "anyOf": [
                                        {
                                            "type": "object",
                                            "properties": {
                                                "type": {
                                                    "type": "string",
                                                    "const": "relative",
                                                },
                                                "cellId": {"type": "string"},
                                                "before": {"type": "boolean"},
                                            },
                                            "required": [
                                                "type",
                                                "cellId",
                                                "before",
                                            ],
                                            "additionalProperties": False,
                                        },
                                        {
                                            "type": "object",
                                            "properties": {
                                                "type": {
                                                    "type": "string",
                                                    "const": "column_end",
                                                },
                                                "columnIndex": {
                                                    "type": "number"
                                                },
                                            },
                                            "required": [
                                                "type",
                                                "columnIndex",
                                            ],
                                            "additionalProperties": False,
                                        },
                                        {
                                            "type": "object",
                                            "properties": {
                                                "type": {
                                                    "type": "string",
                                                    "const": "notebook_end",
                                                }
                                            },
                                            "required": ["type"],
                                            "additionalProperties": False,
                                        },
                                    ]
                                },
                                "code": {"type": "string"},
                            },
                            "required": ["type", "position", "code"],
                            "additionalProperties": False,
                        },
                        {
                            "type": "object",
                            "properties": {
                                "type": {
                                    "type": "string",
                                    "const": "delete_cell",
                                },
                                "cellId": {"type": "string"},
                            },
                            "required": ["type", "cellId"],
                            "additionalProperties": False,
                        },
                    ]
                }
            },
after simplifying
            "properties": {
                "edit": {
                    "type": "object",
                    "properties": {
                        "type": {
                            "type": "string",
                            "enum": ["update_cell", "add_cell", "delete_cell"],
                        },
                        "code": {"type": "string"},
                        "position": {
                            "type": "object",
                            "properties": {
                                "type": {
                                    "type": "string",
                                    "enum": [
                                        "relative",
                                        "column_end",
                                        "notebook_end",
                                    ],
                                },
                                "cellId": {"type": "string"},
                                "columnIndex": {"type": "number"},
                                "before": {"type": "boolean"},
                            },
                            "required": ["type"],
                            "additionalProperties": False,
                        },
                    },
                    "required": ["type", "position"],
                    "additionalProperties": False,
                }
            },

However, the google tools spec is still quite restrictive, even with the cleaned up edit notebook tool. So I implemented a thin wrapper inspired by #7211 on the backend to make sure schemas are compliant.

🔍 Description of Changes

📋 Checklist

  • I have read the contributor guidelines.
  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • I have added tests for the changes made.
  • I have run the code and verified that it works as expected.
@vercel
Copy link

vercel bot commented Nov 20, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
marimo-docs Ready Ready Preview Comment Nov 21, 2025 6:57pm
@Light2Dark Light2Dark changed the title simplify edit notebook tool and add Nov 20, 2025
@Light2Dark Light2Dark force-pushed the sham/simplify-edit-notebook-tool branch from 2ca82a1 to 74ee2aa Compare November 21, 2025 16:12
@Light2Dark Light2Dark added the bug Something isn't working label Nov 21, 2025
@Light2Dark Light2Dark marked this pull request as ready for review November 21, 2025 16:59
@Light2Dark Light2Dark requested a review from manzt as a code owner November 21, 2025 16:59
"properties": tool.parameters.get("properties", {}),
"required": tool.parameters.get("required", []),
},
"parameters": _clean_google_parameters(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be great to enforce this at build/test time instead of at runtime

Copy link
Contributor Author

@Light2Dark Light2Dark Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah.., because it's a frontend tool, I'm not sure how we can test the zod schema against this. Do you have ideas?

Another option is to review the source code for gemini tools to only include allowed keys.
edit: I can check this

mscolnick
mscolnick previously approved these changes Nov 21, 2025
## 📝 Summary

<!--
Provide a concise summary of what this pull request is addressing.

If this PR fixes any issues, list them here by number (e.g., Fixes
#123).
-->

## 🔍 Description of Changes

<!--
Detail the specific changes made in this pull request. Explain the
problem addressed and how it was resolved. If applicable, provide before
and after comparisons, screenshots, or any relevant details to help
reviewers understand the changes easily.
-->

## 📋 Checklist

- [x] I have read the [contributor
guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md).
- [ ] For large changes, or changes that affect the public API: this
change was discussed or approved through an issue, on
[Discord](https://marimo.io/discord?ref=pr), or the community
[discussions](https://github.com/marimo-team/marimo/discussions) (Please
provide a link if applicable).
- [x] I have added tests for the changes made.
- [x] I have run the code and verified that it works as expected.
@mscolnick mscolnick merged commit 1fe8539 into main Nov 21, 2025
33 of 41 checks passed
@mscolnick mscolnick deleted the sham/simplify-edit-notebook-tool branch November 21, 2025 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

3 participants