- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.3k
Closed
Description
@DouweM is looking into this and asked me to write up some notes on the requirements our approach to supporting different output strategies will need to satisfy:
- Until https://peps.python.org/pep-0747/ is supported by type-checkers (specifically, pyright), we can't have output_typeaccept unions directly (i.e., something likeAgent(..., output_type=A | B).- I believe this also is related to why you get a pyright error for output_type=Annotated[A, ...].
- Note that we could introduce a generic type as a workaround for this whose only purpose was to accept type forms as the generic parameter so they can be passed without a type error. I.e., add a generic class called TypeValueand dooutput_type=TypeValue[A | Annotated[B, ...]]or similar. But this is kind of ugly and becomes unnecessary if/when PEP-747 is supported by type-checkers, so 🤷♂ probably not worth it.
 
- I believe this also is related to why you get a pyright error for 
- We need to support using callables as the way to specify the output schema and call it:
- This is important because if you plan to call a function with the output of a tool call, and the function can error, you want the error to go straight back to the model rather than needing to re-call the model, etc.
- The return type of the callable should be the return type of the agent run. (I.e., it should be compatible with the value of the second generic parameter to Agent.)
- ToolOutputneeds to support callables. (I already have an open draft PR for this, but it needs to be finished.)
- New forms of output should also support callables. In particular, even if I'm using response_format or just parsing the content directly, I should be able to use that as the input to a callable and go back to the model if the call fails. And I should not need to manually define a struct with the same fields as the callable, and the output of the callable should be the type
 
- We need a way to provide a list of ToolOutput(forX=Tool, etc.) as a way to more explicitly control precisely what outputs the model can produce. In particular, this gives a way to useToolOutput(type_=str)alongside other tool outputs, and a way to set the tool name for each. It also gives a way to use ananyOfJSON schema as the parameters schema for a tool call. (Some/most models may not support this today, but there's nothing wrong with it in principle.)- Note that it probably doesn't make sense to support a list of ResponseFormatOutputorContentOutputstrategies (or whatever we choose to call them) since there isn't a good mechanism to specify which one is being used. But I'd be open to it if we did come up with such a mechanism. (At least for content output, it's more obvious how this could be done, but I'm not sure it's necessary.)
 
- Note that it probably doesn't make sense to support a list of 
Eventually, I think we need a better native agent handoff, which is in many ways like a callable ToolOutput where the call is the relevant agent.run method. Maybe allowing an agent as an output strategy is enough, I'm not sure. (Maybe it requires some care to get multi-agent streaming to work nicely across handoffs.) But I wouldn't get too caught up on this now unless it's obvious how it could/should work.
nguyenth-sieuviet and arbitropy
Metadata
Metadata
Assignees
Labels
No labels