Configuring Output JSON Format
This feature is only available on Activity and Chat Completion agents.
The output JSON format allows us to specify which format we want for an agent response. For instance, if our prompt instructs the agent to give us a recipe, we can specify the output format to be:
{
"ingredients": [
"ingredient1",
"ingredient2",
...
],
"preparation-steps": [
"step1",
"step2",
...
]
}
This guide explains how to configure the output JSON format for activity or chat completion agents in Serenity* Star. This allows you to control the agent's response format to interact seamlessly with other systems.
Setting Up Output JSON Format
Let's see how to set output JSON format to an existing agent using the Agent Designer.
-
Visit Serenity* Star Dashboard and click on the "AI Agents" button in the sidebar.
-
Filter by agent type and choose an agent you want to edit. In this case, we are filtering by activity agents.
-
Click on the edit button in the right corner to open the agent designer.
-
Once in the Agent Designer, search for the "Output JSON format" section within the "General" tab.
-
Add your expected output format. Here's an example using the JSON defined before:
-
Use the preview pane on the right to execute the agent and test the response format.
Recommended Vendors
To get the best results, consider using the following vendors:
- Groq
- OpenAI
- Together
Other vendors like Mistral and Anthropic also have models capable of returning formatted responses, though performance may vary.
Agent Response Management
JSON Formatted response feature is available in Recommended vendors listed above. While Groq and OpenAI ensure that the response is formatted in all their models, Together only ensures it for a few of them.
Models from Mistral and Anthropic are also capable to return a formatted response but schema wont be validated and response may not be formatted.
To ensure that the models can return a formatted response, you cannot use the "Stream Feature" that allows for the real-time display of text as it is being generated.
Error Handling
When an agent fails to respond with the specified format, the response will be empty. This ensures that systems relying on structured data are not disrupted by malformed responses.
If we execute the agent through the API, the received message can be displayed in the "generatedJson" field.
{
"code": "ERR_BAD_REQUEST",
"response-steps": {
"data": {
"errors": {
"generatedJson": "..."
},
},
},
}