aip-agents-binary 0.5.21__py3-none-macosx_13_0_arm64.whl → 0.6.8__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.
Files changed (149) hide show
  1. aip_agents/agent/__init__.py +44 -4
  2. aip_agents/agent/base_langgraph_agent.py +169 -74
  3. aip_agents/agent/base_langgraph_agent.pyi +3 -2
  4. aip_agents/agent/langgraph_memory_enhancer_agent.py +368 -34
  5. aip_agents/agent/langgraph_memory_enhancer_agent.pyi +3 -2
  6. aip_agents/agent/langgraph_react_agent.py +424 -35
  7. aip_agents/agent/langgraph_react_agent.pyi +46 -2
  8. aip_agents/examples/{hello_world_langgraph_bosa_twitter.py → hello_world_langgraph_gl_connector_twitter.py} +10 -7
  9. aip_agents/examples/hello_world_langgraph_gl_connector_twitter.pyi +5 -0
  10. aip_agents/examples/hello_world_ptc.py +49 -0
  11. aip_agents/examples/hello_world_ptc.pyi +5 -0
  12. aip_agents/examples/hello_world_ptc_custom_tools.py +83 -0
  13. aip_agents/examples/hello_world_ptc_custom_tools.pyi +7 -0
  14. aip_agents/examples/hello_world_sentry.py +2 -2
  15. aip_agents/examples/hello_world_tool_output_client.py +9 -0
  16. aip_agents/examples/tools/multiply_tool.py +43 -0
  17. aip_agents/examples/tools/multiply_tool.pyi +18 -0
  18. aip_agents/guardrails/__init__.py +83 -0
  19. aip_agents/guardrails/__init__.pyi +6 -0
  20. aip_agents/guardrails/engines/__init__.py +69 -0
  21. aip_agents/guardrails/engines/__init__.pyi +4 -0
  22. aip_agents/guardrails/engines/base.py +90 -0
  23. aip_agents/guardrails/engines/base.pyi +61 -0
  24. aip_agents/guardrails/engines/nemo.py +101 -0
  25. aip_agents/guardrails/engines/nemo.pyi +46 -0
  26. aip_agents/guardrails/engines/phrase_matcher.py +113 -0
  27. aip_agents/guardrails/engines/phrase_matcher.pyi +48 -0
  28. aip_agents/guardrails/exceptions.py +39 -0
  29. aip_agents/guardrails/exceptions.pyi +23 -0
  30. aip_agents/guardrails/manager.py +163 -0
  31. aip_agents/guardrails/manager.pyi +42 -0
  32. aip_agents/guardrails/middleware.py +199 -0
  33. aip_agents/guardrails/middleware.pyi +87 -0
  34. aip_agents/guardrails/schemas.py +63 -0
  35. aip_agents/guardrails/schemas.pyi +43 -0
  36. aip_agents/guardrails/utils.py +45 -0
  37. aip_agents/guardrails/utils.pyi +19 -0
  38. aip_agents/mcp/client/__init__.py +38 -2
  39. aip_agents/mcp/client/connection_manager.py +36 -1
  40. aip_agents/mcp/client/connection_manager.pyi +3 -0
  41. aip_agents/mcp/client/persistent_session.py +318 -65
  42. aip_agents/mcp/client/persistent_session.pyi +9 -0
  43. aip_agents/mcp/client/transports.py +52 -4
  44. aip_agents/mcp/client/transports.pyi +9 -0
  45. aip_agents/memory/adapters/base_adapter.py +98 -0
  46. aip_agents/memory/adapters/base_adapter.pyi +25 -0
  47. aip_agents/middleware/base.py +8 -0
  48. aip_agents/middleware/base.pyi +4 -0
  49. aip_agents/middleware/manager.py +22 -0
  50. aip_agents/middleware/manager.pyi +4 -0
  51. aip_agents/ptc/__init__.py +87 -0
  52. aip_agents/ptc/__init__.pyi +14 -0
  53. aip_agents/ptc/custom_tools.py +473 -0
  54. aip_agents/ptc/custom_tools.pyi +184 -0
  55. aip_agents/ptc/custom_tools_payload.py +400 -0
  56. aip_agents/ptc/custom_tools_payload.pyi +31 -0
  57. aip_agents/ptc/custom_tools_templates/__init__.py +1 -0
  58. aip_agents/ptc/custom_tools_templates/__init__.pyi +0 -0
  59. aip_agents/ptc/custom_tools_templates/custom_build_function.py.template +23 -0
  60. aip_agents/ptc/custom_tools_templates/custom_init.py.template +15 -0
  61. aip_agents/ptc/custom_tools_templates/custom_invoke.py.template +60 -0
  62. aip_agents/ptc/custom_tools_templates/custom_registry.py.template +87 -0
  63. aip_agents/ptc/custom_tools_templates/custom_sources_init.py.template +7 -0
  64. aip_agents/ptc/custom_tools_templates/custom_wrapper.py.template +19 -0
  65. aip_agents/ptc/doc_gen.py +122 -0
  66. aip_agents/ptc/doc_gen.pyi +40 -0
  67. aip_agents/ptc/exceptions.py +57 -0
  68. aip_agents/ptc/exceptions.pyi +37 -0
  69. aip_agents/ptc/executor.py +261 -0
  70. aip_agents/ptc/executor.pyi +99 -0
  71. aip_agents/ptc/mcp/__init__.py +45 -0
  72. aip_agents/ptc/mcp/__init__.pyi +7 -0
  73. aip_agents/ptc/mcp/sandbox_bridge.py +668 -0
  74. aip_agents/ptc/mcp/sandbox_bridge.pyi +47 -0
  75. aip_agents/ptc/mcp/templates/__init__.py +1 -0
  76. aip_agents/ptc/mcp/templates/__init__.pyi +0 -0
  77. aip_agents/ptc/mcp/templates/mcp_client.py.template +239 -0
  78. aip_agents/ptc/naming.py +196 -0
  79. aip_agents/ptc/naming.pyi +85 -0
  80. aip_agents/ptc/payload.py +26 -0
  81. aip_agents/ptc/payload.pyi +15 -0
  82. aip_agents/ptc/prompt_builder.py +673 -0
  83. aip_agents/ptc/prompt_builder.pyi +59 -0
  84. aip_agents/ptc/ptc_helper.py +16 -0
  85. aip_agents/ptc/ptc_helper.pyi +1 -0
  86. aip_agents/ptc/sandbox_bridge.py +256 -0
  87. aip_agents/ptc/sandbox_bridge.pyi +38 -0
  88. aip_agents/ptc/template_utils.py +33 -0
  89. aip_agents/ptc/template_utils.pyi +13 -0
  90. aip_agents/ptc/templates/__init__.py +1 -0
  91. aip_agents/ptc/templates/__init__.pyi +0 -0
  92. aip_agents/ptc/templates/ptc_helper.py.template +134 -0
  93. aip_agents/ptc/tool_def_helpers.py +101 -0
  94. aip_agents/ptc/tool_def_helpers.pyi +38 -0
  95. aip_agents/ptc/tool_enrichment.py +163 -0
  96. aip_agents/ptc/tool_enrichment.pyi +60 -0
  97. aip_agents/sandbox/__init__.py +43 -0
  98. aip_agents/sandbox/__init__.pyi +5 -0
  99. aip_agents/sandbox/defaults.py +205 -0
  100. aip_agents/sandbox/defaults.pyi +30 -0
  101. aip_agents/sandbox/e2b_runtime.py +295 -0
  102. aip_agents/sandbox/e2b_runtime.pyi +57 -0
  103. aip_agents/sandbox/template_builder.py +131 -0
  104. aip_agents/sandbox/template_builder.pyi +36 -0
  105. aip_agents/sandbox/types.py +24 -0
  106. aip_agents/sandbox/types.pyi +14 -0
  107. aip_agents/sandbox/validation.py +50 -0
  108. aip_agents/sandbox/validation.pyi +20 -0
  109. aip_agents/sentry/__init__.py +1 -1
  110. aip_agents/sentry/sentry.py +33 -12
  111. aip_agents/sentry/sentry.pyi +5 -4
  112. aip_agents/tools/__init__.py +20 -3
  113. aip_agents/tools/__init__.pyi +4 -2
  114. aip_agents/tools/browser_use/browser_use_tool.py +8 -0
  115. aip_agents/tools/browser_use/streaming.py +2 -0
  116. aip_agents/tools/code_sandbox/e2b_cloud_sandbox_extended.py +80 -31
  117. aip_agents/tools/code_sandbox/e2b_cloud_sandbox_extended.pyi +25 -9
  118. aip_agents/tools/code_sandbox/e2b_sandbox_tool.py +6 -6
  119. aip_agents/tools/constants.py +24 -12
  120. aip_agents/tools/constants.pyi +14 -11
  121. aip_agents/tools/date_range_tool.py +554 -0
  122. aip_agents/tools/date_range_tool.pyi +21 -0
  123. aip_agents/tools/execute_ptc_code.py +357 -0
  124. aip_agents/tools/execute_ptc_code.pyi +90 -0
  125. aip_agents/tools/gl_connector/__init__.py +1 -1
  126. aip_agents/tools/gl_connector/tool.py +62 -30
  127. aip_agents/tools/gl_connector/tool.pyi +3 -3
  128. aip_agents/tools/gl_connector_tools.py +119 -0
  129. aip_agents/tools/gl_connector_tools.pyi +39 -0
  130. aip_agents/tools/memory_search/__init__.py +8 -1
  131. aip_agents/tools/memory_search/__init__.pyi +3 -3
  132. aip_agents/tools/memory_search/mem0.py +114 -1
  133. aip_agents/tools/memory_search/mem0.pyi +11 -1
  134. aip_agents/tools/memory_search/schema.py +33 -0
  135. aip_agents/tools/memory_search/schema.pyi +10 -0
  136. aip_agents/tools/memory_search_tool.py +8 -0
  137. aip_agents/tools/memory_search_tool.pyi +2 -2
  138. aip_agents/utils/langgraph/tool_managers/delegation_tool_manager.py +26 -1
  139. aip_agents/utils/langgraph/tool_output_management.py +80 -0
  140. aip_agents/utils/langgraph/tool_output_management.pyi +37 -0
  141. {aip_agents_binary-0.5.21.dist-info → aip_agents_binary-0.6.8.dist-info}/METADATA +14 -22
  142. {aip_agents_binary-0.5.21.dist-info → aip_agents_binary-0.6.8.dist-info}/RECORD +144 -58
  143. {aip_agents_binary-0.5.21.dist-info → aip_agents_binary-0.6.8.dist-info}/WHEEL +1 -1
  144. aip_agents/examples/demo_memory_recall.py +0 -401
  145. aip_agents/examples/demo_memory_recall.pyi +0 -58
  146. aip_agents/examples/hello_world_langgraph_bosa_twitter.pyi +0 -5
  147. aip_agents/tools/bosa_tools.py +0 -105
  148. aip_agents/tools/bosa_tools.pyi +0 -37
  149. {aip_agents_binary-0.5.21.dist-info → aip_agents_binary-0.6.8.dist-info}/top_level.txt +0 -0
@@ -256,6 +256,104 @@ 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
+ top_k: int | None = None,
265
+ threshold: float | None = 0.3,
266
+ filters: dict[str, Any] | None = None,
267
+ ) -> list[dict[str, Any]]:
268
+ """Delete memories matching a query.
269
+
270
+ Args:
271
+ query: The search query string used to find memories to delete.
272
+ user_id: User identifier for the deletion scope.
273
+ top_k: Maximum number of memories to delete.
274
+ threshold: Minimum similarity threshold for deletion.
275
+ filters: Optional filters to apply to the deletion scope.
276
+
277
+ Returns:
278
+ List of deleted memory hits.
279
+ """
280
+ options = self._build_retrieve_options(
281
+ user_id=user_id,
282
+ limit=top_k,
283
+ filters=filters,
284
+ page=None,
285
+ )
286
+ try:
287
+ start = perf_counter()
288
+ chunks = self._runner.run(
289
+ self._manager.delete_by_user_query(
290
+ query=query,
291
+ user_id=options.user_id,
292
+ agent_id=self.agent_id,
293
+ scopes=DEFAULT_SCOPE,
294
+ metadata=options.metadata,
295
+ threshold=threshold,
296
+ top_k=options.top_k,
297
+ )
298
+ )
299
+ duration = perf_counter() - start
300
+ logger.info(
301
+ "BaseMemoryAdapter: delete_by_query user_id='%s' query='%s' deleted %d hits in %.2fs",
302
+ user_id,
303
+ query,
304
+ len(chunks),
305
+ duration,
306
+ )
307
+ except Exception as exc: # noqa: BLE001
308
+ logger.debug("BaseMemoryAdapter.delete_by_query ignored error: %s", exc)
309
+ return []
310
+
311
+ return [self._chunk_to_hit(chunk) for chunk in chunks]
312
+
313
+ def delete(
314
+ self,
315
+ *,
316
+ memory_ids: list[str] | None,
317
+ user_id: str,
318
+ metadata: dict[str, Any] | None = None,
319
+ categories: list[str] | None = None,
320
+ ) -> Any:
321
+ """Delete memories by IDs or by user scope when IDs are None.
322
+
323
+ Args:
324
+ memory_ids: Optional list of memory IDs to delete.
325
+ user_id: User identifier for the deletion scope.
326
+ metadata: Optional metadata filters to constrain deletion.
327
+ categories: Optional categories to filter by (best-effort).
328
+
329
+ Returns:
330
+ Backend-specific delete result or None on failure.
331
+ """
332
+ try:
333
+ start = perf_counter()
334
+ result = self._runner.run(
335
+ self._call_manager_with_optional_categories(
336
+ self._manager.delete,
337
+ categories=categories,
338
+ memory_ids=memory_ids,
339
+ user_id=user_id or self.agent_id,
340
+ agent_id=self.agent_id,
341
+ scopes=DEFAULT_SCOPE,
342
+ metadata=metadata,
343
+ )
344
+ )
345
+ duration = perf_counter() - start
346
+ logger.info(
347
+ "BaseMemoryAdapter: delete user_id='%s' memory_ids=%s completed in %.2fs",
348
+ user_id,
349
+ "None" if memory_ids is None else len(memory_ids),
350
+ duration,
351
+ )
352
+ return result
353
+ except Exception as exc: # noqa: BLE001
354
+ logger.debug("BaseMemoryAdapter.delete ignored error: %s", exc)
355
+ return None
356
+
259
357
  def save_interaction(self, *, user_text: str, ai_text: str, user_id: str) -> None:
260
358
  """Save a user-AI interaction as memories.
261
359
 
@@ -106,6 +106,31 @@ 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, top_k: int | None = None, threshold: float | None = 0.3, filters: dict[str, Any] | None = None) -> list[dict[str, Any]]:
110
+ """Delete memories matching a query.
111
+
112
+ Args:
113
+ query: The search query string used to find memories to delete.
114
+ user_id: User identifier for the deletion scope.
115
+ top_k: Maximum number of memories to delete.
116
+ threshold: Minimum similarity threshold for deletion.
117
+ filters: Optional filters to apply to the deletion scope.
118
+
119
+ Returns:
120
+ List of deleted memory hits.
121
+ """
122
+ def delete(self, *, memory_ids: list[str] | None, user_id: str, metadata: dict[str, Any] | None = None, categories: list[str] | None = None) -> Any:
123
+ """Delete memories by IDs or by user scope when IDs are None.
124
+
125
+ Args:
126
+ memory_ids: Optional list of memory IDs to delete.
127
+ user_id: User identifier for the deletion scope.
128
+ metadata: Optional metadata filters to constrain deletion.
129
+ categories: Optional categories to filter by (best-effort).
130
+
131
+ Returns:
132
+ Backend-specific delete result or None on failure.
133
+ """
109
134
  def save_interaction(self, *, user_text: str, ai_text: str, user_id: str) -> None:
110
135
  """Save a user-AI interaction as memories.
111
136
 
@@ -86,3 +86,11 @@ class AgentMiddleware(Protocol):
86
86
  if no updates are needed.
87
87
  """
88
88
  return {} # pragma: no cover # Protocol default - cannot be executed directly
89
+
90
+ async def abefore_model(self, state: dict[str, Any]) -> dict[str, Any]:
91
+ """Asynchronous version of before_model hook."""
92
+ return self.before_model(state)
93
+
94
+ async def aafter_model(self, state: dict[str, Any]) -> dict[str, Any]:
95
+ """Asynchronous version of after_model hook."""
96
+ return self.after_model(state)
@@ -69,3 +69,7 @@ class AgentMiddleware(Protocol):
69
69
  Dict of state updates to merge into the agent state. Return empty dict
70
70
  if no updates are needed.
71
71
  """
72
+ async def abefore_model(self, state: dict[str, Any]) -> dict[str, Any]:
73
+ """Asynchronous version of before_model hook."""
74
+ async def aafter_model(self, state: dict[str, Any]) -> dict[str, Any]:
75
+ """Asynchronous version of after_model hook."""
@@ -126,3 +126,25 @@ class MiddlewareManager:
126
126
  updates.update(mw_updates)
127
127
 
128
128
  return updates
129
+
130
+ async def abefore_model(self, state: dict[str, Any]) -> dict[str, Any]:
131
+ """Asynchronously execute before_model hooks for all middleware."""
132
+ state_updates: dict[str, Any] = {}
133
+
134
+ for mw in self.middleware:
135
+ mw_updates = await mw.abefore_model(state)
136
+ if mw_updates:
137
+ state_updates.update(mw_updates)
138
+
139
+ return state_updates
140
+
141
+ async def aafter_model(self, state: dict[str, Any]) -> dict[str, Any]:
142
+ """Asynchronously execute after_model hooks for all middleware in reverse order."""
143
+ updates: dict[str, Any] = {}
144
+
145
+ for mw in reversed(self.middleware):
146
+ mw_updates = await mw.aafter_model(state)
147
+ if mw_updates:
148
+ updates.update(mw_updates)
149
+
150
+ return updates
@@ -78,3 +78,7 @@ class MiddlewareManager:
78
78
  Merged dictionary of all state updates from all middleware.
79
79
  Updates are accumulated in reverse order of execution.
80
80
  """
81
+ async def abefore_model(self, state: dict[str, Any]) -> dict[str, Any]:
82
+ """Asynchronously execute before_model hooks for all middleware."""
83
+ async def aafter_model(self, state: dict[str, Any]) -> dict[str, Any]:
84
+ """Asynchronously execute after_model hooks for all middleware in reverse order."""
@@ -0,0 +1,87 @@
1
+ """PTC (Programmatic Tool Calling) core module.
2
+
3
+ This module provides core PTC functionality, including executor, prompt builder,
4
+ sandbox bridge, and custom tool configuration validation.
5
+
6
+ Authors:
7
+ Putu Ravindra Wiguna (putu.r.wiguna@gdplabs.id)
8
+ """
9
+
10
+ from aip_agents.ptc.custom_tools import (
11
+ PTCCustomToolConfig,
12
+ PTCCustomToolValidationError,
13
+ PTCFileToolDef,
14
+ PTCPackageToolDef,
15
+ PTCToolDef,
16
+ enrich_tool_def_with_metadata,
17
+ extract_tool_metadata,
18
+ validate_custom_tool_config,
19
+ )
20
+ from aip_agents.ptc.custom_tools_payload import (
21
+ CustomToolPayloadResult,
22
+ build_custom_tools_payload,
23
+ )
24
+ from aip_agents.ptc.exceptions import PTCError, PTCToolError
25
+ from aip_agents.ptc.prompt_builder import PromptConfig, build_ptc_prompt, compute_ptc_prompt_hash
26
+ from aip_agents.ptc.tool_def_helpers import file_tool, package_tool
27
+ from aip_agents.ptc.tool_enrichment import (
28
+ build_tool_lookup,
29
+ enrich_custom_tools_from_agent,
30
+ match_tool_by_name,
31
+ )
32
+
33
+ __all__ = [
34
+ # Exceptions
35
+ "PTCError",
36
+ "PTCToolError",
37
+ "PTCCustomToolValidationError",
38
+ # Executor
39
+ "PTCSandboxConfig",
40
+ "PTCSandboxExecutor",
41
+ # Custom tools
42
+ "PTCCustomToolConfig",
43
+ "PTCToolDef",
44
+ "PTCPackageToolDef",
45
+ "PTCFileToolDef",
46
+ "validate_custom_tool_config",
47
+ "extract_tool_metadata",
48
+ "enrich_tool_def_with_metadata",
49
+ # Tool enrichment
50
+ "build_tool_lookup",
51
+ "match_tool_by_name",
52
+ "enrich_custom_tools_from_agent",
53
+ # Tool definition helpers
54
+ "package_tool",
55
+ "file_tool",
56
+ # Custom tools payload
57
+ "CustomToolPayloadResult",
58
+ "build_custom_tools_payload",
59
+ # Prompt builder
60
+ "PromptConfig",
61
+ "build_ptc_prompt",
62
+ "compute_ptc_prompt_hash",
63
+ # Sandbox bridge
64
+ "build_sandbox_payload",
65
+ "wrap_ptc_code",
66
+ ]
67
+
68
+
69
+ def __getattr__(name: str):
70
+ """Lazy import to avoid circular dependencies."""
71
+ if name == "PTCSandboxConfig":
72
+ from aip_agents.ptc.executor import PTCSandboxConfig
73
+
74
+ return PTCSandboxConfig
75
+ elif name == "PTCSandboxExecutor":
76
+ from aip_agents.ptc.executor import PTCSandboxExecutor
77
+
78
+ return PTCSandboxExecutor
79
+ elif name == "build_sandbox_payload":
80
+ from aip_agents.ptc.sandbox_bridge import build_sandbox_payload
81
+
82
+ return build_sandbox_payload
83
+ elif name == "wrap_ptc_code":
84
+ from aip_agents.ptc.sandbox_bridge import wrap_ptc_code
85
+
86
+ return wrap_ptc_code
87
+ raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
@@ -0,0 +1,14 @@
1
+ from aip_agents.ptc.custom_tools import PTCCustomToolConfig as PTCCustomToolConfig, PTCCustomToolValidationError as PTCCustomToolValidationError, PTCFileToolDef as PTCFileToolDef, PTCPackageToolDef as PTCPackageToolDef, PTCToolDef as PTCToolDef, enrich_tool_def_with_metadata as enrich_tool_def_with_metadata, extract_tool_metadata as extract_tool_metadata, validate_custom_tool_config as validate_custom_tool_config
2
+ from aip_agents.ptc.custom_tools_payload import CustomToolPayloadResult as CustomToolPayloadResult, build_custom_tools_payload as build_custom_tools_payload
3
+ from aip_agents.ptc.exceptions import PTCError as PTCError, PTCToolError as PTCToolError
4
+ from aip_agents.ptc.prompt_builder import PromptConfig as PromptConfig, build_ptc_prompt as build_ptc_prompt, compute_ptc_prompt_hash as compute_ptc_prompt_hash
5
+ from aip_agents.ptc.tool_def_helpers import file_tool as file_tool, package_tool as package_tool
6
+ from aip_agents.ptc.tool_enrichment import build_tool_lookup as build_tool_lookup, enrich_custom_tools_from_agent as enrich_custom_tools_from_agent, match_tool_by_name as match_tool_by_name
7
+
8
+ __all__ = ['PTCError', 'PTCToolError', 'PTCCustomToolValidationError', 'PTCSandboxConfig', 'PTCSandboxExecutor', 'PTCCustomToolConfig', 'PTCToolDef', 'PTCPackageToolDef', 'PTCFileToolDef', 'validate_custom_tool_config', 'extract_tool_metadata', 'enrich_tool_def_with_metadata', 'build_tool_lookup', 'match_tool_by_name', 'enrich_custom_tools_from_agent', 'package_tool', 'file_tool', 'CustomToolPayloadResult', 'build_custom_tools_payload', 'PromptConfig', 'build_ptc_prompt', 'compute_ptc_prompt_hash', 'build_sandbox_payload', 'wrap_ptc_code']
9
+
10
+ # Names in __all__ with no definition:
11
+ # PTCSandboxConfig
12
+ # PTCSandboxExecutor
13
+ # build_sandbox_payload
14
+ # wrap_ptc_code