Skip to content

Commit bed63cb

Browse files
authored
Fix CrewAI pydantic state issues (CopilotKit#1487)
1 parent d3e73b5 commit bed63cb

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

sdk-python/copilotkit/crewai/crewai_sdk.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ async def copilotkit_emit_state(state: Any) -> Literal[True]:
143143
"""
144144
execution = get_context_execution()
145145

146+
state_as_dict = state.model_dump() if isinstance(state, BaseModel) else state
146147
state = {
147-
k: v for k, v in state.items() if k not in ["messages"]
148+
k: v for k, v in state_as_dict.items() if k not in ["messages", "copilotkit"]
148149
}
149150

150151
await queue_put(

sdk-python/copilotkit/runloop.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,11 @@ def predict_state(
335335
state=json.dumps(
336336
_filter_state(
337337
state={
338-
**execution["state"],
338+
**(
339+
execution["state"].model_dump()
340+
if isinstance(execution["state"], BaseModel)
341+
else execution["state"]
342+
),
339343
**execution["predicted_state"]
340344
}
341345
)

0 commit comments

Comments
 (0)