AI Task for generating structured Data #1216
|
2025-04-01: Initial proposal using selectors as the schema BackgroundHome Assistant LLMs can call tools by returning structured responses conforming to a specific set of commands. Additionally, this can be extended to support structured conversation outputs. ProposalExtend AI Tasks #1237 to accept an input schema and APIs to allow an AI task entity to generate a response with an object conforming to that structure. Use casesUsers today can only prompt the model to output simple strings or number values, but instead they could:
Solution OverviewThe big picture shape of the solution is:
Solution DetailsAPIasync def async_generate_data(
hass: HomeAssistant,
*,
task_name: str,
entity_id: str | None = None, # Optional, will use preferred entity if set
prompt: str,
structure: dict[str, Any],
) -> GenDataTaskResult:Both will end up calling the entity method async def _async_generate_data(
self,
task: GenDataTask,
chat_log: ChatLog,
) -> GenTextTaskResult:Input schema format
prompt: |-
Please generate some mock user profiles with a name and age in structured response.
Examples:
Name: John Smith, Age: 30, Aliases: Johnny
Name: Alice Parker, Age: 54
structure:
profile:
object:
multiple: true
fields:
name:
description: Full name of the user
selector:
text:
age:
description: Age of the user
selector:
number:
aliases:
description: Additional nicknames for the user
selector:
text:
multiple: true
conversation_id: 8A8E3C8F288A41DBBB12073F6C
data:
profile:
- name: Emily Chen
age: 42
- name: David Rodriguez
age: 30
- name: Benjamin Lee
age: 38
aliases:
- Ben
- BennySelectors now support nested objects fields so we are not limited in what we can describe. However, if we are limited in the future we can extend selectors to support that type. Selectors are primarily used for rendering select UI in the frontend, however, that functionality is not used here. They are only used for defining a voluptuous schema internally. We already have a decided on our approach for how integrations convert between vol schemas and openapi schemas for tool formats, and this will not be revisited for structured outputs and can all be reused. (See We could also decide to explicitly limit to the basic types only. The models of @dataclass(slots=True)
class GenDataTask:
"""Generate structured data task to be processed."""
type: GenTextTaskType
"""Type of the task."""
prompt: str
"""Prompt for the AI."""
structure: dict[str, Any]
"""Response output structure in JSON schema format."""
@dataclass(slots=True)
class GenDataTaskResult:
"""Result of Gen Data task."""
conversation_id: str
"""Unique identifier for the conversation."""
data: dict[str, Any]
"""Generated data following the input structure."""Future workFuture work that will make AI Gen Data Tasks much more useful:
Alternatives
prompt: |-
Please generate a mock user profile with a name and age in structured response.
Examples:
Name: John Smith, Age: 30, Aliases: Johnny
Name: Alice Parker, Age: 54
structure:
type: object
properties:
name:
type: string
description: Full name of the user
age:
type: number
description: Age of the user
aliases:
type: array
description: Additional nicknames for the user
items:
type: string
conversation_id: 8A8E3C8F288A41DBBB12073F6C
data:
name: Emily Chen
age: 42
Integrations supportedThis feature can be supported by all the major LLM conversation agents
|
Replies: 2 comments 2 replies
|
So thinking a bit more on this, and also discussing with Allen offline about upcoming LLM tasks*, I wonder if structured outputs should be a feature solely added to LLM tasks and not be part of (The idea of LLM tasks (architecture proposal TBD) provide a way to use conversation agents for general purpose tasks outside of an assistant pipeline (e.g. use for summarization in the frontend). This uses a conversation agent LLM for general use, without user prompts or customizations.) |
|
The proposal was approved in the core meeting July 3rd |
The proposal was approved in the core meeting July 3rd