Skip to content

Conversation

eyurtsev
Copy link
Collaborator

@eyurtsev eyurtsev commented Jul 16, 2025

  • Adds support for using pydantic base model for the swarm state.

@eyurtsev eyurtsev self-assigned this Jul 16, 2025
@eyurtsev eyurtsev requested a review from Copilot July 16, 2025 17:46
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for using Pydantic BaseModel as the state schema for swarm functionality, extending beyond the existing dictionary-based state approach. The changes enable developers to define typed state schemas using Pydantic models while maintaining backward compatibility.

  • Introduces a generic _get_field utility function to handle field access across different state types (dict, dataclass, Pydantic)
  • Updates the handoff tool implementation to work with both dictionary and Pydantic-based state schemas
  • Adds comprehensive test coverage for the new Pydantic state functionality

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
langgraph_swarm/handoff.py Adds _get_field utility and updates handoff tool to support multiple state types
tests/test_swarm.py Adds test case demonstrating Pydantic state schema usage with swarm functionality

graph=Command.PARENT,
update={
"messages": state["messages"] + [tool_message],
"messages": [*_get_field(state, "messages"), tool_message],
Copy link
Preview

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The unpacking syntax [*_get_field(state, "messages"), tool_message] could be clearer. Consider using _get_field(state, "messages") + [tool_message] for better readability, especially since the original code used concatenation.

Suggested change
"messages": [*_get_field(state, "messages"), tool_message],
"messages": _get_field(state, "messages") + [tool_message],

Copilot uses AI. Check for mistakes.

@eyurtsev eyurtsev marked this pull request as ready for review July 16, 2025 18:10
@eyurtsev eyurtsev merged commit 51f6374 into main Jul 16, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant