wishwakankanamg commited on
Commit
5a0e318
·
1 Parent(s): ce61988
Files changed (3) hide show
  1. __pycache__/agent.cpython-310.pyc +0 -0
  2. agent.py +24 -1
  3. app.py +0 -1
__pycache__/agent.cpython-310.pyc CHANGED
Binary files a/__pycache__/agent.cpython-310.pyc and b/__pycache__/agent.cpython-310.pyc differ
 
agent.py CHANGED
@@ -264,8 +264,31 @@ def build_graph(provider: str = "huggingface"):
264
  builder.add_edge("tools", "assistant")
265
 
266
  # Compile graph
267
- return builder.compile()
268
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
  # test
270
  if __name__ == "__main__":
271
  question = "When was a picture of St. Thomas Aquinas first added to the Wikipedia page on the Principle of double effect?"
 
264
  builder.add_edge("tools", "assistant")
265
 
266
  # Compile graph
267
+ compiled_graph = builder.compile() # This line should already be there or be the next line
268
 
269
+ # --- START: Add this visualization code ---
270
+ try:
271
+ print("Attempting to generate graph visualization...")
272
+ image_filename = "langgraph_state_diagram.png"
273
+ # Using draw_mermaid_png as it's often more robust
274
+ image_bytes = compiled_graph.get_graph().draw_mermaid_png()
275
+ with open(image_filename, "wb") as f:
276
+ f.write(image_bytes)
277
+ print(f"SUCCESS: Graph visualization saved to '{image_filename}'")
278
+
279
+ except ImportError as e:
280
+ print(f"WARNING: Could not generate graph image due to missing package: {e}. "
281
+ "Ensure 'pygraphviz' and 'graphviz' (system) are installed, or Mermaid components are available.")
282
+ except Exception as e:
283
+ print(f"WARNING: An error occurred while generating the graph image: {e}")
284
+ try:
285
+ print("\nGraph (DOT format as fallback):\n", compiled_graph.get_graph().to_string())
286
+ except Exception as dot_e:
287
+ print(f"Could not even get DOT string: {dot_e}")
288
+ # --- END: Visualization code ---
289
+
290
+ return compiled_graph # This should be the last line of the function
291
+
292
  # test
293
  if __name__ == "__main__":
294
  question = "When was a picture of St. Thomas Aquinas first added to the Wikipedia page on the Principle of double effect?"
app.py CHANGED
@@ -24,7 +24,6 @@ class BasicAgent:
24
  self.graph = build_graph()
25
 
26
  def __call__(self, question: str) -> str:
27
- print(f"**--**")
28
  print(f"Agent received question (first 50 chars): {question[:50]}...")
29
  # Wrap the question in a HumanMessage from langchain_core
30
  messages = [HumanMessage(content=question)]
 
24
  self.graph = build_graph()
25
 
26
  def __call__(self, question: str) -> str:
 
27
  print(f"Agent received question (first 50 chars): {question[:50]}...")
28
  # Wrap the question in a HumanMessage from langchain_core
29
  messages = [HumanMessage(content=question)]