How to handle the feedback submitted for a bot response? Is there a common id that intersects both response and feedback ?

Sunjay Varshan 5 Reputation points
2025-03-07T10:42:57.7366667+00:00

I'm using teams toolkit sdk to build a sql chatbot, one of the features is that I want to have is to record the feedback. Though teams toolkit sdk provides a feedback handler it doesn't provide much to work with. I want to be able to know which response the feedback is associated to.
this is the bot.py:

@bot_app.feedback_loop()
async def feedback_loop(_context: TurnContext, _state: TurnState, feedback_loop_data: FeedbackLoopData):
    print(f"Your feedback is:\n{json.dumps(asdict(feedback_loop_data), indent=4)}")
    print("This is from bot.py")
    print(f"Context: {_context}")
    print(f"State: {_state}")
    print(f"Activity: {_context.activity}")
    print(f"Activity Id: {_context.activity.from_property.id}")
    print(f"TurnState: {_context.turn_state}")

Here the feedback is handled by the feedback loop, it keeps track of the reaction of the feedback, feedback text and reply_to_id.
how can I make use of this reply_to_id to identify the user conversation
Here is where the actual conversation logic is :

    async def render_data(self, context: TurnContext, memory: Memory, tokenizer: Tokenizer, maxTokens: int):
        """
        Queries the SQL database using the user-provided input.
        """
        query = memory.get('temp.input')
        if not query:
            return Result('', 0, False)
        print(f"User Query: {query}")
        # Execute the query using LangChain agent
        try:
            sql_query = None
            emp_list = []

            for step in self.agent_executor.stream(
                {"messages": [{"role": "user", "content": query}]},
                stream_mode="values"
            ):
                if "messages" in step:
                    last_message = step["messages"][-1]

                    emp_list.append(step)

                    # Check if a tool was called
                    if "tool_calls" in last_message.additional_kwargs:
                        tool_calls = last_message.additional_kwargs["tool_calls"]
                        
                        for tool_call in tool_calls:
                            if tool_call["function"]["name"] == "sql_db_query":
                                arguments_str = tool_call["function"]["arguments"]
                                arguments_dict = json.loads(arguments_str)
        
                                if "query" in arguments_dict:
                                    sql_query = arguments_dict["query"]
                
            response = emp_list[-1]['messages'][-1].content
            # self.store_chat_in_cosmos(query, sql_query, response,context)
            print("This is from My_data_source")
            print(f"Context: {context}")
            print(f"Activity: {context.activity}")
            print(f"TurnState: {context.turn_state}")
            print(f"Responded: {context.responded}")
            print(f"Agent Response: {response}")


            return Result(self.formatDocument(response), len(response), False) if response else Result('', 0, False)
        except Exception as e:
            print(f"Error querying the database: {e}")
            return Result("", 0, False)

Here the response is actually generated.
I want to know a way to record the response along with the feedback, Even if there is a delay in feedback (meaning more exchanges happened without any feedback) I want to be able to correctly map feedback for the particular response.

Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
3,638 questions
{count} vote

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.