Repository navigation
fix: only fetch agent state for langgraph agents - #2093
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
WalkthroughThe Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant CopilotRuntime
participant AgentsRegistry
participant LangGraphClient
Caller->>CopilotRuntime: loadAgentState(threadId)
CopilotRuntime->>AgentsRegistry: Retrieve aguiAgent
AgentsRegistry-->>CopilotRuntime: aguiAgent or error
alt aguiAgent found
CopilotRuntime->>CopilotRuntime: Determine endpoint type
alt endpoint is LangGraphPlatform
CopilotRuntime->>LangGraphClient: Instantiate with deploymentUrl, apiKey
else
CopilotRuntime->>CopilotRuntime: Use existing client or null
end
alt client is not null
CopilotRuntime->>LangGraphClient: getState(threadId)
LangGraphClient-->>CopilotRuntime: agentState
else
CopilotRuntime->>CopilotRuntime: agentState = {}
end
else aguiAgent not found
CopilotRuntime->>Caller: Throw error
end
CopilotRuntime-->>Caller: agentState
Possibly related PRs
Suggested labels
Suggested reviewers
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
CopilotKit/packages/runtime/src/lib/runtime/copilot-runtime.ts (1)
1019-1019: Remove unreachable code.This throw statement is unreachable because all execution paths above it either return or throw an exception. This creates dead code that should be removed.
- throw new Error(`Agent: ${agent.name} could not be resolved`);The error handling is already properly covered by the earlier validation at lines 967-969.
🧹 Nitpick comments (1)
CopilotKit/packages/runtime/src/lib/runtime/copilot-runtime.ts (1)
973-985: Good implementation of conditional state fetching, but address TypeScript error properly.The conditional client creation and null-safe state fetching logic correctly implements the PR objective of preventing errors when fetching state for non-langgraph agents. However, the
@ts-expect-errorcomment suggests underlying type compatibility issues.Consider addressing the TypeScript error properly instead of suppressing it:
} else { - // @ts-expect-error -- both clients are the same - client = aguiAgent.client ?? null; + // Ensure type compatibility between client types + client = (aguiAgent.client as LangGraphClient) ?? null; }Alternatively, create a proper type guard or interface to ensure type safety.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
CopilotKit/packages/runtime/src/lib/runtime/copilot-runtime.ts(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
CopilotKit/packages/runtime/src/lib/runtime/copilot-runtime.ts (1)
sdk-python/copilotkit/langgraph_agent.py (1)
LangGraphAgent(85-700)
⏰ Context from checks skipped due to timeout of 90000ms (11)
- GitHub Check: Build Images (coagents-qa-native, agent, python, local-deps)
- GitHub Check: Build Images (coagents-research-canvas, agent, python, local-deps)
- GitHub Check: Build Images (next-openai, next-openai)
- GitHub Check: Build Images (coagents-qa-text, agent, python, local-deps)
- GitHub Check: Build Images (coagents-qa-text, ui)
- GitHub Check: Build Images (coagents-qa-native, ui)
- GitHub Check: Build Images (coagents-research-canvas, ui)
- GitHub Check: Build Images (coagents-routing, agent, python, local-deps)
- GitHub Check: Build Images (coagents-routing, ui)
- GitHub Check: Test (20.x)
- GitHub Check: Test (18.x)
| const aguiAgent = graphqlContext._copilotkit.runtime.agents[agent.name] as LangGraphAgent; | ||
| if (!aguiAgent) { | ||
| throw new Error(`Agent: ${agent.name} could not be resolved`); | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Replace unsafe type assertion with proper type checking.
The type assertion as LangGraphAgent is potentially unsafe and could lead to runtime errors if the agent isn't actually a LangGraphAgent instance. This could cause issues when accessing LangGraphAgent-specific properties later.
- const aguiAgent = graphqlContext._copilotkit.runtime.agents[agent.name] as LangGraphAgent;
+ const aguiAgent = graphqlContext._copilotkit.runtime.agents[agent.name];
if (!aguiAgent) {
throw new Error(`Agent: ${agent.name} could not be resolved`);
}
+
+ // Verify it's a LangGraphAgent if we need LangGraph-specific functionality
+ if (!(aguiAgent instanceof LangGraphAgent)) {
+ throw new Error(`Agent: ${agent.name} is not a LangGraphAgent instance`);
+ }📝 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`); | |
| } | |
| // Early lookup without assertion | |
| const aguiAgent = graphqlContext._copilotkit.runtime.agents[agent.name]; | |
| if (!aguiAgent) { | |
| throw new Error(`Agent: ${agent.name} could not be resolved`); | |
| } | |
| // Verify it's a LangGraphAgent before using lang-graph–specific APIs | |
| if (!(aguiAgent instanceof LangGraphAgent)) { | |
| throw new Error(`Agent: ${agent.name} is not a LangGraphAgent instance`); | |
| } |
🤖 Prompt for AI Agents
In CopilotKit/packages/runtime/src/lib/runtime/copilot-runtime.ts around lines
966 to 969, replace the unsafe type assertion 'as LangGraphAgent' with a proper
type check to ensure the retrieved agent is indeed an instance of
LangGraphAgent. Use a runtime type guard or instanceof check before accessing
LangGraphAgent-specific properties, and throw an error if the type does not
match to prevent runtime errors.
|
Preview environments destroyed for this pull request. |
Test ResultsStatus: ✅ Passed (View Run) Commit: 01e3b14 Duration: 242.2s 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
|
This PR fixes the "eager" state loading, which is still possible for langgraph agents, but not possible for other agents atm, which causes some errors.
Summary by CodeRabbit