pub struct AddToolInputExamplesMiddleware { /* private fields */ }Expand description
Middleware that serializes tool.input_examples (if any) and appends them
to the tool’s description field.
Default layout mirrors @ai-sdk/ai/src/middleware/add-tool-input-examples-middleware.ts:
"{description}\n\n{prefix}\n{example_1}\n{example_2}..." where prefix
defaults to "Input Examples:" and each example is JSON.stringify(example.input)
(no enumeration prefix). Override with Self::with_prefix to customise
the header line or Self::with_formatter to take full control.
Implementations§
Source§impl AddToolInputExamplesMiddleware
impl AddToolInputExamplesMiddleware
Sourcepub fn new() -> Self
pub fn new() -> Self
Build with the upstream-aligned defaults.
The default prefix is "Input Examples:" and the default remove is
true, matching upstream add-tool-input-examples-middleware.ts so the
rewritten tool no longer carries the now-redundant input_examples
field on the wire.
Sourcepub fn with_prefix(self, prefix: impl Into<String>) -> Self
pub fn with_prefix(self, prefix: impl Into<String>) -> Self
Override the header line prepended before the serialized examples.
Mirrors upstream prefix option (default "Input Examples:").
Sourcepub fn with_formatter<F>(self, formatter: F) -> Self
pub fn with_formatter<F>(self, formatter: F) -> Self
Override how each example is rendered. The formatter receives the
example and its zero-based index, mirroring upstream
(example, index) => string
(@ai-sdk/ai/src/middleware/add-tool-input-examples-middleware.ts:46).
Sourcepub fn with_remove(self, remove: bool) -> Self
pub fn with_remove(self, remove: bool) -> Self
Toggle whether input_examples is cleared after being appended.
Mirrors upstream remove?: boolean option (default true). When
true, the rewritten function tool drops its input_examples so the
downstream provider does not re-serialize them on the wire after they
have already been folded into description. Set to false to keep
the structured field alongside the textual description.