Skip to content

useCoagent performance tweaks - #2236

Merged
mme merged 3 commits into
mainfrom
mme/use-coagent-performance-tweaks
Jul 28, 2025
Merged

mme merged 3 commits into
mainfrom
mme/use-coagent-performance-tweaks

Conversation

@mme

@mme mme commented Jul 25, 2025 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Improve performance/reduce re-rendering when calling useCoAgent

Checklist

  • I have read the Contribution Guide
  • If the PR changes or adds functionality, I have updated the relevant documentation

Summary by CodeRabbit

  • New Features

    • Improved message handling performance in chat components by introducing a new mechanism for accessing message snapshots.
    • Enhanced support for monitoring user interactions in chat components with new observability hooks, enabling event tracking such as message sent, chat expanded, and minimized (requires a public API key).
  • Documentation

    • Updated documentation for chat components and hooks to include details and examples for the new observability hooks and clarify the requirement for a public API key.

@vercel

vercel Bot commented Jul 25, 2025 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 25, 2025 3:25pm
examples-coagents-ai-travel-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 25, 2025 3:25pm
examples-coagents-research-canvas-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 25, 2025 3:25pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
examples-coagents-ai-researcher-ui ⬜️ Ignored (Inspect) Jul 25, 2025 3:25pm

@coderabbitai

coderabbitai Bot commented Jul 25, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

A new MessagesTap context and provider have been introduced to manage a stable snapshot of chat messages, decoupling message access from the main reactive state. The use-coagent hook and agent execution logic were refactored to use this snapshot. Documentation for several chat components and hooks was updated to detail the new observabilityHooks prop and clarify the requirement for a publicApiKey.

Changes

File(s) Change Summary
src/components/copilot-provider/copilot-messages.tsx Added MessagesTap context, provider, hook, and integrated with CopilotMessages for message snapshotting.
src/components/copilot-provider/copilotkit.tsx Wrapped CopilotMessages with MessagesTapProvider in the internal provider component.
src/hooks/use-coagent.ts Refactored to use useMessagesTap for message retrieval; updated runAgent signature to accept messages array.
src/components/chat/Chat.tsx Updated runAgent invocation to pass current messages array explicitly.
docs/content/docs/reference/components/chat/CopilotChat.mdx Documented observabilityHooks prop, usage example, and publicApiKey requirement.
docs/content/docs/reference/components/chat/CopilotPopup.mdx Documented observabilityHooks prop, usage example, and publicApiKey requirement.
docs/content/docs/reference/components/chat/CopilotSidebar.mdx Documented observabilityHooks prop, usage example, and publicApiKey requirement.
docs/content/docs/reference/hooks/useCopilotChat.mdx Clarified publicApiKey requirement and updated usage examples with provider context.
src/hooks/__tests__/use-coagent-config.test.ts Added Jest mock for useMessagesTap hook to support new message snapshot context in tests.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant CopilotKitInternal
    participant MessagesTapProvider
    participant CopilotMessages
    participant useCoagent
    participant Agent

    App->>CopilotKitInternal: Render
    CopilotKitInternal->>MessagesTapProvider: Wrap children
    MessagesTapProvider->>CopilotMessages: Provide messages tap context
    CopilotMessages->>MessagesTapProvider: Update tap on messages change
    useCoagent->>MessagesTapProvider: useMessagesTap() to get snapshot
    useCoagent->>Agent: runAgent(context, messagesSnapshot, ...)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7b995db and 361eaf0.

📒 Files selected for processing (1)
  • CopilotKit/packages/react-core/src/hooks/__tests__/use-coagent-config.test.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • CopilotKit/packages/react-core/src/hooks/tests/use-coagent-config.test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: Build Images (coagents-qa-native, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-qa-native, ui)
  • GitHub Check: Build Images (next-openai, next-openai)
  • GitHub Check: Build Images (coagents-qa-text, ui)
  • GitHub Check: Build Images (coagents-qa-text, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-routing, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-research-canvas, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-routing, ui)
  • GitHub Check: Build Images (coagents-research-canvas, ui)
  • GitHub Check: Test (20.x)
  • GitHub Check: Test (18.x)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch mme/use-coagent-performance-tweaks

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 generate unit tests to generate unit tests for 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.

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.

@changesets-bot-copilotkit

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 361eaf0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

github-actions Bot commented Jul 25, 2025 •

Copy link
Copy Markdown
Contributor

Preview environments destroyed for this pull request.

@github-actions

github-actions Bot commented Jul 25, 2025 •

Copy link
Copy Markdown
Contributor

Test Results

Status: ✅ Passed (View Run)

Commit: fdb75df

Duration: 292.0s

Total Tests: 33

Pass Rate: 100.0%

Failed Tests: 0

🔍 Detailed Results

coagents-research-canvas

CoAgents Research Canvas (UI) - Local Depenencies

Model Browser Status Video
OpenAI chromium ✅ PASSED -
Anthropic chromium ✅ PASSED -
CrewAI chromium ✅ PASSED -

coagents-qa-native

CoAgents QA Native (UI) - Local

Model Browser Status Video
OpenAI chromium ✅ PASSED -
Anthropic chromium ✅ PASSED -

coagents-qa-text

CoAgents QA Text (UI) - Local

Model Browser Status Video
OpenAI chromium ✅ PASSED -
Anthropic chromium ✅ PASSED -
OpenAI (LGC Python) chromium ✅ PASSED -
Anthropic (LGC Python) chromium ✅ PASSED -
OpenAI (LGC JS) chromium ✅ PASSED -
Anthropic (LGC JS) chromium ✅ PASSED -

coagents-routing

CoAgents Routing (UI) - Local

Model Browser Status Video
OpenAI chromium ✅ PASSED -
Anthropic chromium ✅ PASSED -

next-openai

Next OpenAI - Self Hosted

Model Browser Status Video
OpenAI chromium ✅ PASSED -
Anthropic chromium ✅ PASSED -
LangChain (OpenAI) chromium ✅ PASSED -
Groq chromium ✅ PASSED -

@mme
mme merged commit 5300e68 into main Jul 28, 2025
@mme
mme deleted the mme/use-coagent-performance-tweaks branch July 28, 2025 12:59
@coderabbitai coderabbitai Bot mentioned this pull request Oct 22, 2025
johannhartmann pushed a commit to johannhartmann/CopilotKit that referenced this pull request Oct 31, 2025
johannhartmann pushed a commit to johannhartmann/CopilotKit that referenced this pull request Oct 31, 2025

This branch was successfully deployed

3 active deployments
Preview – docs — 361eaf04 Deployed Jul 25, 2025 by vercel[bot]
Preview – examples-coagents-research-canvas-ui — 361eaf04 Deployed Jul 25, 2025 by vercel[bot]
Preview – examples-coagents-ai-travel-app — 361eaf04 Deployed Jul 25, 2025 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant