Skip to content

API Reference parrot.bots.mixins.infographic_authoring

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.bots.mixins.infographic_authoring

View source

InfographicAuthoringMixin — tier-1 infographic authoring for agents (FEAT-326).

A cooperative mixin (same pattern as :class:~parrot.bots.mixins.model_switching.ModelSwitchingMixin) composable onto :class:~parrot.bots.data.PandasAgent — or any DatasetManager-bearing agent — that wires a pre-configured :class:InfographicToolkit into the agent and adds the tier-1 authoring API::

class MyAgent(InfographicAuthoringMixin, PandasAgent):
    ...

agent = MyAgent(name="reporter", artifact_store=store, template_dirs=[...])

Tier 1 (generate_infographic) builds a one-shot infographic from ad-hoc data and returns a :class:ProvenanceDescriptor that records datasets/params/section mapping and snapshot timestamps — but never the python code used to build it (resolved brainstorm decision; spec §2 / §5). Tier 2 (publish_recipe) is added by TASK-1885.

Alias CreateSurface

Re-exported from parrot.outputs.a2ui.models.CreateSurface.

Alias DataSourceSpec

Re-exported from parrot.outputs.a2ui.recipes.models.DataSourceSpec.

Alias GapReport

Re-exported from parrot.tools.infographic_sections.GapReport.

Class InfographicAuthoringMixin

Cooperative mixin adding infographic authoring to a data agent.

Mix in before the agent class so the MRO reaches this class first::

class MyAgent(InfographicAuthoringMixin, PandasAgent): ...

Constructor kwargs (all optional; popped before the cooperative super().__init__ chain): infographic_toolkit: A pre-built :class:InfographicToolkit to wire in. artifact_store: Used to build an :class:InfographicToolkit when infographic_toolkit is not supplied. recipe_store: Optional recipe store forwarded to the built toolkit (enables tier-2 publish_recipe + the toolkit's recipe tools). template_dirs: Optional template directory(ies) forwarded to the built toolkit (the data-splice template registry).

Parameter Type Default Description
*args Any ()
infographic_toolkit Optional[InfographicToolkit] None
artifact_store Optional[Any] None
recipe_store Optional[Any] None
template_dirs Optional[Any] None
**kwargs Any {}

Method InfographicAuthoringMixin.configure

Re-bind the toolkit (prompt guidance) before base configuration.

InfographicToolkit.set_bot appends its usage guidance to the bot's system_prompt_template; it must run BEFORE the base configure() finalises the prompt. Cooperative: chains super().configure().

configure(*args: Any, **kwargs: Any) -> None

Parameter Type Default Description
*args Any ()
**kwargs Any {}

Method InfographicAuthoringMixin.generate_infographic

Build a one-shot (tier-1) infographic from the section descriptor.

Flow (spec §2): coerce descriptor → fail-fast validation gate → build per-section data → render via the toolkit (data-splice or Jinja per descriptor.mode) → persist → return the render result plus a :class:ProvenanceDescriptor (datasets/params/mapping + snapshot timestamps — NO python code).

generate_infographic(template: str, descriptor: 'SectionDescriptor | str', params: Optional[dict] = None) -> Tuple[InfographicRenderResult, ProvenanceDescriptor]

Parameter Type Default Description
template str Registered template name to render (should match descriptor.template).
descriptor 'SectionDescriptor | str' A :class:SectionDescriptor or its JSON string.
params Optional[dict] None Optional parameters (e.g. {"title": "...", ...}).

Returns: Tuple[InfographicRenderResult, ProvenanceDescriptor] — (InfographicRenderResult, ProvenanceDescriptor).

Raises:

  • InfographicValidationError — When the descriptor's datasets/columns are unmet — raised BEFORE any build/render/persist.
  • RuntimeError — When no toolkit or DatasetManager is wired.

Method InfographicAuthoringMixin.publish_recipe

Publish a descriptor as a deterministic FEAT-324 recipe (tier 2).

Maps each descriptor section onto a registered transformer as a :class:TransformStep. Full coverage → build and save an :class:InfographicRecipe carrying the section_descriptor and a :class:RenderSpec with the supplied delivery config. ANY unmapped section → return a :class:GapReport (with a human-registerable suggested_source per gap) and save nothing (spec G1: never store or execute code).

Section → transformer resolution uses the section's name, normalised to a Python identifier, as the registry key.

FEAT-420: when descriptor.layout is set, it is used VERBATIM as the saved recipe's layout instead of the template-based LayoutSpec below; absent means unchanged legacy behaviour. descriptor.narrative (if declared) is always carried through to the saved recipe.

publish_recipe(name: str, descriptor: 'SectionDescriptor | str', owner: Optional[str] = None, delivery: Optional[dict] = None, overwrite: bool = False) -> Union[InfographicRecipe, GapReport]

Parameter Type Default Description
name str Recipe name (scoped by owner).
descriptor 'SectionDescriptor | str' A :class:SectionDescriptor or its JSON string.
owner Optional[str] None Recipe owner scope.
delivery Optional[dict] None Optional delivery config → RenderSpec.delivery.
overwrite bool False Replace an existing (name, owner) recipe. When False, a collision raises.

Returns: Union[InfographicRecipe, GapReport] — The saved :class:InfographicRecipe, or a :class:GapReport when coverage is partial.

Raises:

  • ValueError — On a (name, owner) collision when overwrite is False.
  • RuntimeError — When no recipe store is wired.

Method InfographicAuthoringMixin.publish_surface

Validate + persist a surface to the ui_surfaces plane (FEAT-492 G4).

Programmatic sibling of :meth:publish_recipe, for persisting a rehydratable A2UI surface (dashboard/infographic/widget) so it can be fetched later via GET /api/v1/ui/surfaces/{surface_id} (TASK-2702) — independent of whether recipe_name is set (a recipe-backed surface is additionally refreshable; a one-shot surface is not).

publish_surface(*, kind: str, title: str, envelope: CreateSurface | dict, recipe_name: str | None = None, recipe_owner: str | None = None, recipe_params: dict | None = None, overwrite: bool = False, surface_store: Any = None, user_id: str | None = None, session_id: str | None = None) -> str

Parameter Type Default Description
kind str One of "dashboard", "infographic", "widget" (UISurfaceKind — validated by the store's row model).
title str Human-readable surface title.
envelope CreateSurface | dict A :class:CreateSurface instance, or its dict dump — either is accepted and coerced via CreateSurface.model_validate.
recipe_name str | None None When set, the surface is refreshable — stored as its recipe_ref for POST .../refresh (TASK-2702) to replay via RecipeRunner.
recipe_owner str | None None Owner scope the recipe was saved under (must match publish_recipe's owner, when applicable).
recipe_params dict | None None Params snapshot used to produce this envelope — the refresh lane's "stored" precedence tier.
overwrite bool False Replace an existing surface_id row. When False (default), a collision raises ValueError (store semantics).
surface_store Any None Injection seam (spec §8) — an explicit PgUISurfaceStore-shaped store. Takes precedence over a self._surface_store attribute the hosting bot may carry, which in turn takes precedence over lazily importing the default PgUISurfaceStore from ai-parrot-server (core MUST NOT import server code at module level — one-way import rule).
user_id str | None None Attributed owner of the row. Falls back to self.user_id (when the hosting bot carries one) and finally to the resolved agent_id (self-authored surface, never invented from nothing) — see the Completion Note for TASK-2704's resolution of this injection seam.
session_id str | None None Optional originating session, attached verbatim.

Returns: str — The persisted surface_id.

Raises:

  • ValueError — On a surface_id collision when overwrite is False (propagated from the store).
  • RuntimeError — When no store is injected/wired AND ai-parrot-server is not installed — an actionable message, never a bare ModuleNotFoundError.
  • LinkedGuardRequired — A linked envelope with no data-plane guard configured — fails CLOSED; nothing is saved (FEAT-598 AC14).
  • AuthorizationRequired — The owner is not permitted one of the envelope's data sources; nothing is saved.
  • CatalogValidationError — The linked envelope fails structural validation; nothing is saved.
  • SnapshotError — The save-time snapshot could not be produced; nothing is saved.

Alias InfographicRecipe

Re-exported from parrot.outputs.a2ui.recipes.models.InfographicRecipe.

Alias InfographicRenderResult

Re-exported from parrot.tools.infographic_toolkit.InfographicRenderResult.

Alias InfographicToolkit

Re-exported from parrot.tools.infographic_toolkit.InfographicToolkit.

Alias InfographicValidationError

Re-exported from parrot.tools.infographic_toolkit.InfographicValidationError.

Alias LayoutSpec

Re-exported from parrot.outputs.a2ui.recipes.models.LayoutSpec.

Alias ProvenanceDescriptor

Re-exported from parrot.tools.infographic_sections.ProvenanceDescriptor.

Alias RecipeNotFoundError

Re-exported from parrot.outputs.a2ui.recipes.store.RecipeNotFoundError.

Alias RenderSpec

Re-exported from parrot.outputs.a2ui.recipes.models.RenderSpec.

Alias SectionDescriptor

Re-exported from parrot.tools.infographic_sections.SectionDescriptor.

Alias SectionSpec

Re-exported from parrot.tools.infographic_sections.SectionSpec.

Alias TransformStep

Re-exported from parrot.outputs.a2ui.recipes.models.TransformStep.

Alias TransformerGap

Re-exported from parrot.tools.infographic_sections.TransformerGap.

Alias build_principal_context

Re-exported from parrot.auth.permission.build_principal_context.

Alias has_data_sources

Re-exported from parrot.outputs.a2ui.linked.has_data_sources.

Attribute logger

Alias transformer_registry

Re-exported from parrot.outputs.a2ui.recipes.transformers.transformer_registry.

Alias validate_descriptor_datasets

Re-exported from parrot.tools.infographic_sections.validate_descriptor_datasets.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally