Conversation
WalkthroughThis update introduces several structural and functional changes across the codebase. The Makefile and project configuration are updated to newer dependency versions. The public API surface of the main package is significantly reduced by removing numerous imports and exports from 📜 Recent review detailsConfiguration used: CodeRabbit UI ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (16)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (15)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Caution
Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.
Actionable comments posted: 1
🧹 Nitpick comments (3)
src/draive/resources/template.py (1)
50-76: Prefer class-level annotations to avoid runtime__annotations__pollutionThe attributes are re-annotated inside
__init__right before theobject.__setattr__calls.
While legal, per-instance annotations:
- Inflate
__annotations__at runtime (one entry per instantiation).- Provide no extra type-checking benefit compared to class-level annotations.
- Obscure the intent of the code because the reader must scan the constructor to learn the attribute types.
Consider moving the three annotations to the class body:
class ResourceTemplate[**Args](…): __slots__ = ("_check_availability", "declaration", "uri") + uri: str + declaration: ResourceDeclaration + _check_availability: ResourceAvailabilityCheckand then keep only the
object.__setattr__calls in__init__.src/draive/prompts/template.py (1)
38-55: Same remark as for resources: move attribute annotations to the class bodyInline annotations for
self.declarationandself._check_availabilityinside__init__create per-instance overhead and clutter the constructor. Relocate them next to__slots__for clarity:class PromptTemplate[**Args](ParametrizedFunction[…]): __slots__ = ("_check_availability", "declaration") + + declaration: PromptDeclaration + _check_availability: PromptAvailabilityChecksrc/draive/evaluation/evaluator.py (1)
266-295: Inline type annotations inside__init__– move them to the class bodySame pattern as in other files: co-locating the annotations with
__slots__improves readability and avoids per-instance overhead.class Evaluator[Value, **Args]: __slots__ = ("_definition", "_execution_context", "meta", "name", "threshold") + + _definition: EvaluatorDefinition[Value, Args] + _execution_context: ScopeContext | None + name: str + threshold: float + meta: Meta
🛑 Comments failed to post (1)
src/draive/prompts/template.py (1)
56-64:
⚠️ Potential issue
_check_availabilityis never initialised – fatal typo inobject.__setattr__callThe second
object.__setattr__still writes to"declaration"instead of"_check_availability".
At runtimeself.availablewill raiseAttributeError, breaking every prompt resolution path.- object.__setattr__( - self, - "declaration", - availability_check + object.__setattr__( + self, + "_check_availability", + availability_check or ( lambda: True # available by default ), )Please patch before merging and add a unit-test that instantiates a
PromptTemplatewithout an explicitavailability_checkto catch this class of issue.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.self._check_availability: PromptAvailabilityCheck object.__setattr__( self, "_check_availability", availability_check or ( lambda: True # available by default ), )🤖 Prompt for AI Agents
In src/draive/prompts/template.py around lines 56 to 64, the object.__setattr__ call incorrectly assigns the availability_check function to the "declaration" attribute instead of "_check_availability", causing self.available to raise AttributeError at runtime. Fix this by changing the attribute name in object.__setattr__ from "declaration" to "_check_availability". Additionally, add a unit test that creates a PromptTemplate instance without passing an explicit availability_check to ensure the default availability check is properly set and no AttributeError occurs.
There was a problem hiding this comment.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
src/draive/prompts/template.py (1)
24-25: 🛠️ Refactor suggestionConsider adding immutability guards to mirror the
Evaluatorpattern
freeze()was removed, but unlikeEvaluator,PromptTemplatedoes not add a custom__setattr__/__delattr__. After the constructor returns, callers can still mutatedeclarationor_check_availability:tmpl.declaration.description = "Oops, mutated"If full immutability is desired, replicate the guard methods introduced in
Evaluator.
🧹 Nitpick comments (1)
src/draive/evaluation/evaluator.py (1)
266-295: Constructor correctly bypasses the custom__setattr__Using
object.__setattr__inside__init__allows you to populate the slotted attributes before the immutability guard kicks in – exactly the right pattern. One small caveat worth noting:
metaitself is still a mutabledict. External callers can mutateevaluator.meta[...] = …without triggering the guard, which partially defeats “immutability”. If that is undesirable, you may want to (a) store aMappingProxyTypeor (b) deep-copy / freeze the dict on assignment.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Knowledge Base: Disabled due to Reviews > Disable Knowledge Base setting
⛔ Files ignored due to path filters (1)
uv.lockis excluded by!**/*.lock
📒 Files selected for processing (16)
Makefile(1 hunks)pyproject.toml(2 hunks)src/draive/__init__.py(1 hunks)src/draive/agents/node.py(1 hunks)src/draive/agents/runner.py(1 hunks)src/draive/agents/workflow.py(1 hunks)src/draive/configuration/__init__.py(1 hunks)src/draive/configuration/state.py(1 hunks)src/draive/configuration/types.py(1 hunks)src/draive/evaluation/evaluator.py(4 hunks)src/draive/evaluation/scenario.py(4 hunks)src/draive/instructions/template.py(1 hunks)src/draive/parameters/function.py(4 hunks)src/draive/prompts/template.py(2 hunks)src/draive/resources/template.py(1 hunks)src/draive/tools/function.py(2 hunks)
✅ Files skipped from review due to trivial changes (3)
- Makefile
- src/draive/agents/node.py
- src/draive/init.py
🚧 Files skipped from review as they are similar to previous changes (11)
- src/draive/configuration/types.py
- src/draive/agents/workflow.py
- src/draive/agents/runner.py
- src/draive/configuration/init.py
- pyproject.toml
- src/draive/instructions/template.py
- src/draive/resources/template.py
- src/draive/configuration/state.py
- src/draive/tools/function.py
- src/draive/parameters/function.py
- src/draive/evaluation/scenario.py
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/draive/prompts/template.py (2)
src/draive/prompts/types.py (2)
PromptDeclaration(41-45)PromptDeclarationArgument(30-38)src/draive/parameters/function.py (1)
arguments(202-203)
🔇 Additional comments (3)
src/draive/evaluation/evaluator.py (2)
245-252: Immutability & memory optimisation achieved with__slots__Introducing
__slots__is a good move – it prevents the dynamic creation of attributes, trims the per-instance memory footprint, and signals the intent to keep the object layout stable.
497-514: Robust attribute-mutation guardThe explicit
__setattr__&__delattr__that always raiseAttributeErrorfully enforce runtime immutability (except for in-place mutation of mutable objects living inside the instance, see previous comment). Nicely done.src/draive/prompts/template.py (1)
38-55:declarationbuilt correctly – but will be overwritten a few lines laterThe first
object.__setattr__(…, "declaration", …)correctly creates thePromptDeclarationinstance. Keep an eye on the next block – it overwrites the same attribute.
e1149d2 to
0434ece
Compare
No description provided.