Skip to content

Comments

Add tool call stage#344

Merged
KaQuMiQ merged 1 commit intomainfrom
feature/tool_stage
Jun 24, 2025
Merged

Add tool call stage#344
KaQuMiQ merged 1 commit intomainfrom
feature/tool_stage

Conversation

@KaQuMiQ
Copy link
Collaborator

@KaQuMiQ KaQuMiQ commented Jun 24, 2025

No description provided.

@coderabbitai
Copy link

coderabbitai bot commented Jun 24, 2025

Walkthrough

The changes introduce a new generic class method, tool_call, to the Stage class, enabling the execution of a FunctionTool within a stage context and handling its result or failure. The method manages tool requests and responses, updates the context accordingly, and adjusts the stage result based on the tool's handling mode. The predefined method in Stage is updated to append context elements conditionally and to extract the last completion result more robustly. The loopback_completion method is modified to change how the last input index is initialized and to remove an early return. Additionally, all return statements constructing a Stage are reformatted for consistency. In the FunctionTool class, the attributes _format_result and _format_failure are renamed to format_result and format_failure, making them public.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e52b8c and 636db4f.

📒 Files selected for processing (2)
  • src/draive/stages/stage.py (19 hunks)
  • src/draive/tools/function.py (4 hunks)
🔇 Additional comments (7)
src/draive/tools/function.py (1)

26-27: LGTM! Attribute visibility change is well-motivated.

The renaming of _format_result and _format_failure to public attributes (format_result and format_failure) is consistent throughout the class and supports the external usage by the new Stage.tool_call method. The changes maintain the same functionality while improving API accessibility.

Also applies to: 112-123, 177-177, 192-192

src/draive/stages/stage.py (6)

27-27: LGTM! Import additions support new functionality.

The added imports for LMMToolRequest, LMMToolResponse, and FunctionTool properly support the new tool_call method functionality.

Also applies to: 29-29, 48-49


143-144: LGTM! Documentation improvement.

The docstring update clarifies the expected behavior regarding LMMCompletion content being used as the stage result.


180-197: LGTM! Improved context element handling.

The changes enhance the predefined method by:

  • Using isinstance() for more precise type checking
  • Adding logic to alternate between LMMInput and LMMCompletion based on index
  • Replacing assertion-based approach with a more robust next() generator expression to find the last completion

These changes make the method more flexible and reliable.


538-546: LGTM! Improved error handling in loopback completion.

The changes improve the loopback_completion method by:

  • Initializing last_input_idx to len(state.context) for better default behavior
  • Removing the early return and allowing the method to continue processing even when no LMMInput is found

This makes the method more resilient to edge cases while maintaining proper logging.


741-837: Excellent implementation of tool call stage functionality.

The new tool_call method is well-designed with:

  • Proper parameter validation
  • Comprehensive error handling for both success and failure cases
  • Correct usage of the tool's public format_result and format_failure attributes
  • Appropriate context management with tool request/response pairs
  • Support for both "auto" and "direct" handling modes
  • Good documentation with examples and warnings

The implementation correctly integrates with the updated FunctionTool class and follows established patterns in the codebase.


209-212: LGTM! Consistent return statement formatting.

The reformatting of return statements across the file improves code consistency and readability while maintaining the same functionality.

Also applies to: 266-269, 306-309, 393-396, 481-484, 563-566, 602-605, 641-644, 699-702, 736-739, 923-926, 969-972, 1025-1028, 1140-1143

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6d7bd4 and 1e52b8c.

📒 Files selected for processing (2)
  • src/draive/stages/stage.py (19 hunks)
  • src/draive/tools/function.py (4 hunks)
🔇 Additional comments (5)
src/draive/tools/function.py (1)

26-27: LGTM! Attribute visibility change is well-executed.

The renaming of _format_result and _format_failure to public attributes is consistent across all usage locations and enables the new stage-level tool execution functionality. The change maintains the same behavior while improving the API design.

Also applies to: 112-123, 177-177, 192-192

src/draive/stages/stage.py (4)

27-27: LGTM! Import additions support the new tool call functionality.

The new imports for LMMToolRequest, LMMToolResponse, and FunctionTool are necessary for the tool call stage implementation.

Also applies to: 29-29, 49-49


181-198: Excellent improvement to context handling robustness.

The updated logic properly checks if elements are LMMContextElement instances before appending, and the completion result extraction using a reverse search is more robust than the previous direct assertion approach. This handles edge cases more gracefully.


210-213: LGTM! Consistent formatting improvement.

The multi-line formatting of return statements improves code readability and consistency across the codebase.

Also applies to: 267-270, 394-397, 482-485, 563-566, 602-605, 641-644, 699-702, 736-739, 923-926, 969-972, 1025-1028, 1140-1143


539-539: Good bug fix for index initialization.

Changing last_input_idx from -1 to len(state.context) provides a more appropriate default value that works correctly with the subsequent loop logic.

@KaQuMiQ KaQuMiQ force-pushed the feature/tool_stage branch from 1e52b8c to 636db4f Compare June 24, 2025 08:32
@KaQuMiQ KaQuMiQ merged commit 35cc6a1 into main Jun 24, 2025
5 checks passed
@KaQuMiQ KaQuMiQ deleted the feature/tool_stage branch June 24, 2025 08:54
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