-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[Draft] Add input model to Agent #2393
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
base: main
Are you sure you want to change the base?
Conversation
@strawgate Thanks for looking into this! I still like the idea conceptually, but the number of places the new generic parameter now needs to be accounted for gives me pause, so I don't think we should do this unless it clearly enables new usage patterns and workarounds are clearly insufficient. I feel like how complex a class feels scales much faster than linearly with the number of generic parameters, so 3 is much worse than 2, not just 50% worse, especially since most users likely won't actually need to use this, but would see it in their IDE etc. Looking back at your issue:
I feel like it would work almost as well to make the deps type itself a dataclass generic in the input type, and then use I was also thinking of this feature in context of handoffs where the parent agent will need to know what type its sub-agent expects, but that could reasonably be worked around with something like I could also imagine a new Agent subclass that takes an input object in its The other concern is that if we add this to the main Curious to hear your thoughts. It'd be great to see specific examples of use cases that are hard-to-impossible to implement using one of these workarounds, to convince ourselves it's worth the extra generic param. |
I felt the same way making the PR, not only that but the ordering of the generics is a bit unfortunate too....
Handoffs are a good example of a use-case, which is basically just another way of exposing the agent as a tool. Unfortunately, I think having the caller of the agent determine the input_type puts the information in the wrong place. I think the key items here are 1) availability in the runcontext (not just compilation into instructions) and 2) the ability to provide the model to the agent in lieu of a user_prompt. I think given that the only viable path forward is probably to see if we can embed it in the depstype, but that's likely also a big change as you mention -- there's no bounds on deps_type today (it can be a str or Path, etc). I'll noodle on this a bit and maybe experiment with your deps_type suggestion. |
@strawgate Responding to your question from Slack here to keep the context in one place: I was actually not thinking of changing anything in Pydantic AI to do that, just whether in your code a workaround could be to have your own (shared) deps type be generic in the input type of a particular agent. But I don't expect that to actually be sufficient. Here's another idea: In #2225, we'll be introducing an I don't quite like that yet and I'm sure it'd hit some hurdles, but I think it's worth experimenting with whether a new Agent class could help us out here without cluttering the main one. |
re: #2329
Having it be properly typed from the agent init -> run -> runcontext means this is not a small change :(