Repository navigation
fix: enable resolving of langgraph agents when cpk starts - #2029
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
|
Warning Rate limit exceeded@ranst91 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 17 minutes and 14 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (7)
## Walkthrough
The changes unify agent discovery and state loading in the CopilotRuntime, enabling support for both remote endpoints and local AGUI agents. New methods for agent discovery are introduced, and the state loading logic is refactored to handle various agent types consistently. Internal logic in the resolver is updated to use the new unified agent retrieval.
## Changes
| File(s) | Change Summary |
|------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|
| .../runtime/src/graphql/resolvers/state.resolver.ts | Refactored `loadAgentState` usage to utilize unified agent discovery via `getAllAgents`, updated agent existence check logic. |
| .../runtime/src/lib/runtime/copilot-runtime.ts | Added `getAllAgents` and `discoverAgentsFromAgui` methods, refactored `loadAgentState` for unified agent state loading and error handling. |
## Sequence Diagram(s)
```mermaid
sequenceDiagram
participant Client
participant StateResolver
participant CopilotRuntime
participant RemoteEndpoint
participant AGUIAgent
Client->>StateResolver: Request agent state (agentName, threadId)
StateResolver->>CopilotRuntime: getAllAgents()
CopilotRuntime->>RemoteEndpoint: discoverAgentsFromEndpoints()
CopilotRuntime->>AGUIAgent: discoverAgentsFromAgui()
CopilotRuntime-->>StateResolver: Combined agents list
StateResolver->>CopilotRuntime: loadAgentState(threadId, agentName)
CopilotRuntime->>CopilotRuntime: Find agent in combined list
alt Agent is remote endpoint
CopilotRuntime->>RemoteEndpoint: Fetch state (HTTP POST)
else Agent is AGUI agent
CopilotRuntime->>AGUIAgent: Fetch thread state
end
CopilotRuntime-->>StateResolver: Agent state
StateResolver-->>Client: Return statePossibly related PRs
Suggested labels
Suggested reviewers
|
8db5426 to
fd6efde
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
CopilotKit/.changeset/hip-ghosts-drum.md(1 hunks)CopilotKit/packages/runtime/src/graphql/resolvers/state.resolver.ts(1 hunks)CopilotKit/packages/runtime/src/lib/runtime/copilot-runtime.ts(5 hunks)
✅ Files skipped from review due to trivial changes (1)
- CopilotKit/.changeset/hip-ghosts-drum.md
🚧 Files skipped from review as they are similar to previous changes (1)
- CopilotKit/packages/runtime/src/graphql/resolvers/state.resolver.ts
🧰 Additional context used
🪛 Biome (1.9.4)
CopilotKit/packages/runtime/src/lib/runtime/copilot-runtime.ts
[error] 1010-1010: This code is unreachable
... because either this statement will throw an exception, ...
... this statement will throw an exception, ...
... this statement will throw an exception, ...
... this statement will return from the function, ...
... this statement will throw an exception, ...
... this statement will throw an exception, ...
... this statement will throw an exception, ...
... this statement will return from the function, ...
... or this statement will return from the function beforehand
(lint/correctness/noUnreachable)
🪛 GitHub Actions: Quality
CopilotKit/packages/runtime/src/lib/runtime/copilot-runtime.ts
[warning] 1-1: Prettier formatting check failed. Run Prettier with --write to fix code style issues.
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Test (20.x)
- GitHub Check: Test (18.x)
🔇 Additional comments (6)
CopilotKit/packages/runtime/src/lib/runtime/copilot-runtime.ts (6)
87-87: LGTM: Clean import additionThe import for
LangGraphAgentis properly added to support the new unified agent discovery functionality.
331-342: Good deprecation handling with clear migration guidanceThe deprecation warning provides clear guidance to users about migrating from LangGraph Platform remote endpoints to the new
agentsproperty. The commented TODO section suggests future work for validating agent imports.
783-790: Excellent unified agent discovery implementationThe method efficiently uses
Promise.allfor concurrent execution and properly combines results from both endpoint-based and AGUI-based agent discovery.
919-925: Improved agent discovery using unified methodGood refactoring to use the new
getAllAgentsmethod for consistent agent discovery across different agent types.
926-966: Clean CopilotKit endpoint handlingThe refactored logic for handling CopilotKit endpoints is well-structured with proper error handling and response formatting.
968-1009: Well-structured LangGraph client initialization and state handlingThe unified approach to handle both LangGraphPlatform endpoints and AGUI agents through a common client interface is a good architectural improvement. The error handling and response formatting are consistent.
| }; | ||
| } | ||
|
|
||
| throw new Error(`Agent: ${agent.name} could not be resolved`); |
There was a problem hiding this comment.
Remove unreachable code
Static analysis correctly identified this line as unreachable. All code paths above either return or throw exceptions, making this statement unreachable.
- throw new Error(`Agent: ${agent.name} could not be resolved`);This line should be removed as it's unreachable due to the preceding conditional logic that handles all possible cases.
📝 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.
| throw new Error(`Agent: ${agent.name} could not be resolved`); |
🧰 Tools
🪛 Biome (1.9.4)
[error] 1010-1010: This code is unreachable
... because either this statement will throw an exception, ...
... this statement will throw an exception, ...
... this statement will throw an exception, ...
... this statement will return from the function, ...
... this statement will throw an exception, ...
... this statement will throw an exception, ...
... this statement will throw an exception, ...
... this statement will return from the function, ...
... or this statement will return from the function beforehand
(lint/correctness/noUnreachable)
🤖 Prompt for AI Agents
In CopilotKit/packages/runtime/src/lib/runtime/copilot-runtime.ts at line 1010,
the throw statement is unreachable because all preceding code paths either
return or throw exceptions. Remove this unreachable throw statement to clean up
the code and avoid confusion.
| const aguiAgent = graphqlContext._copilotkit.runtime.agents[agent.name] as LangGraphAgent | ||
| if (!aguiAgent) { | ||
| throw new Error(`Agent: ${agent.name} could not be resolved`) | ||
| } | ||
| // @ts-expect-error -- both clients are the same | ||
| client = aguiAgent.client | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Improve type safety in agent resolution
The current implementation uses type casting and accessing potentially undefined properties, which could lead to runtime errors.
- const aguiAgent = graphqlContext._copilotkit.runtime.agents[agent.name] as LangGraphAgent
- if (!aguiAgent) {
- throw new Error(`Agent: ${agent.name} could not be resolved`)
- }
- // @ts-expect-error -- both clients are the same
- client = aguiAgent.client
+ const aguiAgent = graphqlContext._copilotkit.runtime.agents[agent.name];
+ if (!aguiAgent || !(aguiAgent instanceof LangGraphAgent)) {
+ throw new Error(`Agent: ${agent.name} could not be resolved or is not a LangGraphAgent`)
+ }
+ client = aguiAgent.client;📝 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.
| const aguiAgent = graphqlContext._copilotkit.runtime.agents[agent.name] as LangGraphAgent | |
| if (!aguiAgent) { | |
| throw new Error(`Agent: ${agent.name} could not be resolved`) | |
| } | |
| // @ts-expect-error -- both clients are the same | |
| client = aguiAgent.client | |
| } | |
| const aguiAgent = graphqlContext._copilotkit.runtime.agents[agent.name]; | |
| if (!aguiAgent || !(aguiAgent instanceof LangGraphAgent)) { | |
| throw new Error(`Agent: ${agent.name} could not be resolved or is not a LangGraphAgent`); | |
| } | |
| client = aguiAgent.client; | |
| } |
🤖 Prompt for AI Agents
In CopilotKit/packages/runtime/src/lib/runtime/copilot-runtime.ts around lines
980 to 986, the code uses type casting and directly accesses properties that
might be undefined, risking runtime errors. To fix this, add explicit type
checks to ensure graphqlContext._copilotkit.runtime.agents and the specific
agent exist before accessing them. Replace the type cast with safer type guards
or conditional checks, and handle the case where the agent or client is
undefined by throwing a clear error or returning early. This will improve type
safety and prevent potential runtime exceptions.
fb4f047 to
065c7a3
Compare
🦋 Changeset detectedLatest commit: 065c7a3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Click here if you're a maintainer who wants to add another changeset to this PR |
|
Preview environments destroyed for this pull request. |
Test ResultsStatus: ✅ Passed (View Run) Commit: 97d2b40 Duration: 243.8s Total Tests: 20 Pass Rate: 100.0% Failed Tests: 0 🔍 Detailed Resultscoagents-research-canvasCoAgents Research Canvas (UI) - Local Depenencies
coagents-qa-nativeCoAgents QA Native (UI) - Local
coagents-qa-textCoAgents QA Text (UI) - Local
coagents-routingCoAgents Routing (UI) - Local
next-openaiNext OpenAI - Self Hosted
|
Summary by CodeRabbit
New Features
Improvements