Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prebuilt: allow pydantic model as state schema in create_react_agent #3559

Merged
merged 9 commits into from
Mar 7, 2025

Conversation

ianchi
Copy link
Contributor

@ianchi ianchi commented Feb 23, 2025

Inherited attributes where not considered.
Pydantic model can inherit from other pydantic models. In those cases, inherited attributes where not considered in the check and the code fails.

Copy link

vercel bot commented Feb 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langgraph-docs-preview ⬜️ Ignored (Inspect) Visit Preview Mar 7, 2025 3:06pm

@benjamincburns
Copy link
Collaborator

Thanks for the contribution @ianchi! Would you mind adding a test for this, please?

@ianchi
Copy link
Contributor Author

ianchi commented Feb 25, 2025

Hi @benjamincburns,

I updated the PR and added the test, but I've run into a problem.
It works ok for v1 but it fails for v2.

It seems that the state that the conditional edge receives is not the full state (but the one in the source node?), so it cannot inject it correctly on the tool.

I don't know if this can be "fixed" somehow.
Any ideas/suggestions??

@ianchi
Copy link
Contributor Author

ianchi commented Feb 25, 2025

Hi @benjamincburns,

I found a "fix" for the v2 problem. Anyhow is more of a hack than a good fix.

Although I couldn't find it clearly in the documentation it seems that currently in Langgraph:

  • conditional edges recieve the same state defined in the origin node (either by input, type annotation, or implicit). Type annotation in the conditional function are completely ignored.
  • for tools, the type in the InjectedState annotation is ignored. The available state is injected as is, with no convertion (as is the case in nodes)

I couldn't find any other more elegant solution, given these conditions.

@vbarda vbarda changed the title Allow pydantic model as state schema in executor prebuilt: allow pydantic model as state schema in create_react_agent Mar 6, 2025
@vbarda
Copy link
Collaborator

vbarda commented Mar 6, 2025

@ianchi thanks for the contribution - i pushed a bunch of updates -- let me know if you have any comments, otherwise will merge shortly

@vbarda vbarda merged commit 3183146 into langchain-ai:main Mar 7, 2025
59 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.

4 participants