Skip to content

Comments

Add configuration interface#316

Merged
KaQuMiQ merged 1 commit intomainfrom
feature/config
May 23, 2025
Merged

Add configuration interface#316
KaQuMiQ merged 1 commit intomainfrom
feature/config

Conversation

@KaQuMiQ
Copy link
Collaborator

@KaQuMiQ KaQuMiQ commented May 22, 2025

No description provided.

@coderabbitai
Copy link

coderabbitai bot commented May 22, 2025

Walkthrough

This 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 src/draive/__init__.py, including observability, agent workflow, guardrails, and utility components. The freeze function and related immutability enforcement are removed from multiple modules, replaced in some classes by __slots__ and the use of object.__setattr__ for attribute assignment. New configuration management capabilities are added via the draive.configuration package, including a Configuration class with asynchronous loading and a ConfigurationLoading protocol. Additional changes enforce immutability in classes by overriding __setattr__ and __delattr__. There are also minor corrections and refactoring in template and tool-related modules.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Knowledge Base: Disabled due to Reviews > Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 0434ece and 1caf50d.

⛔ Files ignored due to path filters (1)
  • uv.lock is 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 (1)
  • src/draive/agents/node.py
🚧 Files skipped from review as they are similar to previous changes (15)
  • src/draive/agents/runner.py
  • Makefile
  • pyproject.toml
  • src/draive/agents/workflow.py
  • src/draive/configuration/init.py
  • src/draive/tools/function.py
  • src/draive/configuration/types.py
  • src/draive/resources/template.py
  • src/draive/prompts/template.py
  • src/draive/instructions/template.py
  • src/draive/parameters/function.py
  • src/draive/evaluation/evaluator.py
  • src/draive/evaluation/scenario.py
  • src/draive/configuration/state.py
  • src/draive/init.py
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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__ pollution

The attributes are re-annotated inside __init__ right before the object.__setattr__ calls.
While legal, per-instance annotations:

  1. Inflate __annotations__ at runtime (one entry per instantiation).
  2. Provide no extra type-checking benefit compared to class-level annotations.
  3. 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: ResourceAvailabilityCheck

and 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 body

Inline annotations for self.declaration and self._check_availability inside __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: PromptAvailabilityCheck
src/draive/evaluation/evaluator.py (1)

266-295: Inline type annotations inside __init__ – move them to the class body

Same 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_availability is never initialised – fatal typo in object.__setattr__ call

The second object.__setattr__ still writes to "declaration" instead of "_check_availability".
At runtime self.available will raise AttributeError, 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 PromptTemplate without an explicit availability_check to 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
src/draive/prompts/template.py (1)

24-25: 🛠️ Refactor suggestion

Consider adding immutability guards to mirror the Evaluator pattern

freeze() was removed, but unlike Evaluator, PromptTemplate does not add a custom __setattr__ / __delattr__. After the constructor returns, callers can still mutate declaration or _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:

  • meta itself is still a mutable dict. External callers can mutate evaluator.meta[...] = … without triggering the guard, which partially defeats “immutability”. If that is undesirable, you may want to (a) store a MappingProxyType or (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

📥 Commits

Reviewing files that changed from the base of the PR and between 7c1a5a4 and 0e706fc.

⛔ Files ignored due to path filters (1)
  • uv.lock is 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 guard

The explicit __setattr__ & __delattr__ that always raise AttributeError fully 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: declaration built correctly – but will be overwritten a few lines later

The first object.__setattr__(…, "declaration", …) correctly creates the PromptDeclaration instance. Keep an eye on the next block – it overwrites the same attribute.

@KaQuMiQ KaQuMiQ force-pushed the feature/config branch 2 times, most recently from e1149d2 to 0434ece Compare May 23, 2025 08:45
@KaQuMiQ KaQuMiQ merged commit 1be819d into main May 23, 2025
5 checks passed
@KaQuMiQ KaQuMiQ deleted the feature/config branch May 23, 2025 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant