Spaces:
Runtime error
Runtime error
Create ui/agent_workflow.py
Browse files- ui/agent_workflow.py +124 -0
ui/agent_workflow.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Agent workflow UI component for the pharmaceutical data management agent.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import streamlit as st
|
| 6 |
+
|
| 7 |
+
def render_workflow_tab(session_state):
|
| 8 |
+
"""
|
| 9 |
+
Render the agent workflow visualization tab in the UI.
|
| 10 |
+
|
| 11 |
+
Args:
|
| 12 |
+
session_state: Streamlit session state
|
| 13 |
+
"""
|
| 14 |
+
st.subheader("Agent Workflow Visualization")
|
| 15 |
+
|
| 16 |
+
# Display current agent and status
|
| 17 |
+
current_agent = session_state.conversation.get("current_agent", "understanding_agent")
|
| 18 |
+
status = session_state.conversation.get("status", "planning")
|
| 19 |
+
|
| 20 |
+
st.markdown(f"**Current State:** {status.title()}")
|
| 21 |
+
st.markdown(f"**Current Agent:** {current_agent.replace('_', ' ').title()}")
|
| 22 |
+
|
| 23 |
+
# Visualize the workflow
|
| 24 |
+
col1, col2, col3, col4 = st.columns(4)
|
| 25 |
+
|
| 26 |
+
# Determine which agent is active
|
| 27 |
+
understanding_active = current_agent == "understanding_agent"
|
| 28 |
+
planning_active = current_agent == "planning_agent"
|
| 29 |
+
sql_active = current_agent == "sql_generator_agent"
|
| 30 |
+
executor_active = current_agent == "executor_agent"
|
| 31 |
+
|
| 32 |
+
# Show the workflow visualization
|
| 33 |
+
with col1:
|
| 34 |
+
if understanding_active:
|
| 35 |
+
st.markdown("### π **Understanding**")
|
| 36 |
+
else:
|
| 37 |
+
st.markdown("### π Understanding")
|
| 38 |
+
st.markdown("Extracts user intent and asks clarification questions")
|
| 39 |
+
|
| 40 |
+
if "user_intent" in session_state.conversation and session_state.conversation["user_intent"]:
|
| 41 |
+
st.success("Completed")
|
| 42 |
+
elif understanding_active:
|
| 43 |
+
st.info("In Progress")
|
| 44 |
+
else:
|
| 45 |
+
st.warning("Not Started")
|
| 46 |
+
|
| 47 |
+
with col2:
|
| 48 |
+
if planning_active:
|
| 49 |
+
st.markdown("### π **Planning**")
|
| 50 |
+
else:
|
| 51 |
+
st.markdown("### π Planning")
|
| 52 |
+
st.markdown("Creates data pipeline plan with sources and transformations")
|
| 53 |
+
|
| 54 |
+
if "pipeline_plan" in session_state.conversation and session_state.conversation["pipeline_plan"]:
|
| 55 |
+
st.success("Completed")
|
| 56 |
+
elif planning_active:
|
| 57 |
+
st.info("In Progress")
|
| 58 |
+
elif understanding_active:
|
| 59 |
+
st.warning("Not Started")
|
| 60 |
+
else:
|
| 61 |
+
st.success("Completed")
|
| 62 |
+
|
| 63 |
+
with col3:
|
| 64 |
+
if sql_active:
|
| 65 |
+
st.markdown("### π» **SQL Generation**")
|
| 66 |
+
else:
|
| 67 |
+
st.markdown("### π» SQL Generation")
|
| 68 |
+
st.markdown("Converts plan into executable SQL queries")
|
| 69 |
+
|
| 70 |
+
if "sql_queries" in session_state.conversation and session_state.conversation["sql_queries"]:
|
| 71 |
+
st.success("Completed")
|
| 72 |
+
elif sql_active:
|
| 73 |
+
st.info("In Progress")
|
| 74 |
+
elif understanding_active or planning_active:
|
| 75 |
+
st.warning("Not Started")
|
| 76 |
+
else:
|
| 77 |
+
st.success("Completed")
|
| 78 |
+
|
| 79 |
+
with col4:
|
| 80 |
+
if executor_active:
|
| 81 |
+
st.markdown("### βοΈ **Execution**")
|
| 82 |
+
else:
|
| 83 |
+
st.markdown("### βοΈ Execution")
|
| 84 |
+
st.markdown("Executes queries and reports results")
|
| 85 |
+
|
| 86 |
+
if "execution_results" in session_state.conversation and session_state.conversation["execution_results"]:
|
| 87 |
+
st.success("Completed")
|
| 88 |
+
elif executor_active:
|
| 89 |
+
st.info("In Progress")
|
| 90 |
+
elif understanding_active or planning_active or sql_active:
|
| 91 |
+
st.warning("Not Started")
|
| 92 |
+
else:
|
| 93 |
+
st.success("Completed")
|
| 94 |
+
|
| 95 |
+
# Overall confidence score
|
| 96 |
+
if "confidence_scores" in session_state.conversation and "overall" in session_state.conversation["confidence_scores"]:
|
| 97 |
+
st.markdown("### Overall Pipeline Confidence")
|
| 98 |
+
score = session_state.conversation["confidence_scores"]["overall"] * 100
|
| 99 |
+
st.progress(score / 100, text=f"{score:.1f}%")
|
| 100 |
+
|
| 101 |
+
# Workflow decision points
|
| 102 |
+
if status == "complete":
|
| 103 |
+
if score > 80:
|
| 104 |
+
st.success("β
High confidence - Pipeline can be deployed automatically")
|
| 105 |
+
else:
|
| 106 |
+
st.warning("β οΈ Medium confidence - Human review recommended before deployment")
|
| 107 |
+
|
| 108 |
+
# Add human review section for pending approval status
|
| 109 |
+
if status == "pending_approval":
|
| 110 |
+
st.markdown("### π€ Human Review Required")
|
| 111 |
+
st.info("This pipeline requires human review before deployment")
|
| 112 |
+
|
| 113 |
+
col1, col2 = st.columns(2)
|
| 114 |
+
with col1:
|
| 115 |
+
if st.button("β
Approve Pipeline"):
|
| 116 |
+
# Update state to approved
|
| 117 |
+
session_state.conversation["status"] = "approved"
|
| 118 |
+
# Trigger execution to continue
|
| 119 |
+
st.rerun()
|
| 120 |
+
with col2:
|
| 121 |
+
if st.button("β Reject Pipeline"):
|
| 122 |
+
# Update state to rejected
|
| 123 |
+
session_state.conversation["status"] = "rejected"
|
| 124 |
+
st.error("Pipeline rejected. Please provide feedback to refine the pipeline.")
|