microsoft / promptflow

Build high-quality LLM apps - from prototyping, testing to production deployment and monitoring.
https://microsoft.github.io/promptflow/
MIT License
9.59k stars 878 forks source link

[Feature Request] Chaining/Reuse of Flows #3671

Open AMSDavis opened 3 months ago

AMSDavis commented 3 months ago

Is your feature request related to a problem? Please describe. The problem that we're running up against is flow complexity and reuse. We have situations where we want to be able to build a flow to perform a specific task, but want to reuse this functionality in several other flows as well. Additionally we're quickly running into the issue where we have a complicated flow that is difficult to comprehend, and encapsulating this complexity into a separate flow component would simplify our higher level flows

Describe the solution you'd like I would like a capability to call one flow from another flow, treating the called flow as if it is a tool or functionality similar to other node types in the flow.

This would be a new node type in the flow.diag.yaml specification similar to the "python", "llm", and "prompt" node types. This node type would reference a separate flow similar to how a python script is called, treating it as a function call.

Describe alternatives you've considered

  1. In a similar vein I've considered whether an API call to a deployed endpoint would be sufficient, however this has the drawback of requiring a pre-deployed endpoint in order to be functional. This seems like a separate functionality as well with different maintenance costs and patterns.

  2. Building a python tool wrapper to call the flow. There's an existing (preview) functionality to call a flow as a python function, however this appears more suited for python contexts where we want to load a flow. This seems like it could be an alternative where we could build a promptflow "tool" in python which just calls the functionality to load the promptflow definition and call it, however this would suffer from additional runtime overhead costs (having to run and parse the flow each time the "parent" flow is called rather than just integrating the flow contents directly), and a less seamless integration.

Additional context I'm unclear if there is already a supported solution for code/flow reuse. There seems to be something for "load a flow as a python function" but this isn't exactly what I'm looking to do.

Here's an example of the type of thing I would want to do (purely for example - not trying to do this specifically):

Let's say we want to be able to assist with writing jokes and comedy.

There are several things that we want to be able to do, including (1) checking any jokes that we come up with against known material so that we're hopefully not duplicating another comedian's jokes on accident (2) have an LLM propose a new joke (3) check for the "cleanliness" of a joke (don't want to be writing R-rated jokes for a "PG" crowd) (4) help compose a comedy set.

In almost all cases we're going to want to include check (1) and probably (3). These could be standalone capabilities, but they're also likely to be sub-components if we're asking the LLM to write a new joke or come up with an entire themed set or series of jokes. image

When performing a more complex task like writing an entire set we should be able to call the individual flows rather than needing to duplicate the functionality over and over: image

anuar12 commented 2 months ago

I also have a use case when I run a standard flow first and then a feed the outputs (including some intermediate outputs) to the chat flow.