Gaykar commited on
Commit
5c83bd9
·
1 Parent(s): 6108f6a

change -> added rutime use

Browse files
Files changed (1) hide show
  1. app/tools/context_agent_tools.py +12 -14
app/tools/context_agent_tools.py CHANGED
@@ -1,27 +1,23 @@
1
  from typing import Any
2
- from langmem import create_search_memory_tool
3
- from langchain.tools import tool
4
  from typing import Dict, Any, Optional,Annotated
5
- from langchain.tools import tool
6
  from langgraph.prebuilt import InjectedState
7
  from langgraph.store.base import BaseStore
 
 
8
 
9
  @tool
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: Annotated[BaseStore, InjectedState("store")] = InjectedState("store")
18
  ) -> str:
19
- """Accepts a SINGLE string query to search the sender's history. Execute this tool multiple times if you need to search for different facts
20
- """
21
 
22
- active_user = state.get("user_id")
23
- # Using fallback to match alternative naming conventions in your state
24
- sender_email = state.get("sender_email_id") or state.get("senders_email")
25
 
26
  if not sender_email:
27
  return "Error: Cannot isolate history. Active sender_email_id is missing from state context."
@@ -30,7 +26,8 @@ def search_sender_memory_tool(
30
  "content.receiver_email_id": sender_email
31
  }
32
 
33
- results = store.search(
 
34
  namespace=("email", active_user, "collection"),
35
  query=query,
36
  filter=metadata_filter,
@@ -54,6 +51,7 @@ def search_sender_memory_tool(
54
 
55
 
56
 
 
57
  @tool
58
  def give_previous_context(memory_summary: str) -> str:
59
  """
 
1
  from typing import Any
2
+ # from langmem import create_search_memory_tool
 
3
  from typing import Dict, Any, Optional,Annotated
4
+ from langchain.tools import tool,ToolRuntime
5
  from langgraph.prebuilt import InjectedState
6
  from langgraph.store.base import BaseStore
7
+ from typing import Literal
8
+ # Correct import path
9
 
10
  @tool
11
  def search_sender_memory_tool(
12
  query: str,
13
  limit: int = 3,
14
+ runtime: ToolRuntime = None # Inject everything natively here
 
 
 
 
15
  ) -> str:
16
+ """Accepts a SINGLE string query to search the sender's history. Execute this tool multiple times if you need to search for different facts."""
 
17
 
18
+ # 1. Pull values from graph state
19
+ active_user = runtime.state.get("user_id")
20
+ sender_email = runtime.state.get("sender_email_id")
21
 
22
  if not sender_email:
23
  return "Error: Cannot isolate history. Active sender_email_id is missing from state context."
 
26
  "content.receiver_email_id": sender_email
27
  }
28
 
29
+ # 2. Access the BaseStore directly through runtime.store
30
+ results = runtime.store.search(
31
  namespace=("email", active_user, "collection"),
32
  query=query,
33
  filter=metadata_filter,
 
51
 
52
 
53
 
54
+
55
  @tool
56
  def give_previous_context(memory_summary: str) -> str:
57
  """