Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -974,7 +974,7 @@ def Create_Graph_Tool(
|
|
| 974 |
# MAIN ORCHESTRATION WORKFLOW
|
| 975 |
# ============================================================================
|
| 976 |
|
| 977 |
-
def orchestrate_turn(user_input: str, session_id: str = "default") -> str:
|
| 978 |
"""
|
| 979 |
Main orchestration function implementing the redesign workflow.
|
| 980 |
|
|
@@ -1008,9 +1008,12 @@ def orchestrate_turn(user_input: str, session_id: str = "default") -> str:
|
|
| 1008 |
# ====================================================================
|
| 1009 |
step_start = log_step("Step 2: Process user input")
|
| 1010 |
|
| 1011 |
-
#
|
| 1012 |
-
|
| 1013 |
-
|
|
|
|
|
|
|
|
|
|
| 1014 |
|
| 1015 |
# Format history for agents
|
| 1016 |
conversation_history_formatted = "\n".join([
|
|
@@ -1409,7 +1412,7 @@ def generate_response(chat_history, conversation_state):
|
|
| 1409 |
try:
|
| 1410 |
# Call orchestration
|
| 1411 |
orch_start = log_step("orchestrate_turn call")
|
| 1412 |
-
raw_response = orchestrate_turn(last_user_message)
|
| 1413 |
log_step("orchestrate_turn call", orch_start)
|
| 1414 |
|
| 1415 |
# Stream the processed response
|
|
@@ -1437,8 +1440,10 @@ def generate_response(chat_history, conversation_state):
|
|
| 1437 |
final_response = chunk if 'chunk' in locals() else raw_response
|
| 1438 |
new_conversation_state = conversation_state + [{"role": "assistant", "content": final_response}]
|
| 1439 |
|
| 1440 |
-
|
| 1441 |
-
|
|
|
|
|
|
|
| 1442 |
|
| 1443 |
# Final yield with complete states
|
| 1444 |
yield chat_history, new_conversation_state
|
|
|
|
| 974 |
# MAIN ORCHESTRATION WORKFLOW
|
| 975 |
# ============================================================================
|
| 976 |
|
| 977 |
+
def orchestrate_turn(user_input: str, conversation_history: list = None, session_id: str = "default") -> str:
|
| 978 |
"""
|
| 979 |
Main orchestration function implementing the redesign workflow.
|
| 980 |
|
|
|
|
| 1008 |
# ====================================================================
|
| 1009 |
step_start = log_step("Step 2: Process user input")
|
| 1010 |
|
| 1011 |
+
# Use conversation_history passed from Gradio state (no global state call)
|
| 1012 |
+
if conversation_history is None:
|
| 1013 |
+
conversation_history = []
|
| 1014 |
+
|
| 1015 |
+
# Take last 8 messages
|
| 1016 |
+
conversation_history = conversation_history[-8:] if conversation_history else []
|
| 1017 |
|
| 1018 |
# Format history for agents
|
| 1019 |
conversation_history_formatted = "\n".join([
|
|
|
|
| 1412 |
try:
|
| 1413 |
# Call orchestration
|
| 1414 |
orch_start = log_step("orchestrate_turn call")
|
| 1415 |
+
raw_response = orchestrate_turn(last_user_message, conversation_state)
|
| 1416 |
log_step("orchestrate_turn call", orch_start)
|
| 1417 |
|
| 1418 |
# Stream the processed response
|
|
|
|
| 1440 |
final_response = chunk if 'chunk' in locals() else raw_response
|
| 1441 |
new_conversation_state = conversation_state + [{"role": "assistant", "content": final_response}]
|
| 1442 |
|
| 1443 |
+
threading.Thread(
|
| 1444 |
+
target=lambda: global_state_manager.update_conversation_state(chat_history, new_conversation_state),
|
| 1445 |
+
daemon=True
|
| 1446 |
+
).start()
|
| 1447 |
|
| 1448 |
# Final yield with complete states
|
| 1449 |
yield chat_history, new_conversation_state
|