Commit 1fe8539
authored
simplify edit notebook tool and add google tool schema cleanup (#7228)
## 📝 Summary
The motivation to clean up the edit notebook tool is that discriminated
unions are more verbose in context size:
<details>
<summary>tool schema parameters with discriminated union</summary>
```json
"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,
},
]
}
},
```
</details>
<details>
<summary>after simplifying</summary>
```json
"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,
}
},
```
</details>
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.
<!--
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.1 parent df841e2 commit 1fe8539
File tree
6 files changed
+349
-66
lines changed- frontend/src/core
- ai/tools
- __tests__
- config
- marimo/_ai
- tests/_ai
6 files changed
+349
-66
lines changedLines changed: 156 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
| 131 | + | |
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
| 157 | + | |
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | | - | |
| 191 | + | |
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
204 | | - | |
| 204 | + | |
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
| |||
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
228 | | - | |
| 228 | + | |
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
236 | 281 | | |
237 | 282 | | |
238 | 283 | | |
| |||
404 | 449 | | |
405 | 450 | | |
406 | 451 | | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
407 | 532 | | |
408 | 533 | | |
409 | 534 | | |
| |||
423 | 548 | | |
424 | 549 | | |
425 | 550 | | |
426 | | - | |
| 551 | + | |
427 | 552 | | |
428 | 553 | | |
429 | 554 | | |
| |||
453 | 578 | | |
454 | 579 | | |
455 | 580 | | |
456 | | - | |
| 581 | + | |
457 | 582 | | |
458 | 583 | | |
459 | 584 | | |
| |||
476 | 601 | | |
477 | 602 | | |
478 | 603 | | |
479 | | - | |
| 604 | + | |
480 | 605 | | |
481 | 606 | | |
482 | 607 | | |
483 | 608 | | |
484 | 609 | | |
485 | 610 | | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
486 | 632 | | |
487 | 633 | | |
488 | 634 | | |
| |||
508 | 654 | | |
509 | 655 | | |
510 | 656 | | |
511 | | - | |
| 657 | + | |
512 | 658 | | |
513 | 659 | | |
514 | 660 | | |
| |||
521 | 667 | | |
522 | 668 | | |
523 | 669 | | |
524 | | - | |
| 670 | + | |
525 | 671 | | |
526 | 672 | | |
527 | 673 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
7 | 12 | | |
8 | 13 | | |
9 | 14 | | |
| |||
87 | 92 | | |
88 | 93 | | |
89 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
90 | 124 | | |
0 commit comments