django-ai-assistant icon indicating copy to clipboard operation
django-ai-assistant copied to clipboard

Support for reviewing actions before executing them

Open BharatKalluri opened this issue 9 months ago • 1 comments

Not sure if this already exists or if there is an easy way to do this, if yes please do let me know and will close this issue.

I have a use case where I want to build a way for users to type out what they want to do and then execute a batch of actions on the database on behalf of the user. Django AI assistant exactly fits my usecase and is a beautifully implemented library. Thanks for all the hard work!

Would it be possible for me to get a list of actions the assistant has figured out it should do so that the user can either approve or iterate on the prompt to get better more accurate actions?

Thanks!

BharatKalluri avatar Mar 03 '25 10:03 BharatKalluri

Hello, @BharatKalluri! I apologize for the delay in getting back to you.

Thanks for the kind words about django-ai-assistant! Your use case of wanting user approval before executing actions might also be valuable to others. Since the library doesn't have a built-in mechanism to pause execution and present planned tool calls for user approval before they run, this could likely fit as a feature request.


How it works now (simplified):

The assistant uses a LangGraph workflow internally (defined in the AIAssistant.as_graph method). In the workflow:

  1. The Language Model (LLM) decides if it needs to use any tools and specifies which ones (agent node).
  2. A check is performed to see if tools were requested (tool_selector node).
  3. If tools were requested, they are executed immediately (tools node).

There isn't a built-in step between the LLM deciding to use a tool and the tool actually running where user interaction can occur.


Implementing Approval

Adding a "human-in-the-loop" approval step like you described involves interrupting this graph execution, communicating the planned actions back to your application, waiting for user input, and then resuming the graph.

The way to approach this might depend on how you are currently invoking the assistant. Could you share a bit more about your setup?

  • Are you calling the assistant's methods (like assistant.invoke(...) or assistant.run(...)) directly from your own Django views or other Python code?
  • Or are you primarily interacting with the assistant through the built-in API views and potentially the frontend components provided by the library?

Knowing this would help understand the potential integration points and complexity:

  • Direct Calls: You might have more flexibility to intercept the process, potentially by customizing the graph execution or adding wrapper logic around the assistant calls within your own code to manage the approval flow.
  • Built-in API: Implementing this would likely require more significant modifications, potentially involving changes to the API views, handling state across requests, and potentially customizing or extending the AIAssistant class to modify its graph behavior.

While we don't support this out-of-the-box, understanding your specific usage pattern could help explore potential workarounds.

Thanks again for reaching out about this matter!

pamella avatar Apr 09 '25 22:04 pamella