feat(go/ai): support middleware in dotprompt frontmatter#5229
Merged
Conversation
Wire the dotprompt `use:` field through the Go prompt loader so middleware references travel from frontmatter to runtime execution, mirroring the JS implementation. Entries may be a bare middleware name or a map with `name` and optional `config`. References are carried through `configsToRefs` via an unexported `middlewareRefArg` adapter that is stripped before reaching `resolveRefs`, routing resolution through the registry (rather than the in-process fast path) so config payloads propagate untouched.
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces support for lazy middleware references in dotprompt frontmatter, allowing middleware to be resolved via the registry. It includes the necessary internal types, parsing logic, and comprehensive test coverage. I have provided a suggestion to simplify the error handling in prompt.go by removing redundant error wrapping.
MichaelDoyle
approved these changes
May 5, 2026
Contributor
MichaelDoyle
left a comment
There was a problem hiding this comment.
I have't verified in the Dev UI yet, but this matches what I expect.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds Go runtime support for the dotprompt
use:frontmatter field, mirroring the JS-side work in #5223. Each entry may be a bare middleware name or a map withnameand optionalconfig, matching the TypeScript shape.The references travel through
[]Middlewarevia an unexportedmiddlewareRefArgadapter, whichconfigsToRefsstrips before constructing theMiddlewareRef. This routes resolution through the registry-lookup path rather than the in-process fast path used for Go-defined middleware, so JSON-shaped configs from YAML propagate untouched.Errors surface at load time for malformed input (non-list
use:, missingname, empty entries) and at execute time for names that do not resolve in the registry.Checklist:
go/ai/middleware_test.goandgo/ai/prompt_test.gocovering the parser, the lazy adapter, end-to-end load + execute, unregistered names, and invalid shapes)