-
Notifications
You must be signed in to change notification settings - Fork 485
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
Port pydantic_ai.Agent
to using pydantic_graph
#725
Conversation
2e5a20f
to
64a7e6d
Compare
Deploying pydantic-ai with
|
Latest commit: |
2e37316
|
Status: | ✅ Deploy successful! |
Preview URL: | https://b595f6c9.pydantic-ai.pages.dev |
Branch Preview URL: | https://dmontagu-graph-agent.pydantic-ai.pages.dev |
a064ead
to
fb95046
Compare
64a7e6d
to
4fa40c9
Compare
Nice one, do the normal and stream variants of each node need to be seperate classes? Could a |
Not in principle, but in practice we’re using different vendor APIs for streaming and non-streaming so it doesn’t get as much benefit from unifying the types as you might think. I’m planning to implement a stream_events API using the graph nodes next, which will better demonstrate how to have streaming with an iterator coexist with the usual run in a graph context. |
Also, it would be nice if nodes could define & return abstractions/signatures of other nodes instead of concrete implementations/instances. Because currently this limits their flexibility and re-usability as building blocks. Like for example each "node type" could have a signature (effectively an abstract base class kind of thing), and this is referenced by other nodes, but the actual implementations could be defined/overridden at runtime. So people could plug in their own implementations of these different nodes within the "agent" to customise it's behaviour as required |
@dmontagu ok, I'm just on my phone so haven't looked in detail, but seems like there's still a bit of overlap in functionality, and to me I think it makes more sense to have a single node with a I would've thought that streaming would require a different method API/signature? |
It sounds to me like you want a way to override a node’s behavior; why can’t you just do that by subclassing the node and overriding the run method? If you intend for the node to be extensible in some way, you can include the ways you want it to be extended as methods called inside the run method, and subclasses can override just those methods. |
But then the subclassed node won't be used in place of the original parent node by other nodes that already reference it. This is because each node implementation contains both the node logic as well as the edge / next node configuration coupled together. |
cf39d81
to
5c94b48
Compare
31bee5d
to
fbff76c
Compare
5c94b48
to
0f0434e
Compare
This is an attempt to move the
pydantic_ai.Agent
implementation to be based onpydantic_graph
, so we can get all the various graph utility features "for free".While I think we might want to change some of the behaviors, I have attempted to port the existing implementation to use pydantic_graph with the minimal set of external-facing changes possible.