Skip to content

fix: update core version and improve tool message handling#56

Merged
Pratham-Mishra04 merged 1 commit intomainfrom
06-04-chore_core_version_updates_in_transports_and_plugins
Jun 4, 2025
Merged

fix: update core version and improve tool message handling#56
Pratham-Mishra04 merged 1 commit intomainfrom
06-04-chore_core_version_updates_in_transports_and_plugins

Conversation

@Pratham-Mishra04
Copy link
Copy Markdown
Collaborator

Enhanced Tool Calling Support and Message Handling

This PR improves tool calling functionality and message handling across the Bifrost system:

  1. Removed unnecessary assertion in the tool calling end-to-end test

  2. Updated the Maxim plugin to properly handle different message types:

    • Added support for tool messages with tool call IDs
    • Fixed image content handling by accessing it through UserMessage
  3. Improved Gemini integration:

    • Enhanced function call argument handling with better error recovery
    • Fixed potential memory issues by properly copying function names
    • Added a shared function type pointer for consistency
  4. Updated dependencies:

    • Upgraded core dependency from v1.0.7 to v1.0.9 in the Maxim plugin
    • Aligned transport module to use core v1.0.9 instead of v1.1.0

These changes improve the robustness of tool calling and ensure proper handling of different message types across the system.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 4, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved message processing to better handle image and tool messages in chat interactions.
    • Enhanced error handling and data marshaling for function call arguments in request conversions.
  • Tests

    • Updated test message types to improve compatibility with chat completion requests.
    • Refined test assertions for tool call identifiers.
  • Chores

    • Updated and synchronized core dependency versions across modules.

Walkthrough

This update refines message handling and tool call processing in the plugin and transport layers, adjusts test assertions, and synchronizes dependency versions for the Bifrost core library across modules. Changes include improved nil checks, type adjustments, function argument marshaling, and dependency version alignment.

Changes

File(s) Change Summary
core/tests/e2e_tool_test.go Removed redundant nil assertion for toolCall.ID in test logic.
plugins/maxim/main.go Enhanced message extraction logic in PreHook, added handling for ToolMessage with non-nil ToolCallID.
plugins/maxim/plugin_test.go Changed test input type from []schemas.Message to []schemas.BifrostMessage.
plugins/maxim/go.mod, transports/go.mod Updated/downgraded github.com/maximhq/bifrost/core dependency version.
transports/bifrost-http/integrations/genai/types.go Refactored function tool call marshaling, improved pointer handling, and added package-level variable for type.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Plugin (PreHook)
    participant Bifrost Client

    User->>Plugin (PreHook): Send chat message (Content/UserMessage/ToolMessage)
    Plugin (PreHook)->>Plugin (PreHook): Check message type
    alt UserMessage with ImageContent
        Plugin (PreHook)->>Plugin (PreHook): Append ImageContent
    else ToolMessage with ToolCallID
        Plugin (PreHook)->>Plugin (PreHook): Append ToolMessage as completion request
    end
    Plugin (PreHook)->>Bifrost Client: Forward processed messages
Loading

Possibly related PRs

Suggested reviewers

  • akshaydeo
  • danpiths

Poem

In the garden of code, where the tool calls grow,
A rabbit refines how the messages flow.
With pointers and checks, dependencies align—
Now plugins and transports work just fine!
Hop, skip, and test, with each gentle nudge,
The code hops forward—no need to begrudge.
🐇✨


📜 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 a5c6e4b and 570f07b.

⛔ Files ignored due to path filters (2)
  • plugins/maxim/go.sum is excluded by !**/*.sum
  • transports/go.sum is excluded by !**/*.sum
📒 Files selected for processing (6)
  • core/tests/e2e_tool_test.go (0 hunks)
  • plugins/maxim/go.mod (1 hunks)
  • plugins/maxim/main.go (1 hunks)
  • plugins/maxim/plugin_test.go (1 hunks)
  • transports/bifrost-http/integrations/genai/types.go (2 hunks)
  • transports/go.mod (1 hunks)
💤 Files with no reviewable changes (1)
  • core/tests/e2e_tool_test.go
🧰 Additional context used
🧠 Learnings (1)
plugins/maxim/plugin_test.go (1)
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#54
File: core/schemas/bifrost.go:46-49
Timestamp: 2025-06-04T09:22:18.093Z
Learning: In core/schemas/bifrost.go, the RequestInput struct uses ChatCompletionInput *[]BifrostMessage (pointer-to-slice) rather than []BifrostMessage to properly represent union type semantics. For text completion requests, ChatCompletionInput should be nil to indicate "no chat payload at all", while for chat completion requests it should be non-nil (even if empty slice). This distinguishes between different request types rather than just empty vs non-empty chat messages.
🧬 Code Graph Analysis (3)
plugins/maxim/plugin_test.go (1)
core/schemas/bifrost.go (1)
  • BifrostMessage (143-152)
plugins/maxim/main.go (1)
core/schemas/bifrost.go (3)
  • UserMessage (155-157)
  • ImageContent (174-179)
  • ToolMessage (160-163)
transports/bifrost-http/integrations/genai/types.go (2)
core/utils.go (1)
  • Ptr (3-5)
core/schemas/bifrost.go (4)
  • ToolChoiceTypeFunction (126-126)
  • FunctionCall (260-263)
  • ToolCall (266-270)
  • Function (101-105)
🔇 Additional comments (9)
transports/bifrost-http/integrations/genai/types.go (4)

5-5: LGTM: Import addition for error handling enhancement.

The fmt import is correctly added to support the improved error handling in the JSON marshaling fallback.


12-12: Excellent optimization with shared pointer.

Creating a package-level pointer to the function type string is a good optimization that avoids repeated pointer allocations and ensures consistency across all tool calls.


46-46: Improved error handling preserves argument information.

The change from defaulting to "{}" to using fmt.Sprintf("%v", ...) is a significant improvement. This preserves the original argument information even when JSON marshaling fails, which will be valuable for debugging and maintaining data integrity.


50-57: Good fix for potential memory safety issue.

The refactor to use an inline function that copies the function name before taking its address is important for memory safety. This prevents potential issues where the pointer might reference memory that gets reused or goes out of scope.

The use of the shared fnTypePtr variable also improves consistency and performance.

transports/go.mod (1)

7-7: Good version alignment for module compatibility.

The downgrade to v1.0.9 aligns with the upgrade in the plugins/maxim module, ensuring consistent dependency versions across the project. This coordination helps avoid potential compatibility issues.

plugins/maxim/go.mod (1)

6-6: Appropriate version upgrade for consistency.

The upgrade to v1.0.9 aligns with the transport module's version change, ensuring both modules use the same core dependency version. This coordination is essential for avoiding version conflicts and ensuring compatibility.

plugins/maxim/plugin_test.go (1)

110-110: Correct type alignment with schema expectations.

The change from []schemas.Message to []schemas.BifrostMessage is the correct type to use for ChatCompletionInput. This aligns with the schema definition and ensures the test accurately reflects the expected message structure.

plugins/maxim/main.go (2)

145-149: LGTM! Good defensive programming with proper nil checks.

The addition of the nil check on message.UserMessage before accessing its ImageContent prevents potential runtime panics and correctly follows the schema structure where UserMessage contains the ImageContent field.


155-160: LGTM! Proper handling of tool messages with tool call IDs.

The new conditional block correctly handles ToolMessage objects by:

  • Checking both message.ToolMessage != nil and message.ToolMessage.ToolCallID != nil
  • Only processing tool messages that have an associated tool call ID
  • Following the same logging pattern as other message types

This extends the plugin's message processing capabilities as intended by the PR objectives.

✨ 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
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@Pratham-Mishra04 Pratham-Mishra04 marked this pull request as ready for review June 4, 2025 10:58
@Pratham-Mishra04 Pratham-Mishra04 merged commit 8d89d0a into main Jun 4, 2025
2 checks passed
@Pratham-Mishra04 Pratham-Mishra04 deleted the 06-04-chore_core_version_updates_in_transports_and_plugins branch June 4, 2025 11:03
akshaydeo pushed a commit that referenced this pull request Nov 17, 2025
# Enhanced Tool Calling Support and Message Handling

This PR improves tool calling functionality and message handling across the Bifrost system:

1. Removed unnecessary assertion in the tool calling end-to-end test
2. Updated the Maxim plugin to properly handle different message types:
   - Added support for tool messages with tool call IDs
   - Fixed image content handling by accessing it through UserMessage

3. Improved Gemini integration:
   - Enhanced function call argument handling with better error recovery
   - Fixed potential memory issues by properly copying function names
   - Added a shared function type pointer for consistency

4. Updated dependencies:
   - Upgraded core dependency from v1.0.7 to v1.0.9 in the Maxim plugin
   - Aligned transport module to use core v1.0.9 instead of v1.1.0

These changes improve the robustness of tool calling and ensure proper handling of different message types across the system.
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