microsoft / promptflow

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

How do you set a persistent variable in Prompt Flow? #1693

Closed comoqueres closed 3 months ago

comoqueres commented 4 months ago

Is your feature request related to a problem? Please describe. It's not related to a problem. This is more of a question.

Describe the solution you'd like I'm building a flow to be able to handle several use cases. So when the use case is defined, I'd like to lock that in so only the nodes associated with that flow/use case are active. Is there a way to do that?

Describe alternatives you've considered I've been thinking of ways to pass the use case information back through the flow without a persistent variable, but have not had luck.

Additional context Right now every time the AI has a round in the chat it reassesses what use case it's talking about.

brynn-code commented 4 months ago

@comoqueres Hi, thanks for the feedback, could you please elaborate more about your scenario? We are not quit get the point, what's the meaning by lock nodes for specific use case? It would be better if you are able to provide a dummy example.

comoqueres commented 4 months ago

Sure. The initial flow and prompts are all about understanding what the user wants to do. Do they want help writing an email? help with code? help with research? Because what I'm building out will have business processes that are unique to my business to help them do this. The prompts will be highly specific. As you can see in the flow, there is a use_case_email_chat prompt. That is the prompt that will be fed to the LLM that will help the user create an email

Screenshot 2024-01-10 at 8 46 40 PM

The problem comes in here. Once the clarify_use_case prompt has identified the use case, I don't want it to try to identify the use case any more. I just want a variable to be set to "email" so I can deactivate "clarify_use_case." Because what happens is midway through an email chat, the llm will think the user wants to do something else, or forgets that the user and ai are writing an email and will go to the welcome prompt again.

I think the solution is a persistent variable that is set, and only unset when a particular string passes through the chat. And I haven't found the ability to do this.

brynn-code commented 4 months ago

Thanks for your patience, please see if the following description is correct, we are trying to simplify your requirements to:

  1. The flow will be executed multiple times.
  2. Only the first time requires run 'classify_use_case'
  3. After use case classified, the afterwards flow run will bypass 'classify' step and run with determined case type.
brynn-code commented 4 months ago

And how will you trigger the flow run with input, by deploying the flow and calling the endpoint?

comoqueres commented 4 months ago

Hi Brynn. Thank you so much for the help.

The three requirements you stated are correct.

Deployment methodology has yet to be decided. It is likely, yes, that we will deploy the flow and call the endpoint. Perhaps a browser will be a place where we can have a persistent variable?

Ideally we could have this capability in prompt flow in azure itself, as I need to show my business leaders the proof of concept, but if that's a limitation then I'll just have to manage. :)

brynn-code commented 4 months ago

Hi @comoqueres, we have a solution for your case:

  1. Link the 'calssify_use_case' step as another flow output
  2. After the first call, you could get the 'classify' step output 'email' from flow output, and you could pass it as flow input, add an 'IF' to the 'classify' step, if it received previous step execution result from flow input, then just skip.

Example inputs for the first call: {"flow_inputs": ....} Example inputs for the second call: {"flow_inputs": ...., "user_intent": "email"}

Prompt flow will not persist any states now, it's a stateless mechanism, for your scenario, please see if the above solution is a possible approach.

comoqueres commented 4 months ago

I'm getting a circular dependency error.

the "IF" that I'm programming in is the activate config, when string equals "none"

How would you recommend configuring this so there is no circular dependency?

Invalid node definitions found in the flow graph. Node circular dependency has been detected among the nodes in your flow. Kindly review the reference relationships for the nodes ['answer_the_question_with_context', 'classify_use_case', 'classify_use_case_chat', 'combine_prompts', 'define_use_case', 'use_case_email_chat'] and resolve the circular reference issue in the flow.

Screenshot 2024-01-15 at 12 23 08 AM
brynn-code commented 4 months ago

image

I suppose there is a line should be removed (I marked 'x' on the graph), and another line should be added. I add more detail steps on the graph.

As you link the 'define_use_case' output to outputs, then you are able to get the 'use_case': 'email' in outputs ( I just assume the relevant flow output named use_case), and the next time you put the 'use_case': 'email' as a flow input to classify step and define step, as you have got the user_case from flow inputs, the classify step can be skipped, and define step just return the use_case as output directly, so you could move on the next step with use_case.

comoqueres commented 4 months ago

I created a new node and input for is "null" or "none" then set use case status set to "not set" Are you all going to build an "Is Not" into your string logic?

I think that's the last piece of logic I need.

Screenshot 2024-01-15 at 11 49 37 AM Screenshot 2024-01-15 at 11 51 27 AM Screenshot 2024-01-15 at 11 51 54 AM
brynn-code commented 4 months ago

We don't have the 'Is not' condition for now, but I think it's not a blocker thing, you could use a specific string for that, for example, just check if the 'use_case' == 'not set' should be ok, at the first time you are calling promptflow, you could just pass 'use_case' = 'not set', and the later times you pass 'use_case' = 'email' or something else.

github-actions[bot] commented 3 months ago

Hi, we're sending this friendly reminder because we haven't heard back from you in 30 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 7 days of this comment, the issue will be automatically closed. Thank you!