Skip to content

feat(ai-agents): support custom structured output schemas for AI Agent responses#3186

Merged
asastre merged 7 commits intomasterfrom
ai-agents/display-flow-builder-content
Mar 23, 2026
Merged

feat(ai-agents): support custom structured output schemas for AI Agent responses#3186
asastre merged 7 commits intomasterfrom
ai-agents/display-flow-builder-content

Conversation

@asastre
Copy link
Copy Markdown
Contributor

@asastre asastre commented Mar 17, 2026

Description

Allow the AI Agent to return custom structured output message types beyond the built-in ones (text, carousel, etc.). This enables the Flow Builder plugin to instruct the AI Agent to respond with a specific Flow Builder content ID, which is then resolved into its full content with all follow-ups.

Context

Currently, the AI Agent can only return a fixed set of message types. There are scenarios where the AI Agent needs to respond by referencing existing Flow Builder content (e.g. a specific node in the flow) instead of generating a free-form response. This PR makes the output schema extensible so that each consumer can inject its own message types.

Approach taken / Explain the design

1. Generic core interfaces (botonic-core)

  • Made BaseMessage, OutputMessage, AgenticOutputMessage, RunResult, and InferenceResponse generic with an Extra type parameter, so they can carry additional message types while remaining backward-compatible (defaults to never).
  • Added outputMessagesSchemas to AiAgentArgs to pass extra Zod schemas to the agent.

2. Dynamic output schema (botonic-plugin-ai-agents)

  • Extracted base message schemas into a constant array and introduced getOutputSchema(externalSchemas) that merges them with any externally provided Zod schemas at runtime.
  • AIAgentBuilder now receives and forwards outputMessagesSchemas.

3. Flow Builder content message (botonic-plugin-flow-builder)

  • Created FlowBuilderContentMessage type and its corresponding FlowBuilderContentSchema Zod object, representing a message with a contentId pointing to a Flow Builder node.
  • Updated getContentsByAiAgent to:
    • Pass FlowBuilderContentSchema to the AI Agent plugin.
    • Separate the AI Agent response into regular messages and flowBuilderContent messages.
    • Resolve each flowBuilderContent message by fetching the referenced node from the CMS and returning its full contents.

To document / Usage example

To add a custom output message type, define a Zod schema and pass it in outputMessagesSchemas:

const MyCustomSchema = z.object({
  type: z.enum(['myCustomType']),
  someField: z.string(),
})

// When calling the AI Agent plugin
aiAgentArgs.outputMessagesSchemas = [MyCustomSchema]

The AI Agent will then be able to return messages of that type alongside the built-in ones.

As for the new FlowBuilderContentSchema, in the AI Agent prompt you could do something like this:
"If the user is asking for the status of an order, display the Flow Builder content 'OPEN_WISMO_WEBVIEW'"

This will result in the AI Agent returning as a response the contents of the Flow Builder content ID OPEN_WISMO_WEBVIEW directly.

Testing

The pull request has unit tests.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@asastre asastre force-pushed the ai-agents/display-flow-builder-content branch from f6ee699 to 88a52ee Compare March 18, 2026 12:35
@github-actions
Copy link
Copy Markdown

Test Results

42 tests   42 ✅  1m 21s ⏱️
 5 suites   0 💤
 1 files     0 ❌

Results for commit 88a52ee.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it would be simpler to declare the ZOD schema within the plugin-ai-agent, just like the other schemas. You’d save yourself all the logic in the plugin-flow-builder when declaring the schema (this is the only one here). You’d also avoid all the logic within the plugin-ai-agent for fetching external schemas and type inference.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree, but doing that you would both plugins would be coupled and I don't think it's a good idea...

Also, doing it the way it is done we allow the bots to add other possible schemas more specific for its use cases, expanding the possibilities of the AI Agents. If we add this new schema in the AI Agent's plugin we will lose this improvement.

As a summary, I would leave it as it is now to expand the possibilities of the AI Agents plugin.

@asastre asastre force-pushed the ai-agents/display-flow-builder-content branch from 0c3f993 to bab2e9d Compare March 20, 2026 15:30
private name: string
private instructions: string
private tools: Tool<TPlugins, TExtraData>[]
private externalOutputMessagesSchemas: z.ZodObject<any>[]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

then should this get typed as z.ZodObject<OutputSchema[]>?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think so because it won't contain any of the baseMessageSchemas.

…from AI Agent (#3188)

## Description
Add a new target attribute in the textWithButtons output schema in the
AI Agent plugin and make them reach the render of the FlowButton in Flow
Builder plugin so an URL button can open the link within the same window
if stated in the AI Agent prompt.

## Context
Through the AI Agent prompt there was no way to make a URL button to
open the website within the same window as the webchat.

## Testing

The pull request has unit tests.
@asastre asastre merged commit 94563be into master Mar 23, 2026
6 checks passed
@asastre asastre deleted the ai-agents/display-flow-builder-content branch March 23, 2026 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants