Document core operation authoring with a working example

This commit is contained in:
2026-11-25 16:24:26 +00:00
parent 514f5a9692
commit 3826dce93b
8 changed files with 295 additions and 86 deletions

View File

@@ -20,8 +20,9 @@ modules. The resolver applies model-profile selections only to model roles.
Static initial/correction dependencies use the same constants as request builders;
they are preflight declarations, not asset manifests or execution fingerprints.
[BuildRequest](../../internal/framework/pipeline/construction.go) supplies the
shared native engine, option values, and prepared references. Option-aware
[BuildRequest](../../internal/framework/pipeline/construction.go) supplies
dependencies, option values, and prepared references; one-shot validators may
use the shared native engine. Option-aware
modules provide a resolver validator and a builder using the same strict decoder.
They do not rediscover configuration or reopen reference files. Generated
references arrive through operation requests, not construction-time file reads.
@@ -43,66 +44,68 @@ Preparation rejects incompatible types/registrations before parsing source.
Projectors do not inspect arbitrary domain JSON or publish files; the
[evidence contract](../integrations/evidence-context.md) owns the excerpt.
## Native Producer Recipe
## Preparing Operations
Follow the actual [spell extractor](../../internal/modules/dnd/extract/spells/extractor.go)
alongside [typed requests/results](../../internal/framework/contracts/typed_pipeline.go)
and [operation contracts](../../internal/framework/contracts/producer.go):
The [tested message-topic example](../../internal/framework/pipeline/author_example_test.go)
shows a domain-neutral input, codec, registrar, text chunk, contextual
interpretation, correction binding, and a deterministic branch. For production
adapters see [spell extraction](../../internal/modules/dnd/extract/spells/extractor.go)
and the [item registry normalizer](../../internal/modules/dnd/normalize/itemregistry/normalizer.go).
1. Validate operation input and prepare owned transcript/reference/contextual
projections once. Retain those fixed bytes and resolution mappings locally.
2. Build the initial `promptkit.RunRequest` using the declared prompt ID,
operation profile/session, native artifacts, and variables.
3. Call [RunProducer](../../internal/framework/pipeline/producer.go) with the shared
engine and the supplied typed operation. Supply ordinary interpretation,
correction-request, and supported fallback functions.
4. Interpret `*promptkit.RunResult` into the typed domain candidate. Attach
deterministic identities and canonical source references here, not by asking
the model to reproduce opaque IDs. Return actionable interpretation guidance
separately from operator diagnostics where the module can correct a selection.
5. Build the follow-up request from new findings/assignment only. Preserve
profile/session selections; native coordination carries prior conversation.
Do not rerender source inputs, serialize a domain artifact as a previous
assistant response, or implement another turn loop.
6. Return the helper's value and outcome in the typed operation result. The
runner has already supplied assessment; do not validate again after the helper.
A typed stage implements its `PrepareExtraction`, `PrepareMerge`,
`PrepareNormalize`, or `PrepareChunk` method from
[preparation contracts](../../internal/framework/contracts/preparation.go).
Core invokes that method once with domain inputs, then executes the returned
operation. The stage does not receive or choose an assessor, engine, cache,
capture, or terminal mode. The runner binds those privately; direct callers can
supply a [core execution context](../../internal/framework/pipeline/operation.go)
and preparation function to the same executor.
The helper checks native structural status before interpretation, binds native
execution overrides/observers, assesses every delivered usable candidate, and
handles prepared reuse. Modules do not replace its assessor/cache or infer
acceptance from provider success. [Pipeline Internals](pipeline.md) owns the
complete assessment/disposition algorithm; [LLM Integration](llm.md) owns native
execution and [State Internals](state.md) owns storage/capture lifecycle.
- Return a deterministic operation with one candidate when no model is needed.
Core assesses it once; there is no native request or synthetic cache key.
- Return a native operation containing the selected `promptkit.RunRequest`,
an interpreter, and, when supported, a correction builder and fallback.
Interpret into an evaluation with a candidate and any ordered guidance.
A correctable selection can provide guidance without a candidate. A candidate
is not an approval: core still runs every configured validator.
- Return an ordinary Go error for preparation failures. Use the explicit
preparation-limit operation only for an existing supported limit, not as
generic error recovery. Core selects strict/permissive handling.
- Supply fallback only when the family supports intrinsically usable output.
It receives the final eligible evaluation, or nil when none remains. It must
preserve domain/source/downstream invariants; core does not re-run ordinary
validators or claim acceptance for fallback.
Fallback construction is explicit and family-owned. It must satisfy intrinsic
shape/source/downstream invariants, but does not rerun ordinary validators or
claim semantic approval. Unsupported/invalid construction fails. No earlier
candidate is recovered after an unusable continuation; cancellation produces no
fallback. Modules do not pick a permissive default or hide an ordinary operation
error as recovery.
For the common correction form, `PromptCorrection` binds ordered guidance to
an integration-chosen prompt input; a specialized builder can instead construct
the assignment directly. Native coordination retains the initial profile/session,
resolved options, and conversation history. Modules do not replay source or
implement a continuation loop. See [Pipeline Internals](pipeline.md) for
assessment and terminal behavior and [LLM Integration](llm.md) for native ownership.
An evaluation and its candidate, diagnostics, guidance, and optional evidence
are one operation-local unit. Core replaces it on each delivered interpretation
and clears it before a selected correction; failed or unusable continuation
cannot restore a prior evaluation. Historical capture may retain prior evidence.
Preparation transfers returned values and callbacks to that operation; a shared
module must not store mutable operation state. Own mutable slices/maps that a
callback might modify and respect the existing detached input boundaries.
Optional evidence projections are lazy and only invoked when capture is enabled.
This does not promise thread safety for caller-supplied writers or observers.
## Validators And Deterministic Work
Validators receive native execution options and detached candidate/context views,
not a producer operation or semantic-turn loop. Return approval, or rejection
with separate stable reason and actionable `CorrectionGuidance`. Operator
`Message` is not model feedback. The detecting rule owns guidance about fields
the producer controls, without internal paths/keys/opaque identities.
Invalid rejection guidance is a contract failure.
not an operation executor. Return approval or rejection with separately authored
actionable correction guidance; operator messages are not model feedback.
A model validator calls the shared engine once and checks native result usability
before interpretation. The [combat validator](../../internal/modules/dnd/validate/scenedescriptions/combat_semantics/validator.go)
is the one-shot example. It does not own a semantic correction loop or extend
native repair budgets.
A model validator calls the shared native engine directly, checks native errors/
validation before interpretation, and distinguishes unavailable judgment from
semantic rejection while preserving causes. See the
[combat validator](../../internal/modules/dnd/validate/scenedescriptions/combat_semantics/validator.go).
Do not rerun a validator to extend native repair budgets.
Deterministic modules produce once through ordinary typed interfaces. The runner
assesses the value and can invoke an explicitly supported result fallback after
nonacceptance. Production errors propagate without generic retries. Model-backed
modules with legitimate no-model branches use direct `AssessProducer` on that
value; preparation-limit terminal handling uses `FinishProducerFailure` rather
than synthetic requests. The [noop normalizer](../../internal/modules/generic/normalize/noop/normalizer.go)
and registry normalizers show the distinct paths.
Deterministic modules return prepared candidates through the same core path.
See the [noop normalizer](../../internal/modules/generic/normalize/noop/typed.go)
and the model-backed extractors with no-model branches.
## Prompt And Schema Ownership
@@ -121,17 +124,17 @@ See [schema selection](../config.md#prompt-output-contracts-and-schemas) and the
## Semantic Reconciliation
The [shared core](../../internal/framework/semanticreconcile/preparation.go)
offers preparation, native request builders, proposal assessment, and typed
application functions, not a replacement execution service.
The [shared facility](../../internal/framework/semanticreconcile/operation.go)
prepares core operations and provides proposal assessment and typed application,
not a replacement execution service.
[Requests](../../internal/framework/semanticreconcile/requests.go) consume one
retained preparation. [Proposal safety](../../internal/framework/semanticreconcile/proposal.go)
resolves request-local handles; [application](../../internal/framework/semanticreconcile/application.go)
clones/preserves originals and applies domain policies.
The [item normalizer](../../internal/modules/dnd/normalize/itemregistry/normalizer.go)
preprocesses fixed originals once, prepares bounded windows/handles once, then
uses the same producer helper as extraction. Each complete proposal is assessed
preprocesses fixed originals once and prepares bounded windows/handles once.
Core executes its operation like extraction. Each complete proposal is assessed
and applied afresh to originals before pipeline assessment. Domain guards,
identity, evidence, diagnostics, and supported final-only fallback remain with
the artifact family. Do not union plans across turns, reuse prior mutated output,