aip-agents-binary 0.5.25b8__py3-none-any.whl → 0.6.0__py3-none-any.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/__init__.pyi +19 -0
- aip_agents/a2a/__init__.pyi +3 -0
- aip_agents/a2a/server/__init__.pyi +4 -0
- aip_agents/a2a/server/base_executor.pyi +73 -0
- aip_agents/a2a/server/google_adk_executor.pyi +51 -0
- aip_agents/a2a/server/langflow_executor.pyi +43 -0
- aip_agents/a2a/server/langgraph_executor.pyi +47 -0
- aip_agents/a2a/types.pyi +132 -0
- aip_agents/agent/__init__.pyi +9 -0
- aip_agents/agent/base_agent.pyi +221 -0
- aip_agents/agent/base_langgraph_agent.py +137 -68
- aip_agents/agent/base_langgraph_agent.pyi +233 -0
- aip_agents/agent/google_adk_agent.pyi +141 -0
- aip_agents/agent/google_adk_constants.pyi +3 -0
- aip_agents/agent/hitl/__init__.pyi +6 -0
- aip_agents/agent/hitl/config.pyi +15 -0
- aip_agents/agent/hitl/langgraph_hitl_mixin.pyi +42 -0
- aip_agents/agent/hitl/manager.pyi +200 -0
- aip_agents/agent/hitl/models.pyi +3 -0
- aip_agents/agent/hitl/prompt/__init__.pyi +4 -0
- aip_agents/agent/hitl/prompt/base.pyi +24 -0
- aip_agents/agent/hitl/prompt/deferred.pyi +30 -0
- aip_agents/agent/hitl/registry.pyi +101 -0
- aip_agents/agent/interface.pyi +81 -0
- aip_agents/agent/interfaces.pyi +44 -0
- aip_agents/agent/langflow_agent.pyi +133 -0
- aip_agents/agent/langgraph_memory_enhancer_agent.pyi +49 -0
- aip_agents/agent/langgraph_react_agent.py +58 -14
- aip_agents/agent/langgraph_react_agent.pyi +131 -0
- aip_agents/agent/system_instruction_context.pyi +13 -0
- aip_agents/clients/__init__.pyi +4 -0
- aip_agents/clients/langflow/__init__.pyi +4 -0
- aip_agents/clients/langflow/client.pyi +140 -0
- aip_agents/clients/langflow/types.pyi +7 -0
- aip_agents/constants.pyi +7 -0
- aip_agents/examples/__init__.pyi +0 -0
- aip_agents/examples/compare_streaming_client.py +2 -2
- aip_agents/examples/compare_streaming_client.pyi +48 -0
- aip_agents/examples/compare_streaming_server.py +1 -1
- aip_agents/examples/compare_streaming_server.pyi +18 -0
- aip_agents/examples/demo_memory_recall.pyi +58 -0
- aip_agents/examples/hello_world_a2a_google_adk_client.pyi +9 -0
- aip_agents/examples/hello_world_a2a_google_adk_client_agent.pyi +9 -0
- aip_agents/examples/hello_world_a2a_google_adk_client_streaming.pyi +9 -0
- aip_agents/examples/hello_world_a2a_google_adk_server.pyi +15 -0
- aip_agents/examples/hello_world_a2a_langchain_client.pyi +5 -0
- aip_agents/examples/hello_world_a2a_langchain_client_agent.pyi +5 -0
- aip_agents/examples/hello_world_a2a_langchain_client_lm_invoker.pyi +5 -0
- aip_agents/examples/hello_world_a2a_langchain_client_streaming.pyi +5 -0
- aip_agents/examples/hello_world_a2a_langchain_reference_client_streaming.pyi +5 -0
- aip_agents/examples/hello_world_a2a_langchain_reference_server.pyi +15 -0
- aip_agents/examples/hello_world_a2a_langchain_server.pyi +15 -0
- aip_agents/examples/hello_world_a2a_langchain_server_lm_invoker.pyi +15 -0
- aip_agents/examples/hello_world_a2a_langflow_client.pyi +9 -0
- aip_agents/examples/hello_world_a2a_langflow_server.pyi +14 -0
- aip_agents/examples/hello_world_a2a_langgraph_artifact_client.pyi +5 -0
- aip_agents/examples/hello_world_a2a_langgraph_artifact_client_streaming.pyi +5 -0
- aip_agents/examples/hello_world_a2a_langgraph_artifact_server.pyi +16 -0
- aip_agents/examples/hello_world_a2a_langgraph_client.pyi +9 -0
- aip_agents/examples/hello_world_a2a_langgraph_client_agent.pyi +9 -0
- aip_agents/examples/hello_world_a2a_langgraph_client_agent_lm_invoker.pyi +2 -0
- aip_agents/examples/hello_world_a2a_langgraph_client_streaming.pyi +9 -0
- aip_agents/examples/hello_world_a2a_langgraph_client_streaming_lm_invoker.pyi +5 -0
- aip_agents/examples/hello_world_a2a_langgraph_client_streaming_tool_streaming.pyi +5 -0
- aip_agents/examples/hello_world_a2a_langgraph_server.pyi +14 -0
- aip_agents/examples/hello_world_a2a_langgraph_server_lm_invoker.pyi +15 -0
- aip_agents/examples/hello_world_a2a_langgraph_server_tool_streaming.pyi +15 -0
- aip_agents/examples/hello_world_a2a_mcp_langgraph.pyi +48 -0
- aip_agents/examples/hello_world_a2a_three_level_agent_hierarchy_client.pyi +48 -0
- aip_agents/examples/hello_world_a2a_three_level_agent_hierarchy_server.pyi +45 -0
- aip_agents/examples/hello_world_a2a_with_metadata_langchain_client.pyi +5 -0
- aip_agents/examples/hello_world_a2a_with_metadata_langchain_server_lm_invoker.pyi +15 -0
- aip_agents/examples/hello_world_google_adk.pyi +5 -0
- aip_agents/examples/hello_world_google_adk_mcp_http.pyi +5 -0
- aip_agents/examples/hello_world_google_adk_mcp_http_stream.pyi +5 -0
- aip_agents/examples/hello_world_google_adk_mcp_sse.pyi +5 -0
- aip_agents/examples/hello_world_google_adk_mcp_sse_stream.pyi +5 -0
- aip_agents/examples/hello_world_google_adk_mcp_stdio.pyi +5 -0
- aip_agents/examples/hello_world_google_adk_mcp_stdio_stream.pyi +5 -0
- aip_agents/examples/hello_world_google_adk_stream.pyi +5 -0
- aip_agents/examples/hello_world_langchain.pyi +5 -0
- aip_agents/examples/hello_world_langchain_lm_invoker.pyi +2 -0
- aip_agents/examples/hello_world_langchain_mcp_http.pyi +5 -0
- aip_agents/examples/hello_world_langchain_mcp_http_interactive.pyi +16 -0
- aip_agents/examples/hello_world_langchain_mcp_http_stream.pyi +5 -0
- aip_agents/examples/hello_world_langchain_mcp_multi_server.pyi +18 -0
- aip_agents/examples/hello_world_langchain_mcp_sse.pyi +5 -0
- aip_agents/examples/hello_world_langchain_mcp_sse_stream.pyi +5 -0
- aip_agents/examples/hello_world_langchain_mcp_stdio.pyi +5 -0
- aip_agents/examples/hello_world_langchain_mcp_stdio_stream.pyi +5 -0
- aip_agents/examples/hello_world_langchain_stream.pyi +5 -0
- aip_agents/examples/hello_world_langchain_stream_lm_invoker.pyi +5 -0
- aip_agents/examples/hello_world_langflow_agent.pyi +35 -0
- aip_agents/examples/hello_world_langgraph.pyi +5 -0
- aip_agents/examples/hello_world_langgraph_gl_connector_twitter.pyi +5 -0
- aip_agents/examples/hello_world_langgraph_mcp_http.pyi +5 -0
- aip_agents/examples/hello_world_langgraph_mcp_http_stream.pyi +5 -0
- aip_agents/examples/hello_world_langgraph_mcp_sse.pyi +5 -0
- aip_agents/examples/hello_world_langgraph_mcp_sse_stream.pyi +5 -0
- aip_agents/examples/hello_world_langgraph_mcp_stdio.pyi +5 -0
- aip_agents/examples/hello_world_langgraph_mcp_stdio_stream.pyi +5 -0
- aip_agents/examples/hello_world_langgraph_stream.pyi +5 -0
- aip_agents/examples/hello_world_langgraph_stream_lm_invoker.pyi +5 -0
- aip_agents/examples/hello_world_model_switch_cli.pyi +30 -0
- aip_agents/examples/hello_world_multi_agent_adk.pyi +6 -0
- aip_agents/examples/hello_world_multi_agent_langchain.pyi +5 -0
- aip_agents/examples/hello_world_multi_agent_langgraph.pyi +5 -0
- aip_agents/examples/hello_world_multi_agent_langgraph_lm_invoker.pyi +5 -0
- aip_agents/examples/hello_world_pii_logger.pyi +5 -0
- aip_agents/examples/hello_world_sentry.pyi +21 -0
- aip_agents/examples/hello_world_step_limits.pyi +17 -0
- aip_agents/examples/hello_world_stock_a2a_server.pyi +17 -0
- aip_agents/examples/hello_world_tool_output_client.py +9 -0
- aip_agents/examples/hello_world_tool_output_client.pyi +5 -0
- aip_agents/examples/hello_world_tool_output_server.pyi +19 -0
- aip_agents/examples/hitl_demo.pyi +67 -0
- aip_agents/examples/pii_demo_langgraph_client.pyi +5 -0
- aip_agents/examples/pii_demo_langgraph_server.pyi +20 -0
- aip_agents/examples/pii_demo_multi_agent_client.pyi +5 -0
- aip_agents/examples/pii_demo_multi_agent_server.pyi +40 -0
- aip_agents/examples/todolist_planning_a2a_langchain_client.py +2 -2
- aip_agents/examples/todolist_planning_a2a_langchain_client.pyi +5 -0
- aip_agents/examples/todolist_planning_a2a_langgraph_server.py +1 -1
- aip_agents/examples/todolist_planning_a2a_langgraph_server.pyi +19 -0
- aip_agents/examples/tools/__init__.pyi +9 -0
- aip_agents/examples/tools/adk_arithmetic_tools.pyi +24 -0
- aip_agents/examples/tools/adk_weather_tool.pyi +18 -0
- aip_agents/examples/tools/data_generator_tool.pyi +15 -0
- aip_agents/examples/tools/data_visualization_tool.pyi +19 -0
- aip_agents/examples/tools/image_artifact_tool.pyi +26 -0
- aip_agents/examples/tools/langchain_arithmetic_tools.pyi +17 -0
- aip_agents/examples/tools/langchain_currency_exchange_tool.pyi +20 -0
- aip_agents/examples/tools/langchain_graph_artifact_tool.pyi +25 -0
- aip_agents/examples/tools/langchain_weather_tool.pyi +19 -0
- aip_agents/examples/tools/langgraph_streaming_tool.pyi +43 -0
- aip_agents/examples/tools/mock_retrieval_tool.pyi +13 -0
- aip_agents/examples/tools/pii_demo_tools.pyi +54 -0
- aip_agents/examples/tools/random_chart_tool.pyi +20 -0
- aip_agents/examples/tools/serper_tool.pyi +16 -0
- aip_agents/examples/tools/stock_tools.pyi +36 -0
- aip_agents/examples/tools/table_generator_tool.pyi +22 -0
- aip_agents/examples/tools/time_tool.pyi +15 -0
- aip_agents/examples/tools/weather_forecast_tool.pyi +14 -0
- aip_agents/guardrails/__init__.pyi +6 -0
- aip_agents/guardrails/engines/__init__.pyi +4 -0
- aip_agents/guardrails/engines/base.py +6 -6
- aip_agents/guardrails/engines/base.pyi +61 -0
- aip_agents/guardrails/engines/nemo.pyi +46 -0
- aip_agents/guardrails/engines/phrase_matcher.pyi +48 -0
- aip_agents/guardrails/exceptions.pyi +23 -0
- aip_agents/guardrails/manager.pyi +42 -0
- aip_agents/guardrails/middleware.pyi +87 -0
- aip_agents/guardrails/schemas.pyi +43 -0
- aip_agents/guardrails/utils.pyi +19 -0
- aip_agents/mcp/__init__.pyi +0 -0
- aip_agents/mcp/client/__init__.pyi +5 -0
- aip_agents/mcp/client/base_mcp_client.pyi +148 -0
- aip_agents/mcp/client/connection_manager.py +36 -1
- aip_agents/mcp/client/connection_manager.pyi +51 -0
- aip_agents/mcp/client/google_adk/__init__.pyi +3 -0
- aip_agents/mcp/client/google_adk/client.pyi +75 -0
- aip_agents/mcp/client/langchain/__init__.pyi +3 -0
- aip_agents/mcp/client/langchain/client.pyi +48 -0
- aip_agents/mcp/client/persistent_session.py +318 -68
- aip_agents/mcp/client/persistent_session.pyi +122 -0
- aip_agents/mcp/client/session_pool.pyi +101 -0
- aip_agents/mcp/client/transports.py +33 -2
- aip_agents/mcp/client/transports.pyi +132 -0
- aip_agents/mcp/utils/__init__.pyi +0 -0
- aip_agents/mcp/utils/config_validator.pyi +82 -0
- aip_agents/memory/__init__.pyi +5 -0
- aip_agents/memory/adapters/__init__.pyi +4 -0
- aip_agents/memory/adapters/base_adapter.pyi +150 -0
- aip_agents/memory/adapters/mem0.pyi +22 -0
- aip_agents/memory/base.pyi +60 -0
- aip_agents/memory/constants.pyi +25 -0
- aip_agents/memory/factory.pyi +24 -0
- aip_agents/memory/guidance.pyi +3 -0
- aip_agents/memory/simple_memory.pyi +23 -0
- aip_agents/middleware/__init__.pyi +5 -0
- aip_agents/middleware/base.pyi +75 -0
- aip_agents/middleware/manager.pyi +84 -0
- aip_agents/middleware/todolist.pyi +125 -0
- aip_agents/schema/__init__.pyi +9 -0
- aip_agents/schema/a2a.pyi +40 -0
- aip_agents/schema/agent.pyi +65 -0
- aip_agents/schema/hitl.pyi +89 -0
- aip_agents/schema/langgraph.pyi +28 -0
- aip_agents/schema/model_id.pyi +54 -0
- aip_agents/schema/step_limit.pyi +63 -0
- aip_agents/schema/storage.pyi +21 -0
- aip_agents/sentry/__init__.pyi +3 -0
- aip_agents/sentry/sentry.pyi +48 -0
- aip_agents/storage/__init__.pyi +8 -0
- aip_agents/storage/base.pyi +58 -0
- aip_agents/storage/clients/__init__.pyi +3 -0
- aip_agents/storage/clients/minio_client.pyi +137 -0
- aip_agents/storage/config.pyi +29 -0
- aip_agents/storage/providers/__init__.pyi +5 -0
- aip_agents/storage/providers/base.pyi +88 -0
- aip_agents/storage/providers/memory.pyi +79 -0
- aip_agents/storage/providers/object_storage.pyi +98 -0
- aip_agents/tools/__init__.pyi +9 -0
- aip_agents/tools/browser_use/__init__.pyi +14 -0
- aip_agents/tools/browser_use/action_parser.pyi +18 -0
- aip_agents/tools/browser_use/browser_use_tool.py +8 -0
- aip_agents/tools/browser_use/browser_use_tool.pyi +50 -0
- aip_agents/tools/browser_use/llm_config.pyi +52 -0
- aip_agents/tools/browser_use/minio_storage.pyi +109 -0
- aip_agents/tools/browser_use/schemas.pyi +32 -0
- aip_agents/tools/browser_use/session.pyi +4 -0
- aip_agents/tools/browser_use/session_errors.pyi +53 -0
- aip_agents/tools/browser_use/steel_session_recording.pyi +63 -0
- aip_agents/tools/browser_use/streaming.py +2 -0
- aip_agents/tools/browser_use/streaming.pyi +81 -0
- aip_agents/tools/browser_use/structured_data_parser.pyi +86 -0
- aip_agents/tools/browser_use/structured_data_recovery.pyi +43 -0
- aip_agents/tools/browser_use/types.pyi +45 -0
- aip_agents/tools/code_sandbox/__init__.pyi +3 -0
- aip_agents/tools/code_sandbox/constant.pyi +4 -0
- aip_agents/tools/code_sandbox/e2b_cloud_sandbox_extended.pyi +102 -0
- aip_agents/tools/code_sandbox/e2b_sandbox_tool.pyi +29 -0
- aip_agents/tools/constants.pyi +138 -0
- aip_agents/tools/document_loader/__init__.pyi +7 -0
- aip_agents/tools/document_loader/base_reader.pyi +75 -0
- aip_agents/tools/document_loader/docx_reader_tool.pyi +10 -0
- aip_agents/tools/document_loader/excel_reader_tool.pyi +26 -0
- aip_agents/tools/document_loader/pdf_reader_tool.pyi +11 -0
- aip_agents/tools/document_loader/pdf_splitter.pyi +18 -0
- aip_agents/tools/gl_connector/__init__.pyi +3 -0
- aip_agents/tools/gl_connector/tool.pyi +74 -0
- aip_agents/tools/gl_connector_tools.pyi +39 -0
- aip_agents/tools/memory_search/__init__.pyi +5 -0
- aip_agents/tools/memory_search/base.pyi +69 -0
- aip_agents/tools/memory_search/mem0.pyi +19 -0
- aip_agents/tools/memory_search/schema.pyi +15 -0
- aip_agents/tools/memory_search_tool.pyi +3 -0
- aip_agents/tools/time_tool.pyi +16 -0
- aip_agents/tools/tool_config_injector.pyi +26 -0
- aip_agents/tools/web_search/__init__.pyi +3 -0
- aip_agents/tools/web_search/serper_tool.pyi +19 -0
- aip_agents/types/__init__.pyi +36 -0
- aip_agents/types/a2a_events.pyi +3 -0
- aip_agents/utils/__init__.pyi +11 -0
- aip_agents/utils/a2a_connector.pyi +146 -0
- aip_agents/utils/artifact_helpers.pyi +203 -0
- aip_agents/utils/constants.pyi +10 -0
- aip_agents/utils/datetime/__init__.pyi +4 -0
- aip_agents/utils/datetime/normalization.pyi +95 -0
- aip_agents/utils/datetime/timezone.pyi +48 -0
- aip_agents/utils/env_loader.pyi +10 -0
- aip_agents/utils/event_handler_registry.pyi +23 -0
- aip_agents/utils/file_prompt_utils.pyi +21 -0
- aip_agents/utils/final_response_builder.pyi +34 -0
- aip_agents/utils/formatter_llm_client.pyi +71 -0
- aip_agents/utils/langgraph/__init__.pyi +3 -0
- aip_agents/utils/langgraph/converter.pyi +49 -0
- aip_agents/utils/langgraph/tool_managers/__init__.pyi +5 -0
- aip_agents/utils/langgraph/tool_managers/a2a_tool_manager.pyi +35 -0
- aip_agents/utils/langgraph/tool_managers/base_tool_manager.pyi +48 -0
- aip_agents/utils/langgraph/tool_managers/delegation_tool_manager.py +26 -1
- aip_agents/utils/langgraph/tool_managers/delegation_tool_manager.pyi +56 -0
- aip_agents/utils/langgraph/tool_output_management.py +80 -0
- aip_agents/utils/langgraph/tool_output_management.pyi +329 -0
- aip_agents/utils/logger.pyi +60 -0
- aip_agents/utils/metadata/__init__.pyi +5 -0
- aip_agents/utils/metadata/activity_metadata_helper.pyi +25 -0
- aip_agents/utils/metadata/activity_narrative/__init__.pyi +7 -0
- aip_agents/utils/metadata/activity_narrative/builder.pyi +35 -0
- aip_agents/utils/metadata/activity_narrative/constants.pyi +10 -0
- aip_agents/utils/metadata/activity_narrative/context.pyi +32 -0
- aip_agents/utils/metadata/activity_narrative/formatters.pyi +48 -0
- aip_agents/utils/metadata/activity_narrative/utils.pyi +12 -0
- aip_agents/utils/metadata/schemas/__init__.pyi +4 -0
- aip_agents/utils/metadata/schemas/activity_schema.pyi +18 -0
- aip_agents/utils/metadata/schemas/thinking_schema.pyi +20 -0
- aip_agents/utils/metadata/thinking_metadata_helper.pyi +4 -0
- aip_agents/utils/metadata_helper.pyi +117 -0
- aip_agents/utils/name_preprocessor/__init__.pyi +6 -0
- aip_agents/utils/name_preprocessor/base_name_preprocessor.pyi +52 -0
- aip_agents/utils/name_preprocessor/google_name_preprocessor.pyi +38 -0
- aip_agents/utils/name_preprocessor/name_preprocessor.pyi +41 -0
- aip_agents/utils/name_preprocessor/openai_name_preprocessor.pyi +34 -0
- aip_agents/utils/pii/__init__.pyi +5 -0
- aip_agents/utils/pii/pii_handler.pyi +96 -0
- aip_agents/utils/pii/pii_helper.pyi +78 -0
- aip_agents/utils/pii/uuid_deanonymizer_mapping.pyi +73 -0
- aip_agents/utils/reference_helper.pyi +81 -0
- aip_agents/utils/sse_chunk_transformer.pyi +166 -0
- aip_agents/utils/step_limit_manager.pyi +112 -0
- aip_agents/utils/token_usage_helper.pyi +60 -0
- {aip_agents_binary-0.5.25b8.dist-info → aip_agents_binary-0.6.0.dist-info}/METADATA +51 -48
- aip_agents_binary-0.6.0.dist-info/RECORD +566 -0
- aip_agents_binary-0.5.25b8.dist-info/RECORD +0 -290
- {aip_agents_binary-0.5.25b8.dist-info → aip_agents_binary-0.6.0.dist-info}/WHEEL +0 -0
- {aip_agents_binary-0.5.25b8.dist-info → aip_agents_binary-0.6.0.dist-info}/top_level.txt +0 -0
|
@@ -12,10 +12,11 @@ from collections.abc import AsyncIterator
|
|
|
12
12
|
from enum import StrEnum
|
|
13
13
|
from typing import Any, Protocol
|
|
14
14
|
|
|
15
|
+
import httpx
|
|
15
16
|
from gllm_tools.mcp.client.config import MCPConfiguration
|
|
16
17
|
from mcp.client.sse import sse_client
|
|
17
18
|
from mcp.client.stdio import StdioServerParameters, stdio_client
|
|
18
|
-
from mcp.client.streamable_http import
|
|
19
|
+
from mcp.client.streamable_http import streamable_http_client
|
|
19
20
|
|
|
20
21
|
from aip_agents.utils.logger import get_logger
|
|
21
22
|
|
|
@@ -142,6 +143,27 @@ class SSETransport(Transport):
|
|
|
142
143
|
class HTTPTransport(Transport):
|
|
143
144
|
"""Streamable HTTP transport handler."""
|
|
144
145
|
|
|
146
|
+
def __init__(self, server_name: str, config: MCPConfiguration) -> None:
|
|
147
|
+
"""Initialize the HTTP transport.
|
|
148
|
+
|
|
149
|
+
Args:
|
|
150
|
+
server_name (str): Name of the MCP server.
|
|
151
|
+
config (MCPConfiguration): Configuration for the transport.
|
|
152
|
+
"""
|
|
153
|
+
super().__init__(server_name, config)
|
|
154
|
+
self._http_client: httpx.AsyncClient | None = None
|
|
155
|
+
|
|
156
|
+
async def close(self) -> None:
|
|
157
|
+
"""Clean up the transport connection and any owned HTTP client."""
|
|
158
|
+
await super().close()
|
|
159
|
+
if self._http_client:
|
|
160
|
+
try:
|
|
161
|
+
await self._http_client.aclose()
|
|
162
|
+
except Exception as e:
|
|
163
|
+
logger.warning(f"Error during HTTP client cleanup for {self.server_name}: {e}")
|
|
164
|
+
finally:
|
|
165
|
+
self._http_client = None
|
|
166
|
+
|
|
145
167
|
async def connect(self) -> tuple[AsyncIterator[bytes], AsyncIterator[bytes], TransportContext]:
|
|
146
168
|
"""Connect using streamable HTTP transport.
|
|
147
169
|
|
|
@@ -163,11 +185,20 @@ class HTTPTransport(Transport):
|
|
|
163
185
|
headers = _sanitize_headers(self.config)
|
|
164
186
|
logger.debug(f"Attempting streamable HTTP connection to {url} with headers: {list(headers.keys())}")
|
|
165
187
|
try:
|
|
166
|
-
|
|
188
|
+
http_client = httpx.AsyncClient(timeout=httpx.Timeout(timeout), headers=headers)
|
|
189
|
+
self._http_client = http_client
|
|
190
|
+
self.ctx = streamable_http_client(url=url, http_client=http_client)
|
|
167
191
|
read_stream, write_stream, _ = await self.ctx.__aenter__()
|
|
168
192
|
logger.info(f"Connected to {self.server_name} via HTTP")
|
|
169
193
|
return read_stream, write_stream, self.ctx
|
|
170
194
|
except Exception as e:
|
|
195
|
+
if self._http_client:
|
|
196
|
+
try:
|
|
197
|
+
await self._http_client.aclose()
|
|
198
|
+
except Exception as close_exc:
|
|
199
|
+
logger.warning(f"Error during HTTP client cleanup for {self.server_name}: {close_exc}")
|
|
200
|
+
finally:
|
|
201
|
+
self._http_client = None
|
|
171
202
|
raise ConnectionError(f"HTTP connection failed for {self.server_name}: {str(e)}") from e
|
|
172
203
|
|
|
173
204
|
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from abc import ABC, abstractmethod
|
|
3
|
+
from aip_agents.utils.logger import get_logger as get_logger
|
|
4
|
+
from collections.abc import AsyncIterator as AsyncIterator
|
|
5
|
+
from enum import StrEnum
|
|
6
|
+
from gllm_tools.mcp.client.config import MCPConfiguration
|
|
7
|
+
from typing import Any, Protocol
|
|
8
|
+
|
|
9
|
+
class TransportContext(Protocol):
|
|
10
|
+
"""Protocol defining the interface for async context managers used in MCP transport connections."""
|
|
11
|
+
async def __aenter__(self) -> None:
|
|
12
|
+
"""Enter the async context, establishing the connection and returning read/write streams."""
|
|
13
|
+
async def __aexit__(self, _exc_type, _exc_val, _exc_tb) -> None:
|
|
14
|
+
"""Exit the async context, performing cleanup and closing the connection.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
_exc_type: Exception type if an exception occurred.
|
|
18
|
+
_exc_val: Exception value if an exception occurred.
|
|
19
|
+
_exc_tb: Exception traceback if an exception occurred.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
logger: Incomplete
|
|
23
|
+
DEFAULT_TIMEOUT: float
|
|
24
|
+
|
|
25
|
+
class TransportType(StrEnum):
|
|
26
|
+
"""Enum for supported MCP transport types."""
|
|
27
|
+
HTTP: str
|
|
28
|
+
SSE: str
|
|
29
|
+
STDIO: str
|
|
30
|
+
|
|
31
|
+
class Transport(ABC):
|
|
32
|
+
"""Abstract base class for MCP transports."""
|
|
33
|
+
server_name: Incomplete
|
|
34
|
+
config: Incomplete
|
|
35
|
+
ctx: Any
|
|
36
|
+
def __init__(self, server_name: str, config: MCPConfiguration) -> None:
|
|
37
|
+
"""Initialize the transport.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
server_name (str): Name of the MCP server.
|
|
41
|
+
config (MCPConfiguration): Configuration for the transport.
|
|
42
|
+
"""
|
|
43
|
+
@abstractmethod
|
|
44
|
+
async def connect(self) -> tuple[AsyncIterator[bytes], AsyncIterator[bytes], TransportContext]:
|
|
45
|
+
"""Establish connection and return read/write streams and context manager.
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
tuple[AsyncIterator[bytes], AsyncIterator[bytes], Any]:
|
|
49
|
+
(read_stream, write_stream, ctx)
|
|
50
|
+
Where:
|
|
51
|
+
- read_stream: AsyncIterator[bytes] for reading from the server.
|
|
52
|
+
- write_stream: AsyncIterator[bytes] for writing to the server.
|
|
53
|
+
- ctx: The async context manager instance for cleanup via __aexit__.
|
|
54
|
+
|
|
55
|
+
Raises:
|
|
56
|
+
ValueError: If required config (e.g., URL or command) is missing.
|
|
57
|
+
ConnectionError: If connection establishment fails.
|
|
58
|
+
"""
|
|
59
|
+
async def close(self) -> None:
|
|
60
|
+
"""Clean up the transport connection."""
|
|
61
|
+
|
|
62
|
+
class SSETransport(Transport):
|
|
63
|
+
"""SSE transport handler."""
|
|
64
|
+
ctx: Incomplete
|
|
65
|
+
async def connect(self) -> tuple[AsyncIterator[bytes], AsyncIterator[bytes], TransportContext]:
|
|
66
|
+
"""Connect using SSE transport.
|
|
67
|
+
|
|
68
|
+
Builds SSE URL from config, initializes client with timeout, and enters context.
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
tuple[AsyncIterator[bytes], AsyncIterator[bytes], Any]: (read_stream, write_stream, ctx)
|
|
72
|
+
|
|
73
|
+
Raises:
|
|
74
|
+
ValueError: If URL is missing.
|
|
75
|
+
ConnectionError: If SSE connection fails.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
class HTTPTransport(Transport):
|
|
79
|
+
"""Streamable HTTP transport handler."""
|
|
80
|
+
def __init__(self, server_name: str, config: MCPConfiguration) -> None:
|
|
81
|
+
"""Initialize the HTTP transport.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
server_name (str): Name of the MCP server.
|
|
85
|
+
config (MCPConfiguration): Configuration for the transport.
|
|
86
|
+
"""
|
|
87
|
+
async def close(self) -> None:
|
|
88
|
+
"""Clean up the transport connection and any owned HTTP client."""
|
|
89
|
+
ctx: Incomplete
|
|
90
|
+
async def connect(self) -> tuple[AsyncIterator[bytes], AsyncIterator[bytes], TransportContext]:
|
|
91
|
+
"""Connect using streamable HTTP transport.
|
|
92
|
+
|
|
93
|
+
Builds MCP URL from config, initializes client with timeout, and enters context.
|
|
94
|
+
|
|
95
|
+
Returns:
|
|
96
|
+
tuple[AsyncIterator[bytes], AsyncIterator[bytes], Any]: (read_stream, write_stream, ctx)
|
|
97
|
+
|
|
98
|
+
Raises:
|
|
99
|
+
ValueError: If URL is missing.
|
|
100
|
+
ConnectionError: If HTTP connection fails.
|
|
101
|
+
"""
|
|
102
|
+
|
|
103
|
+
class StdioTransport(Transport):
|
|
104
|
+
"""STDIO transport handler."""
|
|
105
|
+
ctx: Incomplete
|
|
106
|
+
async def connect(self) -> tuple[AsyncIterator[bytes], AsyncIterator[bytes], TransportContext]:
|
|
107
|
+
"""Connect using STDIO transport.
|
|
108
|
+
|
|
109
|
+
Initializes stdio client from command/args/env in config and enters context.
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
tuple[AsyncIterator[bytes], AsyncIterator[bytes], Any]: (read_stream, write_stream, ctx)
|
|
113
|
+
|
|
114
|
+
Raises:
|
|
115
|
+
ValueError: If command is missing.
|
|
116
|
+
ConnectionError: If STDIO connection fails.
|
|
117
|
+
"""
|
|
118
|
+
|
|
119
|
+
def create_transport(server_name: str, config: MCPConfiguration, transport_type: TransportType | str) -> Transport:
|
|
120
|
+
"""Factory to create the appropriate transport instance.
|
|
121
|
+
|
|
122
|
+
Args:
|
|
123
|
+
server_name (str): Server name
|
|
124
|
+
config (MCPConfiguration): Config
|
|
125
|
+
transport_type (str): Transport type ('http', 'sse', 'stdio')
|
|
126
|
+
|
|
127
|
+
Returns:
|
|
128
|
+
Transport: Concrete transport instance
|
|
129
|
+
|
|
130
|
+
Raises:
|
|
131
|
+
ValueError: If transport_type is unsupported.
|
|
132
|
+
"""
|
|
File without changes
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from aip_agents.utils.logger import get_logger as get_logger
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
logger: Incomplete
|
|
6
|
+
|
|
7
|
+
def validate_allowed_tools_list(allowed_tools: list[str] | None, context: str) -> list[str] | None:
|
|
8
|
+
'''Validate that allowed_tools is a list of strings or None.
|
|
9
|
+
|
|
10
|
+
This function validates the type and contents of allowed_tools parameter.
|
|
11
|
+
It can be used to validate allowed_tools from any source (config dict, function parameter, etc).
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
allowed_tools: The allowed_tools value to validate (can be any type)
|
|
15
|
+
context: Context string for error messages (e.g., "Server \'my_server\'", "\'allowed_tools\' parameter")
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
Validated list of allowed tool names, or None if allowed_tools is None or empty.
|
|
19
|
+
None/empty means no restriction (all tools allowed).
|
|
20
|
+
|
|
21
|
+
Raises:
|
|
22
|
+
ValueError: If allowed_tools is not None/list or contains non-string elements
|
|
23
|
+
|
|
24
|
+
Examples:
|
|
25
|
+
>>> validate_allowed_tools_list(None, "test")
|
|
26
|
+
None
|
|
27
|
+
>>> validate_allowed_tools_list([], "test")
|
|
28
|
+
None
|
|
29
|
+
>>> validate_allowed_tools_list(["tool1", "tool2"], "test")
|
|
30
|
+
[\'tool1\', \'tool2\']
|
|
31
|
+
>>> validate_allowed_tools_list("invalid", "test") # doctest: +SKIP
|
|
32
|
+
ValueError: test: \'allowed_tools\' must be a list of strings, got str
|
|
33
|
+
'''
|
|
34
|
+
def validate_allowed_tools_config(config: dict[str, Any], server_name: str) -> list[str] | None:
|
|
35
|
+
'''Validate and extract allowed_tools configuration from server config.
|
|
36
|
+
|
|
37
|
+
This function validates that the allowed_tools field, if present, is a list of strings.
|
|
38
|
+
It returns a normalized list of allowed tool names, or None if not specified/empty.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
config: Server configuration dictionary that may contain \'allowed_tools\' field
|
|
42
|
+
server_name: Name of the server (for error messages)
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
List of allowed tool names, or None if allowed_tools is not specified or is empty.
|
|
46
|
+
None means no restriction (all tools allowed).
|
|
47
|
+
|
|
48
|
+
Raises:
|
|
49
|
+
ValueError: If allowed_tools is present but not a list
|
|
50
|
+
ValueError: If allowed_tools contains non-string elements
|
|
51
|
+
|
|
52
|
+
Examples:
|
|
53
|
+
>>> validate_allowed_tools_config({"url": "..."}, "my_server")
|
|
54
|
+
None
|
|
55
|
+
>>> validate_allowed_tools_config({"url": "...", "allowed_tools": []}, "my_server")
|
|
56
|
+
None
|
|
57
|
+
>>> validate_allowed_tools_config({"url": "...", "allowed_tools": ["tool1", "tool2"]}, "my_server")
|
|
58
|
+
[\'tool1\', \'tool2\']
|
|
59
|
+
'''
|
|
60
|
+
def validate_mcp_server_config(config: dict[str, Any], server_name: str) -> dict[str, Any]:
|
|
61
|
+
'''Validate complete MCP server configuration including allowed_tools.
|
|
62
|
+
|
|
63
|
+
This function performs comprehensive validation on an MCP server configuration,
|
|
64
|
+
ensuring all required fields are present and allowed_tools (if present) is valid.
|
|
65
|
+
Unknown configuration fields (such as any leftover disabled_tools) are silently ignored.
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
config: Server configuration dictionary
|
|
69
|
+
server_name: Name of the server (for error messages)
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
Validated configuration dictionary (same as input, after validation)
|
|
73
|
+
|
|
74
|
+
Raises:
|
|
75
|
+
ValueError: If configuration is invalid
|
|
76
|
+
|
|
77
|
+
Examples:
|
|
78
|
+
>>> validate_mcp_server_config({"url": "http://localhost:8080"}, "my_server")
|
|
79
|
+
{\'url\': \'http://localhost:8080\'}
|
|
80
|
+
>>> validate_mcp_server_config({"command": "python", "args": ["server.py"]}, "my_server")
|
|
81
|
+
{\'command\': \'python\', \'args\': [\'server.py\']}
|
|
82
|
+
'''
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from aip_agents.memory.base import BaseMemory as BaseMemory
|
|
3
|
+
from aip_agents.memory.constants import MemoryDefaults as MemoryDefaults
|
|
4
|
+
from aip_agents.types import ChatMessage as ChatMessage
|
|
5
|
+
from aip_agents.utils.datetime import format_created_updated_label as format_created_updated_label
|
|
6
|
+
from aip_agents.utils.logger import get_logger as get_logger
|
|
7
|
+
from concurrent.futures import Future
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from gllm_memory import MemoryManager
|
|
10
|
+
from gllm_memory.enums import MemoryScope
|
|
11
|
+
from typing import Any, ClassVar
|
|
12
|
+
|
|
13
|
+
MemoryManager = Any
|
|
14
|
+
MemoryScope = Any
|
|
15
|
+
logger: Incomplete
|
|
16
|
+
DEFAULT_SCOPE: ClassVar[set[MemoryScope]]
|
|
17
|
+
|
|
18
|
+
@dataclass(frozen=True)
|
|
19
|
+
class _RetrieveOptions:
|
|
20
|
+
user_id: str
|
|
21
|
+
top_k: int
|
|
22
|
+
metadata: dict[str, str] | None
|
|
23
|
+
keywords: Any
|
|
24
|
+
page: int
|
|
25
|
+
categories: list[str] | None
|
|
26
|
+
|
|
27
|
+
class _AsyncRunner:
|
|
28
|
+
"""Runs async coroutines on a dedicated background event loop."""
|
|
29
|
+
def __init__(self) -> None: ...
|
|
30
|
+
def run(self, awaitable: Any) -> Any:
|
|
31
|
+
"""Execute an awaitable on the background loop and block for the result.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
awaitable: The coroutine to execute.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
The result of the coroutine execution.
|
|
38
|
+
"""
|
|
39
|
+
def shutdown(self, timeout: float | None = 5.0) -> None:
|
|
40
|
+
"""Gracefully stop the event loop thread.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
timeout: Maximum time to wait for the thread to stop.
|
|
44
|
+
"""
|
|
45
|
+
def __del__(self) -> None: ...
|
|
46
|
+
|
|
47
|
+
class BaseMemoryAdapter(BaseMemory):
|
|
48
|
+
"""Provider-agnostic long-term memory adapter backed by gllm_memory."""
|
|
49
|
+
agent_id: Incomplete
|
|
50
|
+
namespace: Incomplete
|
|
51
|
+
limit: Incomplete
|
|
52
|
+
max_chars: Incomplete
|
|
53
|
+
def __init__(self, *, agent_id: str, manager: MemoryManager, namespace: str | None = None, limit: int = ..., max_chars: int = ...) -> None:
|
|
54
|
+
"""Initialize the GLLM memory adapter.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
agent_id: Unique identifier for the agent using this memory.
|
|
58
|
+
manager: Configured gllm_memory MemoryManager instance.
|
|
59
|
+
namespace: Optional namespace for organizing memories.
|
|
60
|
+
limit: Maximum number of memories to retrieve in search operations.
|
|
61
|
+
max_chars: Maximum character length for text content.
|
|
62
|
+
"""
|
|
63
|
+
@classmethod
|
|
64
|
+
def validate_env(cls) -> None:
|
|
65
|
+
"""Base adapter does not enforce environment validation."""
|
|
66
|
+
def get_messages(self) -> list[ChatMessage]:
|
|
67
|
+
"""Retrieve all stored chat messages.
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
An empty list as GLLM adapter doesn't support message retrieval.
|
|
71
|
+
"""
|
|
72
|
+
def add_message(self, message: ChatMessage) -> None:
|
|
73
|
+
"""Best-effort single-message persistence for API parity.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
message: The chat message to add to memory.
|
|
77
|
+
"""
|
|
78
|
+
def clear(self) -> None:
|
|
79
|
+
"""Clear all stored memories.
|
|
80
|
+
|
|
81
|
+
Raises:
|
|
82
|
+
NotImplementedError: This method is not implemented for GLLM adapter.
|
|
83
|
+
"""
|
|
84
|
+
def search(self, query: str, *, user_id: str, limit: int | None = None, filters: dict[str, Any] | None = None) -> list[dict[str, Any]]:
|
|
85
|
+
"""Search for memories using a text query.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
query: The search query string.
|
|
89
|
+
user_id: User identifier for the search scope.
|
|
90
|
+
limit: Maximum number of results to return.
|
|
91
|
+
filters: Optional filters to apply to the search.
|
|
92
|
+
|
|
93
|
+
Returns:
|
|
94
|
+
List of memory hits matching the search criteria.
|
|
95
|
+
"""
|
|
96
|
+
def retrieve(self, *, query: str | None, user_id: str, limit: int | None = None, filters: dict[str, Any] | None = None, page: int | None = None) -> list[dict[str, Any]]:
|
|
97
|
+
"""Retrieve memories with optional search query and filters.
|
|
98
|
+
|
|
99
|
+
Args:
|
|
100
|
+
query: Optional search query string. If None, retrieves all memories.
|
|
101
|
+
user_id: User identifier for the retrieval scope.
|
|
102
|
+
limit: Maximum number of results to return.
|
|
103
|
+
filters: Optional filters to apply to the retrieval.
|
|
104
|
+
page: Page number for pagination.
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
List of memory hits matching the criteria.
|
|
108
|
+
"""
|
|
109
|
+
def save_interaction(self, *, user_text: str, ai_text: str, user_id: str) -> None:
|
|
110
|
+
"""Save a user-AI interaction as memories.
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
user_text: The user's input text.
|
|
114
|
+
ai_text: The AI's response text.
|
|
115
|
+
user_id: User identifier for the memory storage.
|
|
116
|
+
"""
|
|
117
|
+
def save_interaction_async(self, *, user_text: str, ai_text: str, user_id: str) -> Future[Any]:
|
|
118
|
+
"""Schedule save_interaction without blocking the caller.
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
user_text: The user's input text to save.
|
|
122
|
+
ai_text: The AI's response text to save.
|
|
123
|
+
user_id: User identifier for the memory storage.
|
|
124
|
+
"""
|
|
125
|
+
def format_hits(self, hits: list[dict[str, Any]], max_items: int = ..., with_tag: bool = True) -> str:
|
|
126
|
+
"""Format memory hits into a readable string.
|
|
127
|
+
|
|
128
|
+
Args:
|
|
129
|
+
hits: List of memory hit dictionaries to format.
|
|
130
|
+
max_items: Maximum number of hits to include in the output.
|
|
131
|
+
with_tag: Whether to wrap the output with memory tags.
|
|
132
|
+
|
|
133
|
+
Returns:
|
|
134
|
+
Formatted string representation of the memory hits.
|
|
135
|
+
"""
|
|
136
|
+
def flush_pending_writes(self, timeout: float | None = None) -> None:
|
|
137
|
+
"""Block until current async writes complete.
|
|
138
|
+
|
|
139
|
+
Args:
|
|
140
|
+
timeout: Maximum time to wait for pending writes to complete.
|
|
141
|
+
"""
|
|
142
|
+
def close(self, *, wait: bool = True, timeout: float | None = None) -> None:
|
|
143
|
+
"""Release background resources and optionally wait for pending saves.
|
|
144
|
+
|
|
145
|
+
Args:
|
|
146
|
+
wait: Whether to wait for pending async operations to complete.
|
|
147
|
+
timeout: Maximum time to wait when wait=True.
|
|
148
|
+
"""
|
|
149
|
+
def __del__(self) -> None:
|
|
150
|
+
"""Clean up resources when the adapter is garbage collected."""
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from aip_agents.memory.adapters.base_adapter import BaseMemoryAdapter as BaseMemoryAdapter
|
|
2
|
+
from aip_agents.memory.constants import MemoryDefaults as MemoryDefaults
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
MemoryManager = Any
|
|
6
|
+
|
|
7
|
+
class Mem0Memory(BaseMemoryAdapter):
|
|
8
|
+
"""Mem0-backed long-term memory adapter using the gllm_memory SDK."""
|
|
9
|
+
def __init__(self, *, agent_id: str, namespace: str | None = None, limit: int = ..., max_chars: int = ..., host: str | None = None, instruction: str | None = None) -> None:
|
|
10
|
+
"""Initialize the Mem0 memory adapter.
|
|
11
|
+
|
|
12
|
+
Args:
|
|
13
|
+
agent_id: Unique identifier for the agent using this memory.
|
|
14
|
+
namespace: Optional namespace for organizing memories.
|
|
15
|
+
limit: Maximum number of memories to retrieve in search operations.
|
|
16
|
+
max_chars: Maximum character length for text content.
|
|
17
|
+
host: Optional host URL for the Mem0 service.
|
|
18
|
+
instruction: Optional instruction text for memory operations.
|
|
19
|
+
"""
|
|
20
|
+
@classmethod
|
|
21
|
+
def validate_env(cls) -> None:
|
|
22
|
+
"""Ensure the Mem0 API key is available."""
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from aip_agents.types import ChatMessage as ChatMessage
|
|
3
|
+
from collections.abc import Sequence
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
class BaseMemory(ABC):
|
|
7
|
+
"""Base class for agent memory.
|
|
8
|
+
|
|
9
|
+
This concrete base class provides a default structure. Subclasses
|
|
10
|
+
can inherit from this class to implement specific memory management
|
|
11
|
+
behaviors.
|
|
12
|
+
"""
|
|
13
|
+
@classmethod
|
|
14
|
+
def validate_env(cls) -> None:
|
|
15
|
+
"""Validate environment prerequisites for a memory backend.
|
|
16
|
+
|
|
17
|
+
This hook allows memory implementations to fail fast when required
|
|
18
|
+
environment variables or credentials are missing. Default is a no-op.
|
|
19
|
+
"""
|
|
20
|
+
@abstractmethod
|
|
21
|
+
def get_messages(self) -> list[ChatMessage]:
|
|
22
|
+
"""Retrieve a list of messages.
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
List[ChatMessage]: A list of messages in a generic format.
|
|
26
|
+
"""
|
|
27
|
+
@abstractmethod
|
|
28
|
+
def add_message(self, message: ChatMessage) -> None:
|
|
29
|
+
"""Add a message to the memory.
|
|
30
|
+
|
|
31
|
+
Adds a single ChatMessage to the memory storage. The exact implementation
|
|
32
|
+
depends on the specific memory backend.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
message: The ChatMessage object to add to memory. The message should
|
|
36
|
+
contain role and content information.
|
|
37
|
+
"""
|
|
38
|
+
def add_messages(self, messages: Sequence[ChatMessage]) -> None:
|
|
39
|
+
"""Add multiple messages to the memory.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
messages: A sequence of ChatMessage objects to add.
|
|
43
|
+
"""
|
|
44
|
+
@abstractmethod
|
|
45
|
+
def clear(self) -> None:
|
|
46
|
+
"""Clears the memory or resets the state of the agent.
|
|
47
|
+
|
|
48
|
+
This method must be implemented to define the specific behavior
|
|
49
|
+
for clearing or resetting the memory of the agent.
|
|
50
|
+
"""
|
|
51
|
+
def get_memory_variables(self) -> dict[str, Any]:
|
|
52
|
+
"""Retrieve memory variables.
|
|
53
|
+
|
|
54
|
+
This method returns a dictionary containing memory-related variables.
|
|
55
|
+
The default implementation returns a dictionary with chat_history.
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
Dict[str, Any]: A dictionary where keys are variable names and values
|
|
59
|
+
are the corresponding memory-related data.
|
|
60
|
+
"""
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
|
|
3
|
+
class MemoryMethod:
|
|
4
|
+
"""Constants for memory method names used in hasattr checks."""
|
|
5
|
+
SEARCH: str
|
|
6
|
+
SAVE_INTERACTION: str
|
|
7
|
+
FORMAT_HITS: str
|
|
8
|
+
|
|
9
|
+
class MemoryDefaults:
|
|
10
|
+
"""Default values for memory configuration parameters."""
|
|
11
|
+
MAX_ITEMS: int
|
|
12
|
+
RETRIEVAL_LIMIT: int
|
|
13
|
+
MAX_CHARS: int
|
|
14
|
+
LOG_PREVIEW_LENGTH: int
|
|
15
|
+
SMALL_PREVIEW_LENGTH: int
|
|
16
|
+
AGENT_ID_PREFIX: str
|
|
17
|
+
MEMORY_TAG_OPEN: str
|
|
18
|
+
MEMORY_TAG_CLOSE: str
|
|
19
|
+
DEFAULT_USER_ID: str
|
|
20
|
+
DATE_STRING_LENGTH: int
|
|
21
|
+
|
|
22
|
+
class MemoryBackends:
|
|
23
|
+
"""Supported memory backend identifiers."""
|
|
24
|
+
MEM0: str
|
|
25
|
+
SUPPORTED: Incomplete
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from aip_agents.memory.base import BaseMemory as BaseMemory
|
|
3
|
+
from aip_agents.utils.logger import get_logger as get_logger
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
logger: Incomplete
|
|
7
|
+
BACKENDS: Incomplete
|
|
8
|
+
|
|
9
|
+
class MemoryFactory:
|
|
10
|
+
"""Factory to build concrete memory adapters by backend name."""
|
|
11
|
+
@staticmethod
|
|
12
|
+
def create(backend: str, **kwargs: Any) -> BaseMemory:
|
|
13
|
+
'''Create a memory adapter instance.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
backend: Backend identifier (e.g., "mem0").
|
|
17
|
+
**kwargs: Keyword args passed to adapter constructor (e.g., limit, max_chars, namespace).
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
BaseMemory: A constructed memory adapter instance.
|
|
21
|
+
|
|
22
|
+
Raises:
|
|
23
|
+
ValueError: If backend is unknown or adapter can\'t be constructed.
|
|
24
|
+
'''
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from aip_agents.memory.base import BaseMemory as BaseMemory, ChatMessage as ChatMessage
|
|
2
|
+
|
|
3
|
+
class SimpleMemory(BaseMemory):
|
|
4
|
+
"""A simple memory implementation that stores messages in a list."""
|
|
5
|
+
messages: list[ChatMessage]
|
|
6
|
+
def __init__(self) -> None:
|
|
7
|
+
"""Initialize the SimpleMemory instance with an empty message list."""
|
|
8
|
+
def add_message(self, message_or_role, content=None) -> None:
|
|
9
|
+
'''Add a message to memory.
|
|
10
|
+
|
|
11
|
+
Supports two calling patterns for backward compatibility:
|
|
12
|
+
1. add_message(ChatMessage) - Adds a ChatMessage object directly
|
|
13
|
+
2. add_message(role, content) - Creates and adds a ChatMessage with the given role and content
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
message_or_role: Either a ChatMessage object or a string role (e.g., "user", "assistant").
|
|
17
|
+
content: Optional content string when using the role+content pattern.
|
|
18
|
+
Required when message_or_role is a string role.
|
|
19
|
+
'''
|
|
20
|
+
def get_messages(self) -> list[ChatMessage]:
|
|
21
|
+
"""Get all messages from memory."""
|
|
22
|
+
def clear(self) -> None:
|
|
23
|
+
"""Clear all messages from memory."""
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
from aip_agents.middleware.base import AgentMiddleware as AgentMiddleware, ModelRequest as ModelRequest
|
|
2
|
+
from aip_agents.middleware.manager import MiddlewareManager as MiddlewareManager
|
|
3
|
+
from aip_agents.middleware.todolist import TodoListMiddleware as TodoListMiddleware, TodoStatus as TodoStatus
|
|
4
|
+
|
|
5
|
+
__all__ = ['AgentMiddleware', 'ModelRequest', 'MiddlewareManager', 'TodoListMiddleware', 'TodoStatus']
|