Skip to content

Refinement

Refinement lets an app route change requests against generated artifacts. It is optional. Most CRUD apps, fixed workflow apps, and simple assistants only need app/config/ai.json.

Use refinement when the app needs routed revisions, scoped artifact patches, checkpoint decisions, or workflow re-entry based on request meaning.

Files

File Owns
app/config/refinement_policy.yaml Enables refinement capabilities and selects model profiles.
refinement_harness/config/harness.yaml Optional app-local overlay over mozaiks.default_refinement_harness.
refinement_harness/config/tools.yaml Optional app-specific tool delta. Default tools come from OSS.
refinement_harness/prompts/*.yaml Optional app-specific prompt overrides. Default prompts come from OSS.
workflows/extended_orchestration/extension_registry.json Workflow sequences that the effective harness can route into.

Minimal Policy

schema_version: mozaiks.refinement.policy.v1
enabled: true

llm_profiles:
  classifier:
    purpose: Classify refinement requests into stable change classes.
    expected_behavior: deterministic structured classification
    llm_config:
      api_type: openai
      model: gpt-5-nano
  codegen:
    purpose: Generate scoped code or artifact patches.
    expected_behavior: deterministic code and artifact generation
    llm_config:
      api_type: openai
      model: gpt-5.2-codex
      temperature: 0.1

classifier:
  enabled: true
  llm_profile: classifier
coding:
  enabled: true
  llm_profile: codegen

Model parameters belong inside each profile's llm_config. For models that support temperature, use llm_config.temperature. Profile fields are strict: purpose, expected_behavior, and llm_config. The unused default_temperature field is rejected. Every enabled capability must name a declared profile with a non-empty model; inline capability llm_config and unknown capability fields are rejected when the policy loads.

Studio AI models

Open AI models in the Studio workspace navigation to set the default and allowed models for new Factory builds and refinements. This requires a signed-in workspace administrator. Configure provider keys in the workspace secret policy before enabling them. Studio displays provider availability without returning key values.

Factory prefers Gemini 3.8 Flash. A workspace with only an allowed OpenAI key can start builds with GPT-5 Nano. Choose a model when starting an app build. The chat composer shows the model attached to an active build. In App Review, use the dropdown inside the composer, below the message text and beside Send, to choose the model for a new refinement. Studio saves the choice with the run so routed workflows and approval continue with that model.

For file-based configuration, model_override: gemini or model_override: openai in app/config/refinement_policy.yaml supplies the initial Studio default and selects the refinement engine's structured checkpoint model when no per-run choice exists. Without an override, the declared capability profiles apply to engine calls without a selection. ACP coding and media generation use their separate provider configuration.

Model profiles and coding agents

llm_profiles configures AG2 structured-output calls. A profile name describes the work; its llm_config.model selects the model for that call.

Use a flat llm_config with model and optional api_type. Enabled refinement profiles reject config_list because AG2 would select its first entry instead of the declared flat model.

The first-party policy uses these profiles:

Refinement step Profile What it does
Classify request classifier Chooses the refinement change class.
Select file scope and contract surfaces impact_analyzer Plans the bounded work.
Write a structured patch codegen Produces proposed patch content through AG2.
Regenerate a selected contract surface codegen by default Produces proposed surface files through AG2.

The policy names the two contract-surface steps separately:

contract_surface:
  enabled: true
  llm_profile: impact_analyzer
  regeneration_llm_profile: codegen

llm_profile selects affected surfaces. regeneration_llm_profile selects the file-generation model and must resolve to a declared profile with a non-empty model before regeneration starts. To tune generation independently, declare a surface_regeneration profile and reference it here. This works even when structured patch coding is disabled.

coding.providers.acp.adapter is a separate execution choice. For example, adapter: claude_code starts the Claude Code ACP agent when ACP is enabled and eligible; it does not turn llm_profiles.codegen.llm_config.model into a Claude model. That model is used for structured-output patch coding and for a permitted fallback after an ACP attempt. The current app-bundle ACP adapter uses its coding CLI's default model; ACP model selection is independent of this profile.

The architecture profile is currently an advisory workflow-context label; workflow execution does not resolve its model from this policy yet. planner_replanner and reviewer_validator currently describe optional dry-run plan roles, rather than separate live model calls. The first-party policy leaves them undeclared.

Optional ACP coding provider

The ACP coding provider remains disabled until an isolated worker is connected to the refinement route. Its coding.providers.acp.budget accepts only max_files, max_diff_bytes, and max_wall_seconds. These limit one provider attempt. The unused max_retries setting is rejected; it never controlled provider retries. This does not change provider-specific retry parameters inside llm_config.

A trusted ACP-only worker can pass an approved ControlPlaneACPProviderConfig directly to ACPCodingProvider(provider_config=...). That worker does not make structured-output calls, so it does not need a synthetic codegen model profile. Normal refinement routing still loads the full policy and requires a named model profile for enabled coding and its structured fallback. The direct provider configuration does not authorize a worker launch or relax isolation.

Minimal Harness

schema_version: mozaiks.refinement_harness.v1
extends: mozaiks.default_refinement_harness
overrides: {}

The default OSS harness supplies the standard artifact routes, checkpoint chain, tools, policies, and prompts. Add local overrides.routing, overrides.checkpoints, config/tools.yaml, config/policies.yaml, or prompts/*.yaml only for real app-specific deltas.

Every workflow_sequence referenced by the effective harness must exist in the effective workflows/extended_orchestration/extension_registry.json.

Code Context By Checkpoint

Refinement should use code context progressively:

Checkpoint Context tools Purpose
request_submitted get_revision_context, get_artifact_summary, get_app_intelligence_context classify request scope from builder state and App Intelligence freshness, without raw code snippets
dependency_graph_requested Verified app bundle and bounded graph traversal assess relevant existing files and tests for scope, coding, and generator revision prompts
scope_requested get_app_intelligence_context, get_artifact_workspace_catalog, get_context_graph_catalog, search_app_source_context choose the smallest safe file scope from app shape, graph relationships, and bounded source search
contract_surface_requested get_contract_surface_context, get_app_intelligence_context, search_app_source_context map the request to module/page/workflow/config contract surfaces
coding_requested get_artifact_summary, get_app_intelligence_context, get_artifact_workspace_scope, get_context_graph_scope, read_app_source_file, get_related_app_source_files, search_app_source_context patch only explicit scoped files while using exact source reads and related files as read-only context

Do not dump a repository into prompts. The current AppIntelligenceSnapshot summarizes architecture and ownership; SourceContextBundle stores selected redacted files, chunks, symbols, and imports; agents retrieve exact evidence through tools only when their checkpoint needs it.

Enable the specialist through dependency_graph.enabled in app/config/refinement_policy.yaml and point dependency_graph.llm_profile at a configured profile. Factory uses impact_analyzer. The specialist runs through the same AG2 structured runner as the other checkpoints.

For a selected app build, graph and source tools read that record's archive without borrowing files or relationships from the current app. The specialist requires digest-verified bytes. It starts from selected paths or request keyword matches, follows the Context Graph's dependencies, and passes a bounded list of paths and relationships to the model. The result carries the target app, build record, bundle digest, and graph hash. Scope and coding agents receive this evidence as advice. The harness still enforces edit scope.

Generator revision middleware renders the assessment through the existing graph prompt pack when a verified app bundle is available. When a request starts from an app, AgentGenerator and AppGenerator keep using that app's build record after DesignDocs or AgentGenerator exports a new artifact. AppGenerator uses the selected app archive as its implementation baseline and records the revised workflow separately. A new app without a source build has no dependency assessment. An unavailable or invalid requested build has no fallback to current app evidence.

Reviewing workflow revisions

When DesignDocs asks the owner to review permissions, the card also lists workflow surfaces, the events modules emit, and the triggers each surface declares. For a workflow revision that declares no workflow surfaces, the card says so and the owner can request changes before the design is saved. AgentGenerator presents the executable workflow plan in its own review.

AppGenerator backend revisions

When a reviewed app revision owns only existing module backend/repo.py and backend/service.py files, the worker receives their admitted sources and the module contract. Factory carries the existing action declarations and module files from the verified build and retains the scoped implementation edits. Assembly checks for changes outside that module scope before bundle validation. Edits that require changing a module contract must include that contract in the reviewed plan.

Boundaries

Concern File
Ask/chat/workflow startup app/config/ai.json
Model profile selection app/config/refinement_policy.yaml
Artifact routing and checkpoints refinement_harness/config/harness.yaml
Sequence impact metadata workflows/extended_orchestration/extension_registry.json

Studio review can revalidate a saved inline refinement draft after an interrupted validation. Revalidate draft reads the saved bundle, verifies its archive digest, and runs the contained Docker checks. A passing result makes the draft eligible for the usual acceptance checks. The action does not run a coding agent.