Commit Graph

42 Commits

Author SHA1 Message Date
Martha Schumann 981734fb99 fix: propagate useCopilotReadable context and CopilotKit properties into Python LangGraph agent state
Two silent failures in the Python SDK prevented frontend context from reaching the agent:

1. langgraph_default_merge_state rebuilt copilotkit as {actions} only, dropping the
   useCopilotReadable items the TypeScript runtime had placed in state.copilotkit.context.
2. CopilotKitContext.properties were never forwarded through execute_agent → agent.execute(),
   so <CopilotKit properties={...} /> values never reached state.copilotkit.properties.

Both fields now land cleanly under state["copilotkit"] on every agent invocation.
Also adds tests, a showcase example, and a new docs page.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 18:37:51 -07:00
Jordan Ritter bc4a173751 fix: preserve graph-owned state keys during frontend state merge (#3852)
## Summary
- During frontend state merge in LangGraph agent, preserve keys that are
owned by the graph (not set by the frontend)
- Prevents graph-computed state from being overwritten when frontend
state is merged back

Closes #2893

---
*Split from #3847*
2026-04-14 14:06:10 -07:00
Jordan Ritter de78dfdb68 fix: sanitize NaN/Infinity values in LangGraph state before JSON serialization (#3851)
## Summary
- Add sanitization pass over LangGraph agent state to replace NaN and
Infinity with null before JSON serialization
- Prevents `ValueError: Out of range float values are not JSON
compliant` in Python SDK

Closes #1955

---
*Split from #3847*
2026-04-14 14:06:07 -07:00
Jordan Ritter 76b1d73bb8 fix: convert Pydantic BaseModel instances to dicts before serialization (#2158) (#3816)
## Summary

Fixes #2158

Pydantic `BaseModel` instances in LangGraph agent state are not
serializable by `langchain_dumps`. This adds a recursive
`_serialize_state` helper that converts `BaseModel` instances to dicts
before serialization, preventing crashes when state contains Pydantic
models.

**Additional fixes (second commit):**
- Also applies `_serialize_state` to the `get_state()` code path, which
was missed in the original fix but has the same bug
- Fixes `filter_state_on_schema_keys` returning `None` implicitly when
schema keys are not set (the `except` branch returned `state` but the
non-matching `if` branch did not)
- Adds 17 tests covering `_serialize_state`, `_emit_state_sync_event`,
and `get_state` with Pydantic models

## Merge order note

This PR and #3851 both modify
`sdk-python/copilotkit/langgraph_agent.py`. Both add a helper function
at module level and call it from `_emit_state_sync_event` and
`get_state`. Whichever merges second will need a trivial rebase. No
semantic conflict — the fixes are complementary (this one handles
Pydantic models, #3851 handles NaN/Infinity).

## Test plan

- [x] 17 unit tests covering both code paths
- [x] Red-green verified: `get_state` tests fail without fix, pass with
it
- [x] Existing test suite (test_emit_filtering) still passes
- [x] Verify LangGraph agent with Pydantic BaseModel state serializes
correctly
- [x] Verify non-Pydantic state is unaffected
2026-04-14 14:06:00 -07:00
Jordan Ritter 35705db3c7 fix(sdk-python): update current_graph_state after manual emit to persist across iterations
The _merge_emit_state call merges emitted state with current_graph_state
into manually_emitted_state, but the `continue` statement skips the
later current_graph_state.update(updated_state). Without this update,
the next manual emit merges against stale current_graph_state and loses
keys from the previous emit.

Also guards the update call against non-dict values from _merge_emit_state
to prevent TypeError on edge-case non-dict emits.
2026-04-13 08:29:07 -07:00
Jordan Ritter a559406bee fix: also serialize Pydantic state in get_state() and fix implicit None return
The original fix only covered _emit_state_sync_event but missed the
get_state() code path, which also returns state containing Pydantic
BaseModel instances to callers that will JSON-serialize downstream.

Also fixes filter_state_on_schema_keys returning None implicitly when
schema keys are not set (the except branch returned state but the
non-matching if branch did not).

Adds 17 tests covering _serialize_state, _emit_state_sync_event, and
get_state with Pydantic models (nested, lists, plain dicts, empty).
2026-04-13 08:24:10 -07:00
Jordan Ritter d0b7b6981c fix: sanitize raw event stream to prevent NaN/Infinity in JSON output
The _sanitize_for_json function was applied to state sync events and
get_state responses but not to the raw event stream yielded at line 507.
Events with NaN/Infinity float values in their data payloads would
produce invalid JSON (literal NaN) that downstream parsers cannot handle.
2026-04-13 08:19:35 -07:00
Jordan Ritter 35ee689652 fix: preserve graph-owned state keys during frontend state merge (#2893) 2026-04-12 15:25:10 -07:00
Jordan Ritter 0e57499664 fix: sanitize NaN/Infinity values in LangGraph state before JSON serialization (#1955) 2026-04-12 15:25:03 -07:00
Jordan Ritter eb5b98f296 fix: convert Pydantic BaseModel instances to dicts before langchain_dumps serialization (#2158) 2026-04-12 14:59:36 -07:00
Jordan Ritter ee9e9c37b8 fix(sdk-python): copilotkit_emit_state merges state instead of replacing (#3138)
Sequential emit_state calls with different keys now preserve all keys
in the snapshot. Previously, each call would replace the entire
manually_emitted_state, losing keys from earlier calls.
2026-04-12 13:21:53 -07:00
alexforrestf 8f76efc384 fix(sdk-python): compatibility with langchain v1 (#2633) (#2634) 2025-10-23 15:47:53 -04:00
Ran Shemtov 85e09eea2b fix(sdk-python): preserve state messages on subsequent get_state calls (#2216) 2025-07-23 10:21:38 +02:00
Ran Shemtov cf90f85aad fix: reduce checkpointer calls lg events (#2063) 2025-07-08 14:39:42 +02:00
Ran Shemtov 3f8c575363 fix: time travel regenerate (#2071) 2025-07-01 20:25:12 +02:00
Ran Shemtov c0e799e787 Fix/support langgraph 0.5.0 (#2073) 2025-06-30 23:02:48 +02:00
Suhas Deshpande 1d1c51d2f2 surface every possible errors in clean structured way (#2036) 2025-06-23 15:03:38 -07:00
Ran Shemtov 11b7a29686 fix: use active interrupt from thread instead of saving to global state (python sdk) (#2040) 2025-06-23 14:23:16 +02:00
Ran Shemtov c361a16d31 fix: fix regenerate to rerun tool call on click (#2019) 2025-06-19 18:36:33 +02:00
Ran Shemtov 9bc69d8b99 fix: fix reading and spreading configs in langgraph stream events (#1904) 2025-05-30 11:08:08 +02:00
Nick Stanish 9b26f12ba0 fix:python Invert condition for merge_state deprecation check (#1749) 2025-05-23 13:20:08 -07:00
Ran Shemtov 5f613e667b fix: refrain from overriding graph level config in python sdk (#1773) 2025-05-08 12:10:43 +02:00
Ran Shemtov 742efbb1a8 feat: enable setting langgraph config from ui (#1704) 2025-04-29 17:14:59 +02:00
Ran Shemtov 7a04bd1fd2 fix: langgraph interrupt in chat (#1642) 2025-04-16 16:27:58 +02:00
Ran Shemtov d0e8a1ec5b fix: fix duplicate messages on regenerate (#1613) 2025-04-04 12:08:52 +02:00
Ran Shemtov e652aac4b3 feat: add support for langgraph config schema (#1596) 2025-03-28 18:59:39 +01:00
Ran Shemtov ff58c77595 fix: improve schema fetching for langgraph agent (#1558) 2025-03-26 17:23:11 +01:00
Markus Ecker 082db7a996 Add CrewAI support (#1308)
Co-authored-by: Suhas Deshpande <suhasdeshpande@users.noreply.github.com>
Co-authored-by: Ariel Weinberger <Weinberger.Ariel@gmail.com>
Co-authored-by: Suhas Deshpande <suhas2u@gmail.com>
2025-02-28 12:21:54 +01:00
Ran Shemtov fea916fc92 feat: support input and output schema of langgraph (#1406) 2025-02-24 12:04:40 +01:00
Ran Shemtov cc300f9081 fix: enable usage of async savers by using lg async interface (#1384) 2025-02-17 14:50:22 +01:00
Ran Shemtov 7d061d9e84 feat(configurable): execute langgraph with user config (#1376) 2025-02-17 10:44:43 +01:00
Markus Ecker d49c3517be Fix concurrency issues (#1350) 2025-02-12 16:30:23 +01:00
Ran Shemtov f0e753dad0 fix(interrupt): enable multi type for interrupt value (#1329) 2025-02-11 15:51:43 +01:00
Md Abid Hussain 1a055c9e45 Fix mixing synchronous and asynchronous calls in the LangGraph agent implementation (#1327) 2025-02-11 14:44:34 +01:00
Ran Shemtov 06f9f35405 feat: support message based lg interrupt with convenience function (#1305) 2025-02-06 18:13:05 +01:00
Ran Shemtov 7b3141d3a9 feat: langgraph interrupt hook (#1273) 2025-02-04 17:32:42 +01:00
Markus Ecker 926499bb4e Load agent state (#1251) 2025-01-20 16:53:51 +01:00
Markus Ecker 1b47092b43 CoAgents v0.3 (#1193)
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
Co-authored-by: Tyler Slaton <tyler@copilotkit.ai>
Co-authored-by: Tyler Slaton <54378333+tylerslaton@users.noreply.github.com>
Co-authored-by: Ariel Weinberger <Weinberger.Ariel@gmail.com>
2025-01-07 19:48:51 -06:00
Ran Shemtov 9468014edd fix: fix emitted state being overridden by llm calls (#994)
* fix: fix emitted state being overridden by llm calls

* fix: align state continueity with python sdk implementation
2024-11-29 16:04:06 +01:00
Ran Shemtov 85f781ffed Fix/new streaming system (#990)
* fix: add new langgraph streaming protocol

* fix: go to the next chunk after receiving a manually emitted state

* chore: update all packages

---------

Co-authored-by: Markus Ecker <markus.ecker@gmail.com>
2024-11-28 15:05:39 +01:00
Ran Shemtov f6fab281ae feat: langgraph cloud (#918)
* feat(runtime): rename remoteActions argument to remoteEndpoints

* feat(remote-actions): integrate langgraph-cloud as a remote action for CoAgents

* feat(runtime): rename remoteActions argument to remoteEndpoints

* feat(remote-actions): integrate langgraph-cloud as a remote action for CoAgents

* feat(sdk-js): add SDK for LangGraph JS support

---------

Co-authored-by: Markus Ecker <markus.ecker@gmail.com>
Co-authored-by: Ariel Weinberger <weinberger.ariel@gmail.com>
2024-11-27 13:31:58 +01:00
Ariel Weinberger cd8ff1bdc6 feat(python-sdk): add to monorepo (#908) 2024-11-12 18:59:33 -06:00