aip-agents-binary 0.6.2__py3-none-macosx_13_0_arm64.whl → 0.6.4__py3-none-macosx_13_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aip_agents/agent/base_langgraph_agent.py +26 -6
- aip_agents/agent/langgraph_memory_enhancer_agent.py +368 -34
- aip_agents/agent/langgraph_memory_enhancer_agent.pyi +3 -2
- aip_agents/agent/langgraph_react_agent.py +30 -6
- aip_agents/agent/langgraph_react_agent.pyi +1 -1
- aip_agents/mcp/client/transports.py +5 -1
- aip_agents/memory/adapters/base_adapter.py +94 -0
- aip_agents/memory/adapters/base_adapter.pyi +26 -0
- aip_agents/tools/__init__.py +11 -2
- aip_agents/tools/__init__.pyi +2 -1
- aip_agents/tools/date_range_tool.py +554 -0
- aip_agents/tools/date_range_tool.pyi +21 -0
- aip_agents/tools/memory_search/__init__.py +8 -1
- aip_agents/tools/memory_search/__init__.pyi +3 -3
- aip_agents/tools/memory_search/mem0.py +108 -1
- aip_agents/tools/memory_search/mem0.pyi +11 -1
- aip_agents/tools/memory_search/schema.py +33 -0
- aip_agents/tools/memory_search/schema.pyi +10 -0
- aip_agents/tools/memory_search_tool.py +8 -0
- aip_agents/tools/memory_search_tool.pyi +2 -2
- {aip_agents_binary-0.6.2.dist-info → aip_agents_binary-0.6.4.dist-info}/METADATA +5 -16
- {aip_agents_binary-0.6.2.dist-info → aip_agents_binary-0.6.4.dist-info}/RECORD +24 -24
- aip_agents/examples/demo_memory_recall.py +0 -401
- aip_agents/examples/demo_memory_recall.pyi +0 -58
- {aip_agents_binary-0.6.2.dist-info → aip_agents_binary-0.6.4.dist-info}/WHEEL +0 -0
- {aip_agents_binary-0.6.2.dist-info → aip_agents_binary-0.6.4.dist-info}/top_level.txt +0 -0
|
@@ -54,7 +54,7 @@ from aip_agents.schema.a2a import A2AStreamEventType
|
|
|
54
54
|
from aip_agents.schema.hitl import ApprovalDecision, HitlMetadata
|
|
55
55
|
from aip_agents.schema.langgraph import ToolCallResult, ToolStorageParams
|
|
56
56
|
from aip_agents.schema.step_limit import MaxStepsExceededError, StepLimitConfig
|
|
57
|
-
from aip_agents.tools.memory_search_tool import MEMORY_SEARCH_TOOL_NAME
|
|
57
|
+
from aip_agents.tools.memory_search_tool import MEMORY_DELETE_TOOL_NAME, MEMORY_SEARCH_TOOL_NAME
|
|
58
58
|
from aip_agents.tools.tool_config_injector import TOOL_CONFIGS_KEY
|
|
59
59
|
from aip_agents.utils import add_references_chunks
|
|
60
60
|
from aip_agents.utils.langgraph import (
|
|
@@ -584,6 +584,29 @@ class LangGraphReactAgent(LangGraphHitLMixin, BaseLangGraphAgent):
|
|
|
584
584
|
|
|
585
585
|
return memory_node
|
|
586
586
|
|
|
587
|
+
def _should_save_interaction(self, final_state: dict[str, Any] | None) -> bool:
|
|
588
|
+
"""Return True when interaction should be saved to memory."""
|
|
589
|
+
if self._contains_memory_delete_action(final_state):
|
|
590
|
+
logger.info("Memory: Skipping save_interaction due to memory delete action in state.")
|
|
591
|
+
return False
|
|
592
|
+
return True
|
|
593
|
+
|
|
594
|
+
@staticmethod
|
|
595
|
+
def _contains_memory_delete_action(final_state: dict[str, Any] | None) -> bool:
|
|
596
|
+
"""Return True when final state includes a delete memory action block."""
|
|
597
|
+
if not isinstance(final_state, dict):
|
|
598
|
+
return False
|
|
599
|
+
messages = final_state.get("messages")
|
|
600
|
+
if not isinstance(messages, list):
|
|
601
|
+
return False
|
|
602
|
+
for message in messages:
|
|
603
|
+
content = getattr(message, "content", None)
|
|
604
|
+
if not isinstance(content, str):
|
|
605
|
+
continue
|
|
606
|
+
if "<MEMORY_ACTION>" in content and "action=delete" in content:
|
|
607
|
+
return True
|
|
608
|
+
return False
|
|
609
|
+
|
|
587
610
|
def _extract_user_query_from_messages(self, messages: list[Any]) -> str | None:
|
|
588
611
|
"""Get latest user query string from a list of messages.
|
|
589
612
|
|
|
@@ -2277,11 +2300,12 @@ class LangGraphReactAgent(LangGraphHitLMixin, BaseLangGraphAgent):
|
|
|
2277
2300
|
"""
|
|
2278
2301
|
try:
|
|
2279
2302
|
tool_cfgs = metadata.get(TOOL_CONFIGS_KEY, {})
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
per_tool_config
|
|
2283
|
-
|
|
2284
|
-
|
|
2303
|
+
for tool_name in (MEMORY_SEARCH_TOOL_NAME, MEMORY_DELETE_TOOL_NAME):
|
|
2304
|
+
per_tool_config = tool_cfgs.get(tool_name)
|
|
2305
|
+
if not isinstance(per_tool_config, dict):
|
|
2306
|
+
per_tool_config = {}
|
|
2307
|
+
per_tool_config["user_id"] = memory_user_id
|
|
2308
|
+
tool_cfgs[tool_name] = per_tool_config
|
|
2285
2309
|
metadata[TOOL_CONFIGS_KEY] = tool_cfgs
|
|
2286
2310
|
except Exception as e:
|
|
2287
2311
|
# Non-fatal; metadata injection is best-effort
|
|
@@ -11,7 +11,7 @@ from aip_agents.schema.a2a import A2AStreamEventType as A2AStreamEventType
|
|
|
11
11
|
from aip_agents.schema.hitl import ApprovalDecision as ApprovalDecision, HitlMetadata as HitlMetadata
|
|
12
12
|
from aip_agents.schema.langgraph import ToolCallResult as ToolCallResult, ToolStorageParams as ToolStorageParams
|
|
13
13
|
from aip_agents.schema.step_limit import MaxStepsExceededError as MaxStepsExceededError, StepLimitConfig as StepLimitConfig
|
|
14
|
-
from aip_agents.tools.memory_search_tool import MEMORY_SEARCH_TOOL_NAME as MEMORY_SEARCH_TOOL_NAME
|
|
14
|
+
from aip_agents.tools.memory_search_tool import MEMORY_DELETE_TOOL_NAME as MEMORY_DELETE_TOOL_NAME, MEMORY_SEARCH_TOOL_NAME as MEMORY_SEARCH_TOOL_NAME
|
|
15
15
|
from aip_agents.tools.tool_config_injector import TOOL_CONFIGS_KEY as TOOL_CONFIGS_KEY
|
|
16
16
|
from aip_agents.utils import add_references_chunks as add_references_chunks
|
|
17
17
|
from aip_agents.utils.langgraph import convert_langchain_messages_to_gllm_messages as convert_langchain_messages_to_gllm_messages, convert_lm_output_to_langchain_message as convert_lm_output_to_langchain_message
|
|
@@ -185,7 +185,11 @@ class HTTPTransport(Transport):
|
|
|
185
185
|
headers = _sanitize_headers(self.config)
|
|
186
186
|
logger.debug(f"Attempting streamable HTTP connection to {url} with headers: {list(headers.keys())}")
|
|
187
187
|
try:
|
|
188
|
-
http_client = httpx.AsyncClient(
|
|
188
|
+
http_client = httpx.AsyncClient(
|
|
189
|
+
timeout=httpx.Timeout(timeout),
|
|
190
|
+
headers=headers,
|
|
191
|
+
follow_redirects=True,
|
|
192
|
+
)
|
|
189
193
|
self._http_client = http_client
|
|
190
194
|
self.ctx = streamable_http_client(url=url, http_client=http_client)
|
|
191
195
|
read_stream, write_stream, _ = await self.ctx.__aenter__()
|
|
@@ -256,6 +256,100 @@ class BaseMemoryAdapter(BaseMemory):
|
|
|
256
256
|
|
|
257
257
|
return [self._chunk_to_hit(chunk) for chunk in chunks]
|
|
258
258
|
|
|
259
|
+
def delete_by_query(
|
|
260
|
+
self,
|
|
261
|
+
*,
|
|
262
|
+
query: str,
|
|
263
|
+
user_id: str,
|
|
264
|
+
metadata: dict[str, Any] | None = None,
|
|
265
|
+
threshold: float | None = None,
|
|
266
|
+
top_k: int | None = None,
|
|
267
|
+
categories: list[str] | None = None,
|
|
268
|
+
) -> Any:
|
|
269
|
+
"""Delete memories by semantic query.
|
|
270
|
+
|
|
271
|
+
Args:
|
|
272
|
+
query: Semantic query describing memories to delete.
|
|
273
|
+
user_id: User identifier for the deletion scope.
|
|
274
|
+
metadata: Optional metadata filters to constrain deletion.
|
|
275
|
+
threshold: Optional semantic threshold (if supported by backend).
|
|
276
|
+
top_k: Optional max number of memories to delete by query.
|
|
277
|
+
categories: Optional categories to filter by (best-effort).
|
|
278
|
+
|
|
279
|
+
Returns:
|
|
280
|
+
Backend-specific delete result or None on failure.
|
|
281
|
+
"""
|
|
282
|
+
try:
|
|
283
|
+
start = perf_counter()
|
|
284
|
+
result = self._runner.run(
|
|
285
|
+
self._call_manager_with_optional_categories(
|
|
286
|
+
self._manager.delete_by_user_query,
|
|
287
|
+
categories=categories,
|
|
288
|
+
query=query,
|
|
289
|
+
user_id=user_id or self.agent_id,
|
|
290
|
+
agent_id=self.agent_id,
|
|
291
|
+
scopes=DEFAULT_SCOPE,
|
|
292
|
+
metadata=metadata,
|
|
293
|
+
threshold=threshold,
|
|
294
|
+
top_k=top_k,
|
|
295
|
+
)
|
|
296
|
+
)
|
|
297
|
+
duration = perf_counter() - start
|
|
298
|
+
logger.info(
|
|
299
|
+
"BaseMemoryAdapter: delete_by_query user_id='%s' query='%s' completed in %.2fs",
|
|
300
|
+
user_id,
|
|
301
|
+
query,
|
|
302
|
+
duration,
|
|
303
|
+
)
|
|
304
|
+
return result
|
|
305
|
+
except Exception as exc: # noqa: BLE001
|
|
306
|
+
logger.debug("BaseMemoryAdapter.delete_by_query ignored error: %s", exc)
|
|
307
|
+
return None
|
|
308
|
+
|
|
309
|
+
def delete(
|
|
310
|
+
self,
|
|
311
|
+
*,
|
|
312
|
+
memory_ids: list[str] | None,
|
|
313
|
+
user_id: str,
|
|
314
|
+
metadata: dict[str, Any] | None = None,
|
|
315
|
+
categories: list[str] | None = None,
|
|
316
|
+
) -> Any:
|
|
317
|
+
"""Delete memories by IDs or by user scope when IDs are None.
|
|
318
|
+
|
|
319
|
+
Args:
|
|
320
|
+
memory_ids: Optional list of memory IDs to delete.
|
|
321
|
+
user_id: User identifier for the deletion scope.
|
|
322
|
+
metadata: Optional metadata filters to constrain deletion.
|
|
323
|
+
categories: Optional categories to filter by (best-effort).
|
|
324
|
+
|
|
325
|
+
Returns:
|
|
326
|
+
Backend-specific delete result or None on failure.
|
|
327
|
+
"""
|
|
328
|
+
try:
|
|
329
|
+
start = perf_counter()
|
|
330
|
+
result = self._runner.run(
|
|
331
|
+
self._call_manager_with_optional_categories(
|
|
332
|
+
self._manager.delete,
|
|
333
|
+
categories=categories,
|
|
334
|
+
memory_ids=memory_ids,
|
|
335
|
+
user_id=user_id or self.agent_id,
|
|
336
|
+
agent_id=self.agent_id,
|
|
337
|
+
scopes=DEFAULT_SCOPE,
|
|
338
|
+
metadata=metadata,
|
|
339
|
+
)
|
|
340
|
+
)
|
|
341
|
+
duration = perf_counter() - start
|
|
342
|
+
logger.info(
|
|
343
|
+
"BaseMemoryAdapter: delete user_id='%s' memory_ids=%s completed in %.2fs",
|
|
344
|
+
user_id,
|
|
345
|
+
"None" if memory_ids is None else len(memory_ids),
|
|
346
|
+
duration,
|
|
347
|
+
)
|
|
348
|
+
return result
|
|
349
|
+
except Exception as exc: # noqa: BLE001
|
|
350
|
+
logger.debug("BaseMemoryAdapter.delete ignored error: %s", exc)
|
|
351
|
+
return None
|
|
352
|
+
|
|
259
353
|
def save_interaction(self, *, user_text: str, ai_text: str, user_id: str) -> None:
|
|
260
354
|
"""Save a user-AI interaction as memories.
|
|
261
355
|
|
|
@@ -106,6 +106,32 @@ class BaseMemoryAdapter(BaseMemory):
|
|
|
106
106
|
Returns:
|
|
107
107
|
List of memory hits matching the criteria.
|
|
108
108
|
"""
|
|
109
|
+
def delete_by_query(self, *, query: str, user_id: str, metadata: dict[str, Any] | None = None, threshold: float | None = None, top_k: int | None = None, categories: list[str] | None = None) -> Any:
|
|
110
|
+
"""Delete memories by semantic query.
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
query: Semantic query describing memories to delete.
|
|
114
|
+
user_id: User identifier for the deletion scope.
|
|
115
|
+
metadata: Optional metadata filters to constrain deletion.
|
|
116
|
+
threshold: Optional semantic threshold (if supported by backend).
|
|
117
|
+
top_k: Optional max number of memories to delete by query.
|
|
118
|
+
categories: Optional categories to filter by (best-effort).
|
|
119
|
+
|
|
120
|
+
Returns:
|
|
121
|
+
Backend-specific delete result or None on failure.
|
|
122
|
+
"""
|
|
123
|
+
def delete(self, *, memory_ids: list[str] | None, user_id: str, metadata: dict[str, Any] | None = None, categories: list[str] | None = None) -> Any:
|
|
124
|
+
"""Delete memories by IDs or by user scope when IDs are None.
|
|
125
|
+
|
|
126
|
+
Args:
|
|
127
|
+
memory_ids: Optional list of memory IDs to delete.
|
|
128
|
+
user_id: User identifier for the deletion scope.
|
|
129
|
+
metadata: Optional metadata filters to constrain deletion.
|
|
130
|
+
categories: Optional categories to filter by (best-effort).
|
|
131
|
+
|
|
132
|
+
Returns:
|
|
133
|
+
Backend-specific delete result or None on failure.
|
|
134
|
+
"""
|
|
109
135
|
def save_interaction(self, *, user_text: str, ai_text: str, user_id: str) -> None:
|
|
110
136
|
"""Save a user-AI interaction as memories.
|
|
111
137
|
|
aip_agents/tools/__init__.py
CHANGED
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
from importlib import import_module
|
|
4
4
|
from typing import TYPE_CHECKING
|
|
5
5
|
|
|
6
|
+
from aip_agents.tools.date_range_tool import DateRangeTool
|
|
6
7
|
from aip_agents.tools.gl_connector import GLConnectorTool
|
|
7
|
-
from aip_agents.tools.gl_connector_tools import
|
|
8
|
+
from aip_agents.tools.gl_connector_tools import (
|
|
9
|
+
BOSA_AUTOMATED_TOOLS,
|
|
10
|
+
GL_CONNECTORS_AUTOMATED_TOOLS,
|
|
11
|
+
)
|
|
8
12
|
from aip_agents.tools.time_tool import TimeTool
|
|
9
13
|
from aip_agents.tools.web_search import GoogleSerperTool
|
|
10
14
|
from aip_agents.utils.logger import get_logger
|
|
@@ -17,6 +21,7 @@ __all__ = [
|
|
|
17
21
|
"GLConnectorTool",
|
|
18
22
|
"GoogleSerperTool",
|
|
19
23
|
"TimeTool",
|
|
24
|
+
"DateRangeTool",
|
|
20
25
|
]
|
|
21
26
|
|
|
22
27
|
|
|
@@ -51,5 +56,9 @@ _register_optional("aip_agents.tools.execute_ptc_code", "create_execute_ptc_code
|
|
|
51
56
|
if TYPE_CHECKING:
|
|
52
57
|
from aip_agents.tools.browser_use import BrowserUseTool
|
|
53
58
|
from aip_agents.tools.code_sandbox import E2BCodeSandboxTool
|
|
54
|
-
from aip_agents.tools.document_loader import
|
|
59
|
+
from aip_agents.tools.document_loader import (
|
|
60
|
+
DocxReaderTool,
|
|
61
|
+
ExcelReaderTool,
|
|
62
|
+
PDFReaderTool,
|
|
63
|
+
)
|
|
55
64
|
from aip_agents.tools.execute_ptc_code import create_execute_ptc_code_tool
|
aip_agents/tools/__init__.pyi
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from aip_agents.tools.browser_use import BrowserUseTool as BrowserUseTool
|
|
2
2
|
from aip_agents.tools.code_sandbox import E2BCodeSandboxTool as E2BCodeSandboxTool
|
|
3
|
+
from aip_agents.tools.date_range_tool import DateRangeTool as DateRangeTool
|
|
3
4
|
from aip_agents.tools.document_loader import DocxReaderTool as DocxReaderTool, ExcelReaderTool as ExcelReaderTool, PDFReaderTool as PDFReaderTool
|
|
4
5
|
from aip_agents.tools.execute_ptc_code import create_execute_ptc_code_tool as create_execute_ptc_code_tool
|
|
5
6
|
from aip_agents.tools.gl_connector import GLConnectorTool as GLConnectorTool
|
|
@@ -7,4 +8,4 @@ from aip_agents.tools.gl_connector_tools import BOSA_AUTOMATED_TOOLS as BOSA_AUT
|
|
|
7
8
|
from aip_agents.tools.time_tool import TimeTool as TimeTool
|
|
8
9
|
from aip_agents.tools.web_search import GoogleSerperTool as GoogleSerperTool
|
|
9
10
|
|
|
10
|
-
__all__ = ['BOSA_AUTOMATED_TOOLS', 'GL_CONNECTORS_AUTOMATED_TOOLS', 'GLConnectorTool', 'GoogleSerperTool', 'TimeTool', 'BrowserUseTool', 'E2BCodeSandboxTool', 'DocxReaderTool', 'ExcelReaderTool', 'PDFReaderTool', 'create_execute_ptc_code_tool']
|
|
11
|
+
__all__ = ['BOSA_AUTOMATED_TOOLS', 'GL_CONNECTORS_AUTOMATED_TOOLS', 'GLConnectorTool', 'GoogleSerperTool', 'TimeTool', 'DateRangeTool', 'BrowserUseTool', 'E2BCodeSandboxTool', 'DocxReaderTool', 'ExcelReaderTool', 'PDFReaderTool', 'create_execute_ptc_code_tool']
|