Skip to content

Extract lists of objects with nested fields - #5

Merged
Juanpe merged 2 commits into
mainfrom
feat/nested-object-fields
Oct 28, 2026
Merged

Juanpe merged 2 commits into
mainfrom
feat/nested-object-fields

Conversation

@Juanpe

@Juanpe Juanpe commented Oct 28, 2026

Copy link
Copy Markdown
Owner

🎯 What

Adds Field.Kind.object([Field]), so extract steps and tool parameters can ask for records, such as .list(.object([...])) for the lines of an order. Each object reads as a dictionary.

🤔 Why

Turning free text into actions over app state ("two beers, no cola") needs a list of records with several fields each. With text, number, bool, choice and list only, a host had to flatten records into parallel lists or JSON text.

While nesting, a latent schema bug showed up: AnyLanguageModel stores named nodes (objects and choices) as shared $defs keyed by name, and a later node with the same name silently replaces the earlier one. Nested fields repeat names often (kind, name), and a tool named like one of its choice parameters already hit it. SchemaBuilder now gives each named node its own name (kind, kind2, …).

🧪 How it was tested

  • NestedFieldTests: an extract step returning a list of objects through ScriptedModel; repeated names keep separate definitions in the encoded schema; empty objects and duplicate nested names are preflight issues; workflows with objects round-trip as JSON.
  • New opt-in LiveAppleTests.onDeviceModelExtractsListsOfObjects: Apple's on-device model fills .list(.object(...)) correctly on macOS 27 (RELAY_LIVE=1), so nested $defs survive the Foundation Models bridge.
  • Full suite (292 tests), make check-style, make check-skill, and an iOS build of the four libraries.

✅ Checklist

  • make format and make check-style pass.
  • env -u RELAY_LIVE swift test -Xswiftc -warnings-as-errors passes.
  • Behavior is tested through ScriptedModel / StubProtocol, without live services or keys.
  • Public API changes are documented, and the relevant guide is updated.
  • User-facing changes are in CHANGELOG.md under Unreleased.
  • Breaking changes (API, behavior, Codable or platform) are called out with a migration.
  • No credentials, private data or prompts with user content in code, fixtures or logs.

📣 Notes for review

  • Additive, but not for exhaustive switches: a new case in the public Field.Kind breaks host code that switches over it without default. Pre-1.0, this ships in a minor release.
  • Codable: existing workflow JSON decodes unchanged; .object encodes like the other cases.
  • Schema names: names only change when they would collide, so existing schemas keep theirs.
  • Validation: field checks moved into Field+Validation.swift (schemaProblems), which shortens validationIssues. Its function_body_length baseline entry goes from 107 to 94 lines, and the stale SchemaBuilder entry is removed.
  • Follow-up: MCP input schemas still read object properties as JSON text; they could map to .object next.

Field.Kind.object groups fields, so extract steps and tool parameters can
ask for records such as the lines of an order. Each named schema node now
gets its own name, since repeated names replaced each other's definitions.
@Juanpe Juanpe mentioned this pull request Oct 28, 2026
7 tasks done
@Juanpe
Juanpe added this pull request to stack #7 October 28, 2026 12:01
@Juanpe
Juanpe merged commit 3c80b56 into main Oct 28, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant