alisamak commited on
Commit
f75c084
·
verified ·
1 Parent(s): 62c5a8c

Update LG_agent.py

Browse files
Files changed (1) hide show
  1. LG_agent.py +19 -5
LG_agent.py CHANGED
@@ -41,7 +41,6 @@ class AgentState(TypedDict):
41
  # 3. Assistant node
42
 
43
  def assistant(state: AgentState):
44
- # Inject tools description to a system message
45
  tool_descriptions = "\n".join([
46
  f"{tool.name}{inspect.signature(tool.func)}:\n {tool.description.strip()}"
47
  for tool in all_tools
@@ -55,8 +54,20 @@ def assistant(state: AgentState):
55
  )
56
  )
57
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  return {
59
- "messages": [chat_with_tools.invoke([sys_msg] + state["messages"])],
60
  }
61
 
62
  # 4. Build the agent graph
@@ -75,13 +86,16 @@ def build_graph(max_steps: int = 5):
75
  def limited_invoke(state):
76
  steps = 0
77
  while steps < max_steps:
78
- print(f"🔁 Step {steps + 1}")
79
  state = graph.invoke(state)
80
 
81
  for msg in state["messages"]:
82
  if isinstance(msg, AIMessage):
83
- print(f"🤔 LLM Thought: {msg.content.strip()}")
84
-
 
 
 
85
  latest_message = state["messages"][-1] if state["messages"] else None
86
 
87
  if latest_message and isinstance(latest_message, AIMessage):
 
41
  # 3. Assistant node
42
 
43
  def assistant(state: AgentState):
 
44
  tool_descriptions = "\n".join([
45
  f"{tool.name}{inspect.signature(tool.func)}:\n {tool.description.strip()}"
46
  for tool in all_tools
 
54
  )
55
  )
56
 
57
+ input_msgs = [sys_msg] + state["messages"]
58
+ print("\n🧠 Assistant received messages:")
59
+ for msg in input_msgs:
60
+ print(f"🔹 {msg.__class__.__name__}: {getattr(msg, 'content', '')[:200]}")
61
+
62
+ output = chat_with_tools.invoke(input_msgs)
63
+
64
+ print("\n🗣️ Assistant response:")
65
+ print("-" * 40)
66
+ print(getattr(output, 'content', '')[:500])
67
+ print("-" * 40)
68
+
69
  return {
70
+ "messages": [output],
71
  }
72
 
73
  # 4. Build the agent graph
 
86
  def limited_invoke(state):
87
  steps = 0
88
  while steps < max_steps:
89
+ print(f"\U0001f501 Step {steps + 1}")
90
  state = graph.invoke(state)
91
 
92
  for msg in state["messages"]:
93
  if isinstance(msg, AIMessage):
94
+ print("\n🤖 Assistant says:")
95
+ print("-" * 40)
96
+ print(msg.content.strip())
97
+ print("-" * 40)
98
+
99
  latest_message = state["messages"][-1] if state["messages"] else None
100
 
101
  if latest_message and isinstance(latest_message, AIMessage):