Skip to content

feat: integrate AG-UI LangGraph agent in CopilotKit - #1968

Merged
ranst91 merged 6 commits into
mainfrom
feat/cpk-langgraph-agui
Jun 12, 2025
Merged

ranst91 merged 6 commits into
mainfrom
feat/cpk-langgraph-agui

Conversation

@ranst91

@ranst91 ranst91 commented Jun 10, 2025 •

Copy link
Copy Markdown
Contributor

This PR introduces the AGUI LangGraph agent in CopilotKit

Summary by CodeRabbit

  • New Features

    • Introduced a new CopilotKit LangGraph agent, enabling enhanced event handling and state management for agent interactions.
    • Added support for configuring multiple named agents with shared deployment URLs in the demo viewer.
  • Improvements

    • Updated the demo viewer's recipe preferences to use a strongly typed set of special preferences for improved clarity and selection.
  • Dependencies

    • Added new dependencies to support LangGraph integration and client functionality.
    • Updated CopilotKit package versions to the latest feature branch.
  • Documentation

    • Updated documentation to reflect the use of the new AGUI agent.

@vercel

vercel Bot commented Jun 10, 2025 •

Copy link
Copy Markdown
Contributor

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

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

@coderabbitai

coderabbitai Bot commented Jun 10, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The changes introduce a CopilotKit-specific LangGraph agent by adding a new dependency, implementing a custom agent class with specialized event handling, and updating API usage to support multiple named agents. Type safety and enum usage are improved in the demo viewer. Package versions are updated, and documentation and configuration files are revised accordingly.

Changes

Files / Grouped Paths Change Summary
CopilotKit/packages/runtime/package.json, examples/demo-viewer/package.json Added @ag-ui/langgraph and @ag-ui/client dependencies; updated @copilotkit package versions to a feature branch.
CopilotKit/packages/runtime/src/lib/index.ts Exported all from the new LangGraph agent module.
CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts Added new LangGraphAgent class extending AGUILangGraphAgent with CopilotKit-specific event handling, state merging, and intermediate state prediction signaling. Introduced related types and enums.
examples/demo-viewer/agent/demo/langgraph_shared_state/page.tsx Replaced string-based dietary options with a strongly typed SpecialPreferences enum; updated state and handler logic to use the enum; renamed properties and updated UI references accordingly.
examples/demo-viewer/src/app/api/copilotkit/route.ts Switched from a single remote agent endpoint to multiple named LangGraphAgent instances using the new agent class and deployment URL, updating the API handler logic.
CopilotKit/.changeset/modern-vans-perform.md Added a changeset describing the new LangGraph agent feature and documentation update.
examples/demo-viewer/agent/pyproject.toml Added a [project] section with name and version fields alongside the existing [tool.poetry] section.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API_Route
    participant CopilotRuntime
    participant LangGraphAgent
    participant AGUILangGraphAgent

    Client->>API_Route: POST /api/copilotkit?langgraph=true
    API_Route->>CopilotRuntime: Initialize with named agents (LangGraphAgent instances)
    API_Route->>LangGraphAgent: Run agent (input, metadata)
    LangGraphAgent->>AGUILangGraphAgent: Superclass run logic
    AGUILangGraphAgent-->>LangGraphAgent: Event stream
    LangGraphAgent->>LangGraphAgent: Custom event dispatching, state merging, intermediate state prediction
    LangGraphAgent->>API_Route: Stream processed events
    API_Route->>Client: Respond with event stream
Loading

Suggested reviewers

  • mme
  • ataibarkai
  • suhasdeshpande

📜 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 bcdd5ff and 2253b17.

⛔ Files ignored due to path filters (2)
  • CopilotKit/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • examples/demo-viewer/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (8)
  • CopilotKit/.changeset/modern-vans-perform.md (1 hunks)
  • CopilotKit/packages/runtime/package.json (1 hunks)
  • CopilotKit/packages/runtime/src/lib/index.ts (1 hunks)
  • CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts (1 hunks)
  • examples/demo-viewer/agent/demo/langgraph_shared_state/page.tsx (5 hunks)
  • examples/demo-viewer/agent/pyproject.toml (1 hunks)
  • examples/demo-viewer/package.json (1 hunks)
  • examples/demo-viewer/src/app/api/copilotkit/route.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • CopilotKit/.changeset/modern-vans-perform.md
  • examples/demo-viewer/package.json
  • CopilotKit/packages/runtime/src/lib/index.ts
  • examples/demo-viewer/agent/pyproject.toml
  • CopilotKit/packages/runtime/package.json
  • examples/demo-viewer/src/app/api/copilotkit/route.ts
  • examples/demo-viewer/agent/demo/langgraph_shared_state/page.tsx
🧰 Additional context used
🪛 Biome (1.9.4)
CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts

[error] 44-46: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test (18.x)
  • GitHub Check: Test (20.x)
✨ 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:

‼️ 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 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 8

🧹 Nitpick comments (4)
CopilotKit/packages/runtime/package.json (1)

53-53: Add new dependency for LangGraph integration
Dependency @ag-ui/langgraph is required by the new LangGraphAgent implementation and correctly added here.

Consider adding @ag-ui/langgraph to peerDependencies (>=0.0.1) to align with the other AG-UI packages and enforce consistent versioning for consumers.

docs/content/docs/(root)/guides/backend-actions/langgraph-platform-endpoint.mdx (1)

62-80: Update snippet to use new agents config object
The example correctly shows how to instantiate LangGraphAgent within the agents map.

In the import block, ensure there’s a comma after LangGraphAgent for valid TS syntax:

-import {
-    CopilotRuntime,
-    LangGraphAgent  // [!code highlight]
-    // ...
-} from "@copilotkit/runtime";
+import {
+    CopilotRuntime,
+    LangGraphAgent,  // [!code highlight]
+    // ...
+} from "@copilotkit/runtime";

Also verify that the backtick fences and MDX code markers render correctly.

docs/content/docs/coagents/tutorials/ai-travel-app/step-4-integrate-the-agent.mdx (1)

73-87: Self-Hosted snippet: ensure valid import and config syntax
The Self-Hosted example correctly replaces the old remoteEndpoints pattern with agents.

  • Add a trailing comma after LangGraphAgent in the import block.
  • Double-check that the removed const runtime = new CopilotRuntime(); and the new instantiation block render as intended in MDX.
-import { CopilotRuntime, LangGraphAgent } from '@copilotkit/runtime'; // [!code ++]
+import { CopilotRuntime, LangGraphAgent, } from '@copilotkit/runtime'; // [!code ++]
examples/demo-viewer/agent/demo/langgraph_shared_state/page.tsx (1)

288-288: Remove debug console.log statement.

Debug statements should be removed before merging to production.

-  console.log(recipe)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a188b4f and 1ce80a1.

⛔ Files ignored due to path filters (1)
  • CopilotKit/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (9)
  • CopilotKit/packages/runtime/package.json (1 hunks)
  • CopilotKit/packages/runtime/src/lib/index.ts (1 hunks)
  • CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts (1 hunks)
  • docs/content/docs/(root)/guides/backend-actions/langgraph-platform-endpoint.mdx (1 hunks)
  • docs/content/docs/coagents/troubleshooting/common-issues.mdx (2 hunks)
  • docs/content/docs/coagents/tutorials/ai-travel-app/step-4-integrate-the-agent.mdx (2 hunks)
  • docs/snippets/self-hosting-remote-endpoints.mdx (2 hunks)
  • examples/demo-viewer/agent/demo/langgraph_shared_state/page.tsx (5 hunks)
  • examples/demo-viewer/agent/pyproject.toml (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
examples/demo-viewer/agent/demo/langgraph_shared_state/page.tsx (2)
examples/demo-viewer/agent/demo/langgraph_shared_state/agent.py (1)
  • SpecialPreferences (33-43)
examples/demo-viewer/agent/demo/crewai_shared_state/agent.py (1)
  • Recipe (106-115)
CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts (1)
registry/registry/quickstarts/mcp-starter/utils/mcp-client.ts (1)
  • tools (115-234)
🪛 Biome (1.9.4)
CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts

[error] 40-42: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

🪛 GitHub Actions: Quality
CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts

[warning] 1-1: Prettier formatting check failed. Code style issues found in this file. Run Prettier with --write to fix.

⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: Build Images (next-openai, next-openai)
  • GitHub Check: Build Images (coagents-routing, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-qa-native, ui)
  • GitHub Check: Build Images (coagents-qa-text, ui)
  • GitHub Check: Build Images (coagents-qa-text, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-qa-native, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-research-canvas, ui)
  • GitHub Check: Build Images (coagents-routing, ui)
  • GitHub Check: Build Images (coagents-research-canvas, agent, python, local-deps)
  • GitHub Check: Test (20.x)
  • GitHub Check: Test (18.x)
🔇 Additional comments (10)
CopilotKit/packages/runtime/src/lib/index.ts (1)

11-11: Expose the new LangGraphAgent in the public API
Great addition—re-exporting ./runtime/langgraph/langgraph-agent makes LangGraphAgent available to end users.

docs/content/docs/coagents/tutorials/ai-travel-app/step-4-integrate-the-agent.mdx (1)

18-22: Clarify registration step
The updated intro clearly signals that you will register an agent and then wire it up with useCoAgent. The phrasing is concise and matches the new API surface.

docs/content/docs/coagents/troubleshooting/common-issues.mdx (1)

125-134: Documentation correctly shows the new agent registration pattern.

The example properly demonstrates the new approach using the agents object with LangGraphAgent instances.

docs/snippets/self-hosting-remote-endpoints.mdx (2)

11-25: Documentation snippet correctly shows the new pattern.

The Local (LangGraph Studio) tab properly demonstrates the new LangGraphAgent usage.


50-64: LangGraph Platform configuration is consistent.

The example maintains consistency with the Local tab, showing the same agent registration pattern.

examples/demo-viewer/agent/demo/langgraph_shared_state/page.tsx (2)

82-93: Good refactoring to use TypeScript enum for type safety.

The SpecialPreferences enum provides better type safety and matches the Python backend enum values.


98-98: Property rename is consistently applied throughout.

The rename from dietary_preferences to special_preferences is applied consistently across the interface, state, handlers, and UI.

Also applies to: 112-112, 203-215, 352-352, 359-360

CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts (3)

44-140: Event dispatching logic is well-structured.

The implementation properly handles CopilotKit-specific custom events and conditionally filters tool/message events based on metadata flags. The separation of concerns between custom and standard events is clean.


171-179: State merging customization looks good.

The override properly wraps returned tools under the copilotkit.actions key, maintaining compatibility with CopilotKit's expected state structure.


142-143:

Details

❓ Verification inconclusive

Remove @ts-ignore and fix the TypeScript issue properly.

Using @ts-ignore suppresses potentially important TypeScript errors. Consider fixing the underlying type issue instead.

Can you investigate what TypeScript error is being suppressed here and provide a proper fix?


🏁 Script executed:

#!/bin/bash
# Check the parent class definition to understand the type mismatch
ast-grep --pattern 'class AGUILangGraphAgent {
  $$$
  run($_) {
    $$$
  }
  $$$
}'

Length of output: 87


Let’s locate the parent class and inspect its run method signature:


🏁 Script executed:

#!/bin/bash
# 1. Locate the parent class file
parent_file=$(rg -l "class AGUILangGraphAgent" -n . | head -n1)
echo "Parent class file: $parent_file"

# 2. Show the 'run' method signature and surrounding context
rg -n "run" "$parent_file" -A3 -B3

Length of output: 180


We need to inspect the local class and its supertype to see why @ts-ignore was added. Let’s dump the class declaration, its extends, and the run signature in this file, plus search globally for the parent class:


🏁 Script executed:

#!/bin/bash
# File under review
file="CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts"
echo "=== Inspecting $file ==="
rg -n "class " "$file" -n
rg -n "extends " "$file" -n
rg -n "run(" "$file" -A3 -B3

echo
echo "=== Searching for parent class globally ==="
rg -n "AGUILangGraphAgent" -n .

Length of output: 1125


Let’s dump the top of the file to see the import/alias and find the real parent:


🏁 Script executed:

#!/bin/bash
file="CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts"
echo "=== First 60 lines of $file ==="
sed -n '1,60p' "$file"

Length of output: 2407


Align run override with the parent signature instead of using @ts-ignore

Remove the @ts-ignore on line 142 of
CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts
and update the run method to exactly match the parameter and return types of
AGUILangGraphAgent.run(…) from the @ag-ui/langgraph package.

• File: CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts

  • Delete the // @ts-ignore above run(input: RunAgentInput)
  • Adjust the run(...) signature (and its return type) to align with the external AGUILangGraphAgent declaration

Please check the TypeScript definitions in @ag-ui/langgraph (e.g. its .d.ts files) to verify the correct method signature and return type.

Comment on lines +8 to +11
[project]
name = "demo"
version = "0.0.1"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Duplicate project metadata and version mismatch
You've introduced a PEP 621 [project] table with version = "0.0.1" alongside the existing [tool.poetry] version = "0.1.0". This creates conflicting version declarations.

Please remove the redundant [project] table or synchronize the version numbers to avoid build errors and confusion.

🤖 Prompt for AI Agents
In examples/demo-viewer/agent/pyproject.toml around lines 8 to 11, there is a
duplicate project metadata section with conflicting version numbers between the
[project] table and the existing [tool.poetry] section. To fix this, either
remove the redundant [project] table entirely or update its version to match the
version specified in [tool.poetry] to ensure consistency and prevent build
errors.

Comment on lines +236 to +242
'agent-name', new LangGraphAgent({({
deploymentUrl: "https://your-fastapi-endpoint:port",
langsmithApiKey: <langsmith API key>
graphId: 'langgraph.json graph id', // Your previous graphId definition
},
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix syntax error in the code example.

The code example has multiple syntax errors that would confuse users.

Apply this diff to fix the syntax:

-            'agent-name', new LangGraphAgent({({
+            'agent-name': new LangGraphAgent({
               deploymentUrl: "https://your-fastapi-endpoint:port",
-              langsmithApiKey: <langsmith API key>
+              langsmithApiKey: '<langsmith API key>',
               graphId: 'langgraph.json graph id', // Your previous graphId definition
-            },
+            }),
         });
📝 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.

Suggested change
'agent-name', new LangGraphAgent({({
deploymentUrl: "https://your-fastapi-endpoint:port",
langsmithApiKey: <langsmith API key>
graphId: 'langgraph.json graph id', // Your previous graphId definition
},
});
'agent-name': new LangGraphAgent({
deploymentUrl: "https://your-fastapi-endpoint:port",
langsmithApiKey: '<langsmith API key>',
graphId: 'langgraph.json graph id', // Your previous graphId definition
}),
});
🤖 Prompt for AI Agents
In docs/content/docs/coagents/troubleshooting/common-issues.mdx around lines 236
to 241, the code example has syntax errors such as misplaced parentheses and
missing commas. Fix the syntax by properly structuring the object passed to the
LangGraphAgent constructor: remove extraneous parentheses, add missing commas
between properties, and ensure the object and function call are correctly
closed.

Comment on lines +40 to +46
constructor(config: LangGraphAgentConfig) {
super(config);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove unnecessary constructor.

The constructor only calls super without adding any functionality.

-  constructor(config: LangGraphAgentConfig) {
-    super(config);
-  }
📝 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.

Suggested change
constructor(config: LangGraphAgentConfig) {
super(config);
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 40-42: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

🤖 Prompt for AI Agents
In CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts at
lines 40 to 42, the constructor is redundant as it only calls super with the
same config parameter without adding any extra logic. Remove the entire
constructor method to simplify the class definition and rely on the default
constructor behavior.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts (1)

44-46: Remove the unnecessary constructor.

This constructor only calls super(config) without adding any functionality and should be removed to simplify the class definition.

-  constructor(config: LangGraphAgentConfig) {
-    super(config);
-  }
🧰 Tools
🪛 Biome (1.9.4)

[error] 44-46: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

🧹 Nitpick comments (3)
CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts (3)

50-51: Simplify redundant type casting.

The type casting on line 51 is redundant since event is already typed as ProcessedEvents from the parameter.

-      // const event = processedEvent as unknown as CustomEvent;
-      const customEvent = event as unknown as CustomEvent;
+      const customEvent = event as unknown as CustomEvent;

Or better yet, add proper type guards to avoid the need for type assertions.


153-153: Improve null safety for event data access.

The nested optional chaining could be more robust to prevent potential runtime errors.

Consider adding explicit null checks or using a more defensive approach:

-          const event = (processedEvent as RawEvent).event ?? (processedEvent as RawEvent).rawEvent;
+          const rawEventData = processedEvent as RawEvent;
+          const event = rawEventData.event ?? rawEventData.rawEvent;
+          if (!event) return processedEvent;

159-161: Add safety check for metadata access.

The metadata access could benefit from additional null safety to prevent runtime errors.

-          const toolCallUsedToPredictState = event.metadata?.[
-            "copilotkit:emit-intermediate-state"
-          ]?.some(
-            (predictStateTool: PredictStateTool) => predictStateTool.tool === toolCallData?.name,
-          );
+          const toolCallUsedToPredictState = event.metadata?.["copilotkit:emit-intermediate-state"]?.some(
+            (predictStateTool: PredictStateTool) => 
+              predictStateTool?.tool === toolCallData?.name
+          ) ?? false;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1ce80a1 and 59751b0.

📒 Files selected for processing (3)
  • CopilotKit/.changeset/modern-vans-perform.md (1 hunks)
  • CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts (1 hunks)
  • docs/content/docs/coagents/troubleshooting/common-issues.mdx (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • CopilotKit/.changeset/modern-vans-perform.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/content/docs/coagents/troubleshooting/common-issues.mdx
🧰 Additional context used
🧬 Code Graph Analysis (1)
CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts (1)
registry/registry/quickstarts/mcp-starter/utils/mcp-client.ts (1)
  • tools (115-234)
🪛 Biome (1.9.4)
CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts

[error] 44-46: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test (18.x)
  • GitHub Check: Test (20.x)
🔇 Additional comments (1)
CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts (1)

177-189: Well-structured state merging implementation.

The langGraphDefaultMergeState method correctly wraps tools under the copilotkit.actions key while preserving other state properties. The destructuring approach is clean and maintainable.

return true;
}

// @ts-ignore

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Address the TypeScript ignore directive.

The @ts-ignore comment suggests there may be a type incompatibility in the method signature override. This should be resolved properly rather than suppressed.

Please investigate and fix the underlying type issue instead of using @ts-ignore. If the base class method signature is incompatible, consider:

  1. Updating the method signature to match the base class
  2. Using proper type assertions if the override is intentional
  3. Adding proper JSDoc comments explaining why the override is necessary
🤖 Prompt for AI Agents
In CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts at
line 146, remove the @ts-ignore directive by investigating the type
incompatibility causing the error. Fix the method signature to properly match
the base class method it overrides, or if intentional, use correct type
assertions and add JSDoc comments explaining the override rationale. This
ensures type safety without suppressing errors.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
examples/demo-viewer/src/app/api/copilotkit/route.ts (1)

21-29: Consider refactoring agent creation to reduce duplication.

While the explicit agent configuration is functional and clear for a demo, consider extracting the agent creation logic to reduce duplication:

+  const agentNames = [
+    "agentic_chat",
+    "agentic_generative_ui", 
+    "human_in_the_loop",
+    "predictive_state_updates",
+    "shared_state",
+    "tool_based_generative_ui",
+    "no_chat"
+  ];
+  
+  const agents = Object.fromEntries(
+    agentNames.map(name => [name, new LangGraphAgent({ deploymentUrl, graphId: name })])
+  );
+
   runtime = new CopilotRuntime({
-    agents: {
-      "agentic_chat": new LangGraphAgent({ deploymentUrl, graphId: 'agentic_chat' }),
-      "agentic_generative_ui": new LangGraphAgent({ deploymentUrl, graphId: 'agentic_generative_ui' }),
-      "human_in_the_loop": new LangGraphAgent({ deploymentUrl, graphId: 'human_in_the_loop' }),
-      "predictive_state_updates": new LangGraphAgent({ deploymentUrl, graphId: 'predictive_state_updates' }),
-      "shared_state": new LangGraphAgent({ deploymentUrl, graphId: 'shared_state' }),
-      "tool_based_generative_ui": new LangGraphAgent({ deploymentUrl, graphId: 'tool_based_generative_ui' }),
-      "no_chat": new LangGraphAgent({ deploymentUrl, graphId: 'no_chat' })
-    }
+    agents
   });

This would make it easier to maintain the agent list and reduce repetitive code.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 59751b0 and 9c9c873.

📒 Files selected for processing (1)
  • examples/demo-viewer/src/app/api/copilotkit/route.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
examples/demo-viewer/src/app/api/copilotkit/route.ts (1)
CopilotKit/packages/runtime/src/lib/runtime/copilot-runtime.ts (1)
  • CopilotRuntime (276-1217)
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: Build Images (next-openai, next-openai)
  • GitHub Check: Build Images (coagents-qa-native, ui)
  • GitHub Check: Build Images (coagents-qa-text, ui)
  • GitHub Check: Build Images (coagents-qa-native, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-qa-text, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-research-canvas, ui)
  • GitHub Check: Build Images (coagents-routing, ui)
  • GitHub Check: Build Images (coagents-routing, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-research-canvas, agent, python, local-deps)
  • GitHub Check: Test (20.x)
  • GitHub Check: Test (18.x)
🔇 Additional comments (2)
examples/demo-viewer/src/app/api/copilotkit/route.ts (2)

5-5: LGTM! Import addition aligns with new agent integration.

The import of LangGraphAgent is necessary for the new agent configuration approach and aligns with the PR objective of integrating AG-UI LangGraph agent.


19-19: Environment variable naming is clear and follows convention.

The use of LG_DEPLOYMENT_URL environment variable with a sensible fallback to localhost is appropriate for demo purposes.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts (2)

44-46: Redundant constructor still present – remove it

The constructor only delegates to super with the same argument and adds no behaviour. Static analysis already flagged this (noUselessConstructor). Delete the constructor to reduce noise.

🧰 Tools
🪛 Biome (1.9.4)

[error] 44-46: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)


146-147: @ts-ignore hides a real type-mismatch – please fix the signature instead

Suppressing the error masks potential runtime issues and defeats the purpose of strict typing. Align the override with the base class signature (likely run<T extends RunAgentInput>(input: T): Observable<ProcessedEvents>), or perform a proper type assertion.

🧹 Nitpick comments (2)
CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts (2)

48-71: Factor out the three consecutive subscriber.next calls to avoid duplication

The manual message emission repeats the same pattern (START → CONTENT → END). Extracting a small helper (e.g., emitAssistantMessage(messageId, text, raw)) will:

• remove repetition (six nearly-identical objects across message & tool call branches)
• reduce the chance of future inconsistencies (e.g., forgetting to include rawEvent)


74-94: Same duplication pattern for tool calls

As above, emitting START/ARGS/END can be abstracted into emitToolCall(...) to centralise the logic and keep dispatchEvent readable.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9c9c873 and 884030f.

⛔ Files ignored due to path filters (1)
  • CopilotKit/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (11)
  • CopilotKit/.changeset/modern-vans-perform.md (1 hunks)
  • CopilotKit/packages/runtime/package.json (1 hunks)
  • CopilotKit/packages/runtime/src/lib/index.ts (1 hunks)
  • CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts (1 hunks)
  • docs/content/docs/(root)/guides/backend-actions/langgraph-platform-endpoint.mdx (1 hunks)
  • docs/content/docs/coagents/troubleshooting/common-issues.mdx (2 hunks)
  • docs/content/docs/coagents/tutorials/ai-travel-app/step-4-integrate-the-agent.mdx (2 hunks)
  • docs/snippets/self-hosting-remote-endpoints.mdx (2 hunks)
  • examples/demo-viewer/agent/demo/langgraph_shared_state/page.tsx (5 hunks)
  • examples/demo-viewer/agent/pyproject.toml (1 hunks)
  • examples/demo-viewer/src/app/api/copilotkit/route.ts (2 hunks)
✅ Files skipped from review due to trivial changes (3)
  • CopilotKit/packages/runtime/package.json
  • CopilotKit/packages/runtime/src/lib/index.ts
  • docs/content/docs/coagents/tutorials/ai-travel-app/step-4-integrate-the-agent.mdx
🚧 Files skipped from review as they are similar to previous changes (7)
  • CopilotKit/.changeset/modern-vans-perform.md
  • examples/demo-viewer/agent/pyproject.toml
  • examples/demo-viewer/src/app/api/copilotkit/route.ts
  • docs/content/docs/(root)/guides/backend-actions/langgraph-platform-endpoint.mdx
  • docs/content/docs/coagents/troubleshooting/common-issues.mdx
  • docs/snippets/self-hosting-remote-endpoints.mdx
  • examples/demo-viewer/agent/demo/langgraph_shared_state/page.tsx
🧰 Additional context used
🪛 Biome (1.9.4)
CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts

[error] 44-46: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: Build Images (coagents-qa-text, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-qa-text, ui)
  • GitHub Check: Build Images (next-openai, next-openai)
  • GitHub Check: Build Images (coagents-routing, ui)
  • GitHub Check: Build Images (coagents-research-canvas, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-qa-native, ui)
  • GitHub Check: Build Images (coagents-routing, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-qa-native, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-research-canvas, ui)
  • GitHub Check: Test (20.x)
  • GitHub Check: Test (18.x)

type LangGraphAgentConfig,
ProcessedEvents,
} from "@ag-ui/langgraph";
import { Message as LangGraphMessage } from "@langchain/langgraph-sdk/dist/types.messages";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Import uses a private dist/ path – switch to the public export before it breaks

@langchain/langgraph-sdk/dist/types.messages is an internal build artefact, not part of the package’s public API surface. Relying on it is brittle and will break as soon as the package author refactors the build output or ship ESM‐only bundles.

-import { Message as LangGraphMessage } from "@langchain/langgraph-sdk/dist/types.messages";
+import { Message as LangGraphMessage } from "@langchain/langgraph-sdk";
📝 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.

Suggested change
import { Message as LangGraphMessage } from "@langchain/langgraph-sdk/dist/types.messages";
-import { Message as LangGraphMessage } from "@langchain/langgraph-sdk/dist/types.messages";
+import { Message as LangGraphMessage } from "@langchain/langgraph-sdk";
🤖 Prompt for AI Agents
In CopilotKit/packages/runtime/src/lib/runtime/langgraph/langgraph-agent.ts at
line 20, the import statement uses a private internal path
'@langchain/langgraph-sdk/dist/types.messages' which is not part of the public
API and may break in future updates. Change the import to use the public API
export from '@langchain/langgraph-sdk' or another officially supported path
provided by the package to ensure stability and compatibility.

@changesets-bot-copilotkit

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2253b17

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@copilotkit/runtime Minor
@copilotkit/runtime-client-gql Minor
@copilotkit/react-core Minor
@copilotkit/react-textarea Minor
@copilotkit/react-ui Minor
@copilotkit/sdk-js Minor
@copilotkit/shared Minor

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

@github-actions

Copy link
Copy Markdown
Contributor

Previews

Commit SHA: 9f63200

Name Preview
coagents-routing Preview • Preview with LGC Python • Preview with LGC JS
coagents-research-canvas Preview • Preview with LGC Python • Preview with LGC JS
coagents-qa-text Preview • Preview with LGC Python • Preview with LGC JS
coagents-qa-native Preview • Preview with LGC Python • Preview with LGC JS
next-openai Preview

@coderabbitai coderabbitai Bot mentioned this pull request Oct 22, 2025

This branch was successfully deployed

5 active deployments
Preview – docs — 2253b173 Deployed Jun 12, 2025 by vercel[bot]
Preview – examples-coagents-ai-travel-app — 2253b173 Deployed Jun 12, 2025 by vercel[bot]
Preview – copilotkit-feature-viewer — 2253b173 Deployed Jun 12, 2025 by vercel[bot]
Preview – demo-viewer — 2253b173 Deployed Jun 12, 2025 by vercel[bot]
Preview – examples-coagents-research-canvas-ui — 2253b173 Deployed Jun 12, 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