legolasyiu commited on
Commit
6b68172
·
verified ·
1 Parent(s): d451172

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +25 -8
src/streamlit_app.py CHANGED
@@ -115,15 +115,32 @@ agent = create_deep_agent(
115
  system_prompt=research_instructions,
116
  )
117
 
118
- # --- Streamlit Chat UI ---
119
- st.title("🧠 Deep Research Agent")
120
- st.caption(f"Running on: **{provider}** backend")
121
-
 
 
 
 
 
 
 
 
122
  if prompt := st.chat_input("Ask your research question..."):
 
 
123
  st.chat_message("user").write(prompt)
 
 
124
  with st.chat_message("assistant"):
125
  st_callback = StreamlitCallbackHandler(st.container())
126
- response = agent.invoke({"messages": [{"role": "user", "content": prompt}]},{"callbacks": [st_callback]})
127
- displayed_response = response["messages"][-1].content
128
- #output = response.get("output", str(response))
129
- st.write(displayed_response)
 
 
 
 
 
 
115
  system_prompt=research_instructions,
116
  )
117
 
118
+ # Initialize chat history
119
+ if "messages" not in st.session_state:
120
+ st.session_state["messages"] = [
121
+ {"role": "assistant", "content": "Hello! I’m your Deep Research Agent. What would you like to explore today?"}
122
+ ]
123
+
124
+ # Display chat history
125
+ for msg in st.session_state.messages:
126
+ with st.chat_message(msg["role"]):
127
+ st.markdown(msg["content"])
128
+
129
+ # --- Chat Input ---
130
  if prompt := st.chat_input("Ask your research question..."):
131
+ # Save user message
132
+ st.session_state.messages.append({"role": "user", "content": prompt})
133
  st.chat_message("user").write(prompt)
134
+
135
+ # Process assistant response
136
  with st.chat_message("assistant"):
137
  st_callback = StreamlitCallbackHandler(st.container())
138
+ response = agent.invoke(
139
+ {"messages": st.session_state.messages},
140
+ {"callbacks": [st_callback]},
141
+ )
142
+
143
+ # Extract and display assistant reply
144
+ reply = response["messages"][-1].content
145
+ st.markdown(reply)
146
+ st.session_state.messages.append({"role": "assistant", "content": reply})