improve: get_state (filter the output in the state).
In fact, the get_input_jsonschema and get_output_jsonschema of langgraph do not use the config parameter. The get_state has been improved to only return the output data, avoiding returning the input and internal state when initializing the thread.
fixed: #2113
Summary by CodeRabbit
-
Refactor
- Improved performance and consistency by centralizing schema key retrieval and filtering to initialization.
- Enhanced reliability of state outputs by ensuring only allowed keys are included based on schema definitions.
⏭️ Changeset Not Required
Latest commit: 2d31b5b25700e718027d596275db87859e71e8ad
No changes in this PR affected the @copilitkit/* packages. Merging this PR will not cause a version bump for any packages.
Changeset is not required for this PR.
Walkthrough
The changes refactor schema key handling in the LangGraphAgent class by initializing input, output, and config schema keys during construction and storing them as instance variables. Methods are updated to use these stored keys for consistent schema-based filtering of input, output, and agent state, ensuring only allowed keys are included.
Changes
| File(s) | Change Summary |
|---|---|
| sdk-python/copilotkit/langgraph_agent.py | Refactored to initialize and store schema keys in constructor; updated methods to use stored keys for filtering; added filter_state_on_schema_keys method; updated get_schema_keys signature and usage. |
Sequence Diagram(s)
sequenceDiagram
participant User
participant LangGraphAgent
participant Graph
User->>LangGraphAgent: Initialize
LangGraphAgent->>Graph: get_input_jsonschema()
LangGraphAgent->>Graph: get_output_jsonschema()
LangGraphAgent->>Graph: get_config_schema()
LangGraphAgent->>LangGraphAgent: Store schema keys
User->>LangGraphAgent: prepare_stream(input, config)
LangGraphAgent->>LangGraphAgent: Filter input/config using stored schema keys
User->>LangGraphAgent: get_state()
LangGraphAgent->>LangGraphAgent: Filter state using output schema keys
LangGraphAgent-->>User: Return filtered state
Assessment against linked issues
| Objective | Addressed | Explanation |
|---|---|---|
| Only output states should be returned by loadAgentState; input/internal states excluded (#2113) | ✅ |
Assessment against linked issues: Out-of-scope changes
No out-of-scope changes found.
📜 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 90ca5ef2eef686d462c44a88591af816f005e9fb and 2d31b5b25700e718027d596275db87859e71e8ad.
📒 Files selected for processing (1)
-
sdk-python/copilotkit/langgraph_agent.py(4 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`{sdk-python/**,sdk-python/copilotkit/crewai/**,sdk-python/copilotkit/openai/**}...
{sdk-python/**,sdk-python/copilotkit/crewai/**,sdk-python/copilotkit/openai/**}: Python SDK and its integrations should be implemented in sdk-python/, with CrewAI agents in sdk-python/copilotkit/crewai/ and OpenAI integrations in sdk-python/copilotkit/openai/
📄 Source: CodeRabbit Inference Engine (.cursor/rules/copilotkit-architecture.mdc)
List of files the instruction was applied to:
-
sdk-python/copilotkit/langgraph_agent.py
`sdk-python/**/*`: Use [sdk-python/] package for developing Python agents
sdk-python/**/*: Use [sdk-python/] package for developing Python agents
📄 Source: CodeRabbit Inference Engine (.cursor/rules/quick-reference.mdc)
List of files the instruction was applied to:
-
sdk-python/copilotkit/langgraph_agent.py
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: CopilotKit/CopilotKit#0
File: .cursor/rules/quick-reference.mdc:0-0
Timestamp: 2025-07-04T14:02:44.738Z
Learning: Applies to CopilotKit/package.json : Review [CopilotKit/package.json] for workspace setup
sdk-python/copilotkit/langgraph_agent.py (1)
Learnt from: CR
PR: CopilotKit/CopilotKit#0
File: .cursor/rules/quick-reference.mdc:0-0
Timestamp: 2025-07-04T14:02:44.738Z
Learning: Applies to sdk-python/copilotkit/agent.py : Check [copilotkit/agent.py] for main agent class when developing Python agents
🧬 Code Graph Analysis (1)
sdk-python/copilotkit/langgraph_agent.py (1)
sdk-python/copilotkit/utils.py (1)
filter_by_schema_keys(1-8)
🔇 Additional comments (6)
sdk-python/copilotkit/langgraph_agent.py (6)
188-192: Schema key initialization looks good and improves performance.Moving schema key calculation to the constructor is a good optimization that avoids recalculating these values multiple times during the agent's lifecycle. The approach is clean and efficient.
264-264: Proper use of the new filtering helper method.The code correctly uses the new
filter_state_on_schema_keysmethod to filter the stream input based on input schema keys, which ensures only allowed input keys are processed.
265-265: Efficient use of pre-stored config schema keys.Using
self.config_schema_keysinstead of recalculating improves performance and maintains consistency with the new approach.
614-614: Correct filtering of state in get_state method.The filtering ensures that only output schema keys are included in the returned state, which aligns perfectly with the PR objective to "filter the output in the state" and prevents returning input and internal state information.
630-660: Method signature change is appropriate and well-implemented.The removal of the
configparameter fromget_schema_keysis correct based on the PR objectives noting that LangGraph's schema methods don't utilize the config parameter. The parameterless calls toget_input_jsonschema()andget_output_jsonschema()are properly implemented.
661-667: Well-implemented filtering helper method with proper error handling.The
filter_state_on_schema_keysmethod is well-designed with:
- Proper type hints using
Literalfor schema_type- Dynamic attribute access using
getattr- Safe fallback to original state on exceptions
- Consistent error handling pattern
✨ 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.
🪧 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
@coderabbitaiin a new review comment at the desired location with your query. Examples:-
@coderabbitai explain this code block. -
@coderabbitai modularize this function.
-
- PR comments: Tag
@coderabbitaiin 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 pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai generate docstringsto generate docstrings for this PR. -
@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere 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.
@angular-moon is attempting to deploy a commit to the CopilotKit Team on Vercel.
A member of the Team first needs to authorize it.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| registry | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Jul 8, 2025 9:00am |
Thanks for the contribution Due to lack of setup on our side, I will have to recreate the PR in order for our tests and workflow to run. I'll try to get to it soon so this can be added quickly