Gaykar commited on
Commit
873e08b
·
1 Parent(s): a590be9
Files changed (1) hide show
  1. app/tools/context_agent_tools.py +7 -12
app/tools/context_agent_tools.py CHANGED
@@ -10,32 +10,27 @@ from langgraph.store.base import BaseStore
10
  def search_sender_memory_tool(
11
  query: str,
12
  limit: int = 3,
13
- # 1. Inject the entire Graph state at runtime
14
- state: Annotated[Dict[str, Any], InjectedState] = InjectedState,
15
 
16
- # 2. Inject the compiled graph storage layer
17
- store: BaseStore = InjectedState("store")
18
  ) -> str:
19
  """Search long-term memory for specific historical email contexts.
20
  This tool automatically scopes the search to the active sender interaction.
21
  """
22
 
23
- # Extract the runtime sender/receiver information directly from your graph state
24
- # Replace keys with your exact LangGraph state schema keys (e.g., state.get("current_sender"))
25
  active_user = state.get("user_id")
26
- sender_email = state.get("sender_email_id")
 
27
 
28
- # Fail gracefully if mandatory identification is missing in the state
29
  if not sender_email:
30
  return "Error: Cannot isolate history. Active sender_email_id is missing from state context."
31
 
32
- # Formulate a strict metadata dictionary check matching your EmailMemory schema.
33
- # We look for records where the communication partner matches the sender.
34
  metadata_filter = {
35
  "receiver_email_id": sender_email
36
  }
37
 
38
- # Query your PostgresStore with explicit structural filters
39
  results = store.search(
40
  namespace=("email", active_user, "collection"),
41
  query=query,
@@ -46,7 +41,6 @@ def search_sender_memory_tool(
46
  if not results:
47
  return f"No prior email context found specifically for sender: {sender_email}."
48
 
49
- # Format structural outputs cleanly for your Context Agent
50
  formatted_memories = []
51
  for item in results:
52
  val = item.value
@@ -60,6 +54,7 @@ def search_sender_memory_tool(
60
  return "\n".join(formatted_memories)
61
 
62
 
 
63
  @tool
64
  def give_previous_context(memory_summary: str) -> str:
65
  """
 
10
  def search_sender_memory_tool(
11
  query: str,
12
  limit: int = 3,
13
+ # 1. Inject the entire Graph state at runtime (Corrected ✅)
14
+ state: Annotated[Dict[str, Any], InjectedState] = InjectedState,
15
 
16
+ # 2. Inject the compiled graph storage layer (Fixed line below 👇)
17
+ store: Annotated[BaseStore, InjectedState("store")] = InjectedState("store")
18
  ) -> str:
19
  """Search long-term memory for specific historical email contexts.
20
  This tool automatically scopes the search to the active sender interaction.
21
  """
22
 
 
 
23
  active_user = state.get("user_id")
24
+ # Using fallback to match alternative naming conventions in your state
25
+ sender_email = state.get("sender_email_id") or state.get("senders_email")
26
 
 
27
  if not sender_email:
28
  return "Error: Cannot isolate history. Active sender_email_id is missing from state context."
29
 
 
 
30
  metadata_filter = {
31
  "receiver_email_id": sender_email
32
  }
33
 
 
34
  results = store.search(
35
  namespace=("email", active_user, "collection"),
36
  query=query,
 
41
  if not results:
42
  return f"No prior email context found specifically for sender: {sender_email}."
43
 
 
44
  formatted_memories = []
45
  for item in results:
46
  val = item.value
 
54
  return "\n".join(formatted_memories)
55
 
56
 
57
+
58
  @tool
59
  def give_previous_context(memory_summary: str) -> str:
60
  """