Python semantic layer: injection resolution and the public API - #256
Draft
jat255 wants to merge 3 commits into
Draft
Python semantic layer: injection resolution and the public API#256jat255 wants to merge 3 commits into
jat255 wants to merge 3 commits into
Conversation
jat255
force-pushed
the
jat255/wwmt-injections
branch
from
September 3, 2026 00:31
9c65851 to
9c2fc1d
Compare
jat255
force-pushed
the
jat255/wwmt-injections
branch
from
September 4, 2026 04:32
9c2fc1d to
4e215d3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Last of four stacked PRs building the Python semantic layer (M3). Based on #249. Completes the milestone.
The one-sentence version: some measure arguments are not the model's to fill in — a database connection, say — so this PR adds the small function that matches each of those
Injectedarguments to a named data source, and it opens the public API:measure,semantic_layer, and their types are now importable fromcommonsitself.Carrying on the recipe-box analogy from #249: an
Injectedargument is an ingredient the kitchen supplies, not the chef.resolve_injections()is the stocking step that matches each kitchen-supplied ingredient to a named pantry, by name.The three rules. For each injected argument of each measure: an argument named after a data source receives that source's connection, even when the argument has a default. One matching no source keeps its default. One matching no source and having no default is an error naming the measure, the arguments, and the sources that are available. The error is raised here, at construction, so a measure that can never run is caught before the agent starts a conversation, not in the middle of one.
A deliberate boundary.
resolve_injections(measures, injectables)takes a plainMapping[str, Any], not a data-source type, and nothing in this milestone imports the data layer. That mirrors the R package's division of labor:resolve_injections()inpkg-r/R/measures.Ralso takes a plain named list, whilemeasure_injectables(), the part that knows what a data source is, lives inpkg-r/R/commons.Rwith the agent. Nothing callsresolve_injections()yet for that reason — its caller is the agent constructor, which M5 adds, and which is where the error surfaces to a user.The public API.
__all__gainsInjected,Measure,SemanticLayer,measure, andsemantic_layer.measure_schema_text()andresolve_injections()stay private, matching the R package's export discipline: they are seams the agent layer imports, not API a measure author uses. The test fixture files move to the public import path (from commons import Injected, measure) in the same commit, which is what checks the surface is usable the way a measure author will use it.Verified on both supported interpreters: 187 tests pass on 3.11 and 3.13.