[EPIC] Wire prompt compiler tool projection into the real rlm_completion planner surface #450
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
nsaspy/prolog-rlm#450
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Goal
Make
rlm_prompt_compileractually control the tool schemas the root LLM sees in the productionrlm_completionpath, while keeping the full trusted runtime bindings available for execution and authority checks.This closes the current gap between:
and:
The implementation must preserve the architectural rule:
No new tool registry or model-facing interface should be created.
Research: current main behavior
1.
prolog/rlm_prompt_compiler.plis implementedThe compiler already provides:
It produces a structured
compiled_context{...}containing selected/rejected units, context units, tool schemas, token ledger, active units, reasons and a fingerprint.It performs bounded evidence-driven selection, dependency closure, capability/discovery filtering, conflicts/supersession, and shared context packing.
research/RLM-RESEARCH-010-symbolic-prompt-compiler.organdresearch/RLM-RESEARCH-011-managed-context-tool-discovery.orgdefine this as the provider-visible projection boundary.2. Current
rlm_completionbypasses itIn
prolog/rlm_completion.pl,completion_with_handle/...currently does:and
runtime_tools/4currently resolves registry schemas with:Therefore every schema returned by the runtime registry is still handed directly to the root planner when a registry is supplied.
That means prompt-compiler contextual activation/deactivation does not yet govern the actual production planner tool view.
3.
planner_prompt/7serializes those schemas directlyThe current planner prompt contains:
using the raw
ToolSchemasreturned bytool_discover/2.So the actual LLM-facing tool projection today is still owned by
rlm_completion, not byrlm_prompt_compiler.4. Compiler tests are currently isolated
Repository search of
prompt_compile/4shows compiler implementation/research/tests and other schema work, but no productionrlm_completioncall site on current main.The compiler test
context_deactivation_does_not_unregister_runtime_toolcorrectly proves that a tool may disappear from compiled context without runtime unregistering, but the production completion path does not yet consume that compiled tool list.5. Existing research already called for this integration
RLM-RESEARCH-011-managed-context-tool-discovery.orgexplicitly states the intended direction:This epic implements that already-researched contract rather than inventing a new architecture.
Design contract
Split the current ambiguous
runtime_toolsresponsibility into two explicit concepts:Conceptually:
Selection does not unregister tools. Selection does not grant authority. A tool hidden from the planner may remain registered and executable by trusted host code; a tool visible to the planner still must pass normal capability/schema/preflight/authority/effect checks when invoked.
Completion API / options
Do not add a second completion API.
Use existing
rlm_completion(..., Options, ...)configuration.Add/normalize compiler-related host options conceptually as:
Exact option naming may follow current conventions, but ownership must remain host-side.
Default mode
Target default after migration:
all_toolsremains an explicit compatibility/debug/benchmark mode as already specified by RLM-RESEARCH-010/011.If backwards-compatibility risk requires a staged rollout, implementation may temporarily require an explicit compiler option for one release/slice, but the issue must document that staging and include a test proving the intended eventual
compileddefault. Do not leave two indefinite ambiguous defaults.Catalog ownership
Preferred behavior:
prompt_catalog(Catalog), use it directly;tool_registry(Registry)exists, build a bounded ephemeral catalog projection from that registry for the completion call usingprompt_catalog_register_tool_registry/4;A long-lived host catalog remains preferable when Skills/instructions/MCP/resources need to coexist with tool metadata across turns.
Do not store executable handlers inside the prompt catalog.
Exact
rlm_completionflowRefactor
completion_with_handle/...so the order becomes conceptually:The important invariant is:
Do not replace
RuntimeToolswith only selected tools unless a separate authority design explicitly requires that later.Exact implementation files
1.
prolog/rlm_completion.plA. Imports
Import/use
rlm_prompt_compilerthrough the module-qualified style consistent with current architecture.B. Split
runtime_tools/4Current predicate:
currently conflates executable tools and model-visible schemas.
Refactor into explicit responsibilities, conceptually:
or equivalent names following current conventions.
runtime_tool_bindingsowns the full trusted execution list.provider_tool_projectionowns catalog creation/import/compile/render and returns at least:Do not pass raw handlers/callables into the compiler projection.
C. Compile input
The minimum compile input is the current normalized user
Query.Preferred shape:
For the first integration slice,
TrustedSignals,Needs,HostSelected, andHostDeniedmay default empty unless already available in Options.Expose host options for these only if they can be cleanly normalized through the existing compiler API. Do not parse arbitrary model output into trusted
selected/deniedfields.D. Compiler mode
For
compiledmode callprompt_compile/4normally.For
all_tools, use the compiler's existing compatibility mode instead of bypassing the compiler and directly callingtool_discover/2for planner exposure. This keeps one projection path and makes comparison deterministic.E. Planner prompt
Change
planner_prompt/...so it no longer labels raw registry results as:Use language that reflects actual model visibility, e.g.:
Add compiler-rendered text in one explicit section, e.g.:
Do not serialize the same full tool schema twice. If
prompt_render/3already includes full schema text inCompiledText, decide one canonical representation for the planner path:Active tool schemasfield in the typed-planner prompt.The token ledger must charge the actual representation used. Do not count one representation and render another.
F. Completion result observability
Add non-secret compiler metadata to the completion result/trajectory if a stable extension point exists:
Do not expose rejected hidden tool schemas or host-only catalog internals by default.
This makes it possible to prove which projection the planner actually received.
G. Cleanup
If completion creates an ephemeral prompt catalog, wrap it in
setup_call_cleanup/3and destroy it on success, failure, timeout, cancellation, or planner error.Host-owned catalogs supplied through Options must never be destroyed by completion cleanup.
2.
prolog/rlm_prompt_compiler.plA. Provider tool schemas must correspond to active packed units
Audit
selected_tool_schemas/2,active_units_from_pack/2, andprompt_render/3together.Current
tool_schemasare derived from pre-packSelectedEntries, whileactive_unitscome from the context pack.For mandatory imported tools these normally coincide, but a custom tool with
mandatory_context:falsecould theoretically be selected then omitted by packing while remaining inCompiled.tool_schemas.The provider-visible contract must be exact:
Implement one canonical helper, conceptually:
and ensure
prompt_render/3returns only schemas corresponding to active tool/mcp_tool units.If
pack(false)is used for inspection, preserve a clearly documented pre-pack state rather than pretending it is a provider-ready render.B. #174 integration
Issue #174 adds declarative
activation:always|relevantto the sameprompt_unitinterface.This completion epic must consume whatever final compiler contract #174 lands. It must not add its own special always-visible list.
If #176 lands before #174, tests should use current relevance behavior and add the always-visible integration regression when #174 lands.
3.
test/rlm_completion_test.plor canonical completion test fileAdd production-path tests proving the root planner sees compiled schemas rather than raw registry discovery.
If current completion tests use support planners that capture planner prompt text, extend those fixtures instead of building a separate test harness.
4.
test/rlm_prompt_compiler_test.plAdd/adjust active-schema packing regressions if
tool_schemasderivation changes.5.
docs/completion-runtime.mdReplace the current statement that the root planner receives
registered tool schemaswith the precise contract:Document
compiledvsall_toolsmode and catalog ownership.6. New stable runtime doc
Create:
This was already identified as missing in #174.
Required sections:
The doc must explicitly show:
7. Research/design source of truth
Update:
Add an
Implementation closure / completion integrationsection recording the exact landed path.Do not create another competing architecture research note for this integration; RLM-RESEARCH-011 already researched and required it.
Required regression matrix
completion_planner_hides_irrelevant_registered_toolgit_diffandproject_search;completion_executor_retains_hidden_runtime_bindingcompletion_all_tools_mode_preserves_compatibility_projectionall_toolsmode;completion_capability_denied_tool_not_visiblecompletion_compiler_projection_fingerprint_is_observablecompletion_prompt_uses_active_not_registered_wordingcompletion_does_not_duplicate_full_schema_renderingcompletion_ephemeral_catalog_is_cleaned_on_successcompletion_ephemeral_catalog_is_cleaned_on_planner_failurecompletion_ephemeral_catalog_is_cleaned_on_timeout_or_cancelcompletion_host_owned_catalog_is_not_destroyedcompletion_compiled_projection_can_include_instruction_or_skill_contextcompletion_pack_budget_applies_to_tool_projectionprovider_tool_schemas_are_subset_of_active_unitsoptional_selected_but_packed_out_tool_schema_is_not_sentalways_visible_tool_reaches_completion_planner_on_unrelated_queryactivation:always;relevant_tool_still_deactivates_between_completion_turnshidden_tool_cannot_be_model_selected_by_test_planner_without_schema_visibilityBackwards compatibility
all_toolsfor old projection behavior;tools(...)host bindings remain supported, but their model-visible schema story must be documented explicitly instead of silently bypassing compilation;Non-goals
prompt_unitactivation field);Dependencies / ordering
Acceptance gate
Complete only when:
rlm_completionno longer gives rawtool_discover/2output directly to the planner in normal compiled mode;all_toolsremains an explicit compatibility mode through the same compiler path;docs/prompt-compiler.md,docs/completion-runtime.md, and RLM-RESEARCH-011 reflect the landed contract;Implementation agents must re-read live main before editing, but they must preserve this separation of runtime execution bindings from provider-visible compiled tool schemas.
nsaspy referenced this issue2026-09-10 21:20:50 +00:00
Duplicate of #176 (pre-existing Forgejo mirror). Closing this accidental duplicate created by today's open-state sync; #176 stays canonical on Forgejo.