You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ofbiz.apache.org by "Anil K Patel (Jira)" <ji...@apache.org> on 2026/06/03 16:15:00 UTC
[jira] [Created] (OFBIZ-13432) AI Plugin: Structured output — typed Map result from agentRun
Anil K Patel created OFBIZ-13432:
------------------------------------
Summary: AI Plugin: Structured output — typed Map result from agentRun
Key: OFBIZ-13432
URL: https://issues.apache.org/jira/browse/OFBIZ-13432
Project: OFBiz
Issue Type: Sub-task
Reporter: Anil K Patel
h2. Summary
Allow an AI agent to return a typed, schema-validated Map instead of free text. When an agent definition carries a {{responseSchema}} (a JSON Schema), {{agentRun}} populates a {{structuredResult}} OUT parameter that callers can use directly in OFBiz service chains without string parsing.
h2. Motivation
The current {{agentRun}} service always returns an {{assistantMessage}} string. This is useful for conversational flows but is a barrier for integration use cases:
- An MRP advisor that returns {{recommendedQuantity}}, {{supplierId}}, and {{urgency}} as a typed Map can feed directly into a purchase-order creation service
- A document extractor that returns structured fields can populate entity records without a parsing step
- A classification agent that returns a category code can be used as a routing condition in a service group
Free-text output requires the caller to parse and validate the LLM's response, which is fragile. Structured output moves that contract into the agent definition where it belongs.
h2. Design
h3. Agent definition
{{responseSchema}} is added to {{AiAgentDef}} as an optional {{very-long}} field containing a JSON Schema string:
{code:json}
{
"type": "object",
"properties": {
"recommendedQuantity": {"type": "integer"},
"supplierId": {"type": "string"},
"urgency": {"type": "string", "enum": ["low", "medium", "high"]}
},
"required": ["recommendedQuantity", "supplierId", "urgency"]
}
{code}
When {{responseSchema}} is absent, behaviour is identical to today.
h3. Service change
{{agentRun}} gains one optional OUT parameter:
{code}
agentRun(...) OUT: assistantMessage (unchanged), structuredResult (Map, optional)
{code}
When {{responseSchema}} is set, {{structuredResult}} is populated and {{assistantMessage}} carries the raw JSON string. When absent, {{structuredResult}} is null and {{assistantMessage}} is free text as today.
h3. Provider handling
- *OpenAI*: {{response_format: {type: "json_schema", json_schema: {name, schema, strict: true}}}} added to the request. Response is free text that is valid JSON — parsed into the result Map.
- *Anthropic*: a synthetic {{structured_output}} tool is injected with the schema. The agent is forced to call it on the final turn. The tool's {{input}} Map becomes the result.
h3. Admin screen
The Edit Agent screen gains a {{responseSchema}} textarea so administrators can set or clear the schema without touching code.
h2. What does NOT change
- Agents without {{responseSchema}} behave identically to today
- {{agentRun}} service signature is additive — existing callers are unaffected
- Tool dispatch, approval gate, and conversation memory are unchanged
h2. Acceptance criteria
- An agent with {{responseSchema}} set returns a populated {{structuredResult}} Map from {{agentRun}}
- An agent without {{responseSchema}} returns {{null}} for {{structuredResult}} and free text in {{assistantMessage}} as before
- Works correctly on both OpenAI and Anthropic providers
- Edit Agent screen shows the {{responseSchema}} textarea
- {{./gradlew classes}} and {{./gradlew checkstyleMain}} pass
h2. Development branch
[patelanil/ofbiz-plugins — feature/ai-plugin|https://github.com/patelanil/ofbiz-plugins/tree/feature/ai-plugin]
--
This message was sent by Atlassian Jira
(v8.20.10#820010)