aip-agents-binary 0.4.8__cp312-cp312-win_amd64.whl → 0.5.4__cp312-cp312-win_amd64.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 +1 -1
- aip_agents/a2a/server/base_executor.pyi +6 -6
- aip_agents/a2a/server/google_adk_executor.pyi +11 -11
- aip_agents/a2a/server/langflow_executor.pyi +43 -0
- aip_agents/a2a/server/langgraph_executor.pyi +10 -11
- aip_agents/a2a/types.pyi +54 -47
- aip_agents/agent/__init__.pyi +3 -1
- aip_agents/agent/base_agent.pyi +24 -8
- aip_agents/agent/base_langgraph_agent.pyi +67 -25
- aip_agents/agent/google_adk_agent.pyi +34 -21
- 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 +199 -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/interface.pyi +5 -5
- 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.pyi +50 -57
- 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 +1 -0
- aip_agents/examples/compare_streaming_client.pyi +48 -0
- 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 +2 -2
- aip_agents/examples/hello_world_a2a_google_adk_client_agent.pyi +2 -2
- aip_agents/examples/hello_world_a2a_google_adk_client_streaming.pyi +2 -2
- aip_agents/examples/hello_world_a2a_google_adk_server.pyi +7 -2
- aip_agents/examples/hello_world_a2a_langchain_client.pyi +1 -1
- aip_agents/examples/hello_world_a2a_langchain_client_agent.pyi +1 -1
- aip_agents/examples/hello_world_a2a_langchain_client_lm_invoker.pyi +1 -1
- aip_agents/examples/hello_world_a2a_langchain_client_streaming.pyi +1 -1
- aip_agents/examples/hello_world_a2a_langchain_reference_client_streaming.pyi +1 -1
- aip_agents/examples/hello_world_a2a_langchain_reference_server.pyi +8 -3
- aip_agents/examples/hello_world_a2a_langchain_server.pyi +7 -2
- aip_agents/examples/hello_world_a2a_langchain_server_lm_invoker.pyi +7 -2
- 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 +1 -1
- aip_agents/examples/hello_world_a2a_langgraph_artifact_client_streaming.pyi +1 -1
- aip_agents/examples/hello_world_a2a_langgraph_artifact_server.pyi +7 -2
- aip_agents/examples/hello_world_a2a_langgraph_client.pyi +2 -2
- aip_agents/examples/hello_world_a2a_langgraph_client_agent.pyi +2 -2
- aip_agents/examples/hello_world_a2a_langgraph_client_agent_lm_invoker.pyi +1 -1
- aip_agents/examples/hello_world_a2a_langgraph_client_streaming.pyi +3 -3
- aip_agents/examples/hello_world_a2a_langgraph_client_streaming_lm_invoker.pyi +1 -1
- aip_agents/examples/hello_world_a2a_langgraph_client_streaming_tool_streaming.pyi +1 -1
- aip_agents/examples/hello_world_a2a_langgraph_server.pyi +7 -2
- aip_agents/examples/hello_world_a2a_langgraph_server_lm_invoker.pyi +7 -2
- aip_agents/examples/hello_world_a2a_langgraph_server_tool_streaming.pyi +7 -2
- aip_agents/examples/hello_world_a2a_mcp_langgraph.pyi +1 -1
- aip_agents/examples/hello_world_a2a_three_level_agent_hierarchy_client.pyi +31 -6
- aip_agents/examples/hello_world_a2a_three_level_agent_hierarchy_server.pyi +33 -5
- aip_agents/examples/hello_world_a2a_with_metadata_langchain_client.pyi +1 -1
- aip_agents/examples/hello_world_a2a_with_metadata_langchain_server_lm_invoker.pyi +7 -2
- aip_agents/examples/hello_world_langchain_mcp_http_interactive.pyi +16 -0
- aip_agents/examples/hello_world_langchain_mcp_multi_server.pyi +18 -0
- aip_agents/examples/hello_world_langflow_agent.pyi +35 -0
- aip_agents/examples/hello_world_model_switch_cli.pyi +18 -3
- aip_agents/examples/hello_world_pii_logger.pyi +1 -1
- aip_agents/examples/hello_world_sentry.pyi +1 -1
- aip_agents/examples/hello_world_step_limits.pyi +17 -0
- aip_agents/examples/hello_world_stock_a2a_server.pyi +7 -2
- aip_agents/examples/hello_world_tool_output_client.pyi +1 -1
- aip_agents/examples/hello_world_tool_output_server.pyi +7 -2
- 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.pyi +5 -0
- aip_agents/examples/todolist_planning_a2a_langgraph_server.pyi +19 -0
- aip_agents/examples/tools/__init__.pyi +3 -1
- aip_agents/examples/tools/adk_weather_tool.pyi +1 -1
- aip_agents/examples/tools/data_visualization_tool.pyi +2 -0
- aip_agents/examples/tools/image_artifact_tool.pyi +2 -0
- aip_agents/examples/tools/langchain_arithmetic_tools.pyi +7 -0
- aip_agents/examples/tools/langchain_currency_exchange_tool.pyi +0 -1
- aip_agents/examples/tools/langchain_graph_artifact_tool.pyi +2 -0
- aip_agents/examples/tools/langchain_weather_tool.pyi +1 -1
- aip_agents/examples/tools/langgraph_streaming_tool.pyi +1 -1
- 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/stock_tools.pyi +18 -3
- aip_agents/mcp/client/__init__.pyi +4 -3
- aip_agents/mcp/client/base_mcp_client.pyi +148 -0
- aip_agents/mcp/client/connection_manager.pyi +48 -0
- aip_agents/mcp/client/google_adk/__init__.pyi +1 -1
- aip_agents/mcp/client/google_adk/client.pyi +50 -13
- aip_agents/mcp/client/langchain/__init__.pyi +1 -1
- aip_agents/mcp/client/langchain/client.pyi +47 -2
- aip_agents/mcp/client/persistent_session.pyi +113 -0
- aip_agents/mcp/client/session_pool.pyi +101 -0
- aip_agents/mcp/client/transports.pyi +123 -0
- aip_agents/mcp/utils/__init__.pyi +0 -0
- aip_agents/mcp/utils/config_validator.pyi +82 -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 +3 -3
- aip_agents/memory/constants.pyi +9 -0
- aip_agents/memory/factory.pyi +1 -1
- aip_agents/memory/guidance.pyi +3 -0
- aip_agents/middleware/__init__.pyi +5 -0
- aip_agents/middleware/base.pyi +71 -0
- aip_agents/middleware/manager.pyi +80 -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 +1 -1
- aip_agents/sentry/sentry.pyi +2 -2
- aip_agents/storage/base.pyi +1 -2
- aip_agents/storage/config.pyi +9 -46
- aip_agents/storage/providers/base.pyi +2 -3
- aip_agents/storage/providers/object_storage.pyi +1 -1
- aip_agents/tools/__init__.pyi +1 -1
- aip_agents/tools/bosa_tools.pyi +2 -2
- aip_agents/tools/constants.pyi +105 -100
- 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/types/__init__.pyi +19 -3
- aip_agents/types/a2a_events.pyi +2 -73
- aip_agents/utils/__init__.pyi +7 -2
- aip_agents/utils/a2a_connector.pyi +14 -4
- aip_agents/utils/artifact_helpers.pyi +26 -2
- 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 +2 -2
- aip_agents/utils/event_handler_registry.pyi +23 -0
- aip_agents/utils/final_response_builder.pyi +34 -0
- aip_agents/utils/formatter_llm_client.pyi +71 -0
- aip_agents/utils/langgraph/converter.pyi +1 -1
- aip_agents/utils/langgraph/tool_managers/a2a_tool_manager.pyi +2 -2
- aip_agents/utils/langgraph/tool_managers/base_tool_manager.pyi +2 -3
- aip_agents/utils/langgraph/tool_managers/delegation_tool_manager.pyi +14 -8
- aip_agents/utils/langgraph/tool_output_management.pyi +15 -2
- 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 +50 -34
- aip_agents/utils/name_preprocessor/base_name_preprocessor.pyi +1 -2
- aip_agents/utils/name_preprocessor/google_name_preprocessor.pyi +1 -1
- aip_agents/utils/name_preprocessor/name_preprocessor.pyi +4 -4
- aip_agents/utils/name_preprocessor/openai_name_preprocessor.pyi +1 -1
- aip_agents/utils/pii/__init__.pyi +5 -0
- aip_agents/utils/pii/pii_handler.pyi +86 -0
- aip_agents/utils/pii/pii_helper.pyi +69 -0
- aip_agents/utils/pii/uuid_deanonymizer_mapping.pyi +62 -0
- aip_agents/utils/reference_helper.pyi +38 -6
- 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 +1 -1
- aip_agents.cp312-win_amd64.pyd +0 -0
- aip_agents.pyi +92 -34
- aip_agents_binary-0.5.4.dist-info/METADATA +649 -0
- aip_agents_binary-0.5.4.dist-info/RECORD +242 -0
- {aip_agents_binary-0.4.8.dist-info → aip_agents_binary-0.5.4.dist-info}/WHEEL +2 -1
- aip_agents_binary-0.5.4.dist-info/top_level.txt +1 -0
- aip_agents/agent/types.pyi +0 -109
- aip_agents/examples/hello_world_a2a_mem0_coordinator_client.pyi +0 -14
- aip_agents/examples/hello_world_a2a_mem0_coordinator_server.pyi +0 -10
- aip_agents/examples/hello_world_a2a_multi_agent_coordinator_client.pyi +0 -19
- aip_agents/examples/hello_world_a2a_multi_agent_coordinator_client_streaming.pyi +0 -9
- aip_agents/examples/hello_world_a2a_multi_agent_coordinator_server.pyi +0 -12
- aip_agents/examples/hello_world_langgraph_bosa.pyi +0 -5
- aip_agents/examples/hello_world_mem0_coordinator.pyi +0 -5
- aip_agents/examples/tools/pr_details_bosa_tool.pyi +0 -26
- aip_agents/memory/mem0_memory.pyi +0 -94
- aip_agents/tools/base.pyi +0 -44
- aip_agents/tools/base_bosa_tools.pyi +0 -12
- aip_agents/tools/bosa_connector.pyi +0 -30
- aip_agents/tools/bosa_tools_interface.pyi +0 -26
- aip_agents/utils/logger_manager.pyi +0 -151
- aip_agents.build/.gitignore +0 -1
- aip_agents_binary-0.4.8.dist-info/METADATA +0 -280
- aip_agents_binary-0.4.8.dist-info/RECORD +0 -166
|
@@ -11,9 +11,33 @@ class ArtifactHandler:
|
|
|
11
11
|
def __init__(self) -> None:
|
|
12
12
|
"""Initialize the ArtifactHandler."""
|
|
13
13
|
def create_file_artifact(self, result: str, artifact_data: bytes | str, artifact_name: str, artifact_description: str = '', mime_type: str | None = None, enable_deduplication: bool = True) -> dict[str, Any]:
|
|
14
|
-
|
|
14
|
+
'''Deprecated. Use create_artifact instead.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
result (str): The message/result to show to the agent.
|
|
18
|
+
artifact_data (bytes | str): The binary data for the artifact.
|
|
19
|
+
artifact_name (str): The name for the artifact file.
|
|
20
|
+
artifact_description (str, optional): Description of the artifact. Defaults to "".
|
|
21
|
+
mime_type (str | None, optional): MIME type of the artifact. If None, will be auto-detected.
|
|
22
|
+
enable_deduplication (bool, optional): Whether to deduplicate by content hash. Defaults to True.
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
dict[str, Any]: Dictionary with \'result\' and \'artifact\' keys.
|
|
26
|
+
'''
|
|
15
27
|
def create_text_artifact(self, result: str, artifact_text: str, artifact_name: str, artifact_description: str = '', mime_type: str | None = None, enable_deduplication: bool = True) -> dict[str, Any]:
|
|
16
|
-
|
|
28
|
+
'''Deprecated. Use create_artifact instead.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
result (str): The message/result to show to the agent.
|
|
32
|
+
artifact_text (str): The text content for the artifact.
|
|
33
|
+
artifact_name (str): The name for the artifact file.
|
|
34
|
+
artifact_description (str, optional): Description of the artifact. Defaults to "".
|
|
35
|
+
mime_type (str | None, optional): MIME type of the artifact. If None, will be auto-detected.
|
|
36
|
+
enable_deduplication (bool, optional): Whether to deduplicate by content hash. Defaults to True.
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
dict[str, Any]: Dictionary with \'result\' and \'artifact\' keys.
|
|
40
|
+
'''
|
|
17
41
|
def create_artifact(self, result: str, data: bytes | str, artifact_name: str, artifact_description: str = '', mime_type: str | None = None, enable_deduplication: bool = True) -> dict[str, Any]:
|
|
18
42
|
"""Create an artifact with automatic text/binary handling.
|
|
19
43
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from enum import StrEnum
|
|
2
|
+
from uuid import UUID
|
|
3
|
+
|
|
4
|
+
__all__ = ['DefaultTimezone', 'DEFAULT_PII_TAG_NAMESPACE']
|
|
5
|
+
|
|
6
|
+
class DefaultTimezone(StrEnum):
|
|
7
|
+
"""Default timezone constants used across the application."""
|
|
8
|
+
JAKARTA: str
|
|
9
|
+
|
|
10
|
+
DEFAULT_PII_TAG_NAMESPACE: UUID
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
from aip_agents.utils.datetime.normalization import format_created_updated_label as format_created_updated_label, is_valid_date_string as is_valid_date_string, next_day_iso as next_day_iso, normalize_timestamp_to_date as normalize_timestamp_to_date
|
|
2
|
+
from aip_agents.utils.datetime.timezone import ensure_utc_datetime as ensure_utc_datetime, get_timezone_aware_now as get_timezone_aware_now
|
|
3
|
+
|
|
4
|
+
__all__ = ['normalize_timestamp_to_date', 'format_created_updated_label', 'is_valid_date_string', 'next_day_iso', 'ensure_utc_datetime', 'get_timezone_aware_now']
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
__all__ = ['normalize_timestamp_to_date', 'format_created_updated_label', 'is_valid_date_string', 'next_day_iso']
|
|
4
|
+
|
|
5
|
+
def normalize_timestamp_to_date(value: Any) -> str | None:
|
|
6
|
+
'''Normalize various timestamp representations into a YYYY-MM-DD string.
|
|
7
|
+
|
|
8
|
+
This function handles multiple input types and formats, converting them to
|
|
9
|
+
a standardized ISO date string. It gracefully handles invalid inputs by
|
|
10
|
+
returning None or the string representation.
|
|
11
|
+
|
|
12
|
+
Args:
|
|
13
|
+
value: The timestamp value to normalize. Can be:
|
|
14
|
+
- None or empty string: Returns None
|
|
15
|
+
- int/float: Unix timestamp (seconds since epoch)
|
|
16
|
+
- str: ISO format, datetime string, or other string representation
|
|
17
|
+
- Other types: Converted to string representation
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
str | None: A YYYY-MM-DD formatted date string, or None if the input
|
|
21
|
+
cannot be parsed as a valid date.
|
|
22
|
+
|
|
23
|
+
Raises:
|
|
24
|
+
ValueError: If the timestamp value is invalid (e.g., negative timestamp).
|
|
25
|
+
|
|
26
|
+
Examples:
|
|
27
|
+
>>> normalize_timestamp_to_date(1640995200) # Unix timestamp
|
|
28
|
+
\'2022-01-01\'
|
|
29
|
+
>>> normalize_timestamp_to_date("2022-01-01T12:00:00")
|
|
30
|
+
\'2022-01-01\'
|
|
31
|
+
>>> normalize_timestamp_to_date("invalid")
|
|
32
|
+
\'invalid\'
|
|
33
|
+
>>> normalize_timestamp_to_date(None)
|
|
34
|
+
None
|
|
35
|
+
'''
|
|
36
|
+
def format_created_updated_label(created_at: Any | None, updated_at: Any | None) -> str | None:
|
|
37
|
+
'''Build a compact label combining created/updated timestamps when available.
|
|
38
|
+
|
|
39
|
+
Creates a human-readable label that shows creation and update timestamps
|
|
40
|
+
in a compact format. If both dates are the same, only shows one date.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
created_at: The creation timestamp (any format supported by normalize_timestamp_to_date).
|
|
44
|
+
updated_at: The update timestamp (any format supported by normalize_timestamp_to_date).
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
str | None: A formatted label string, or None if both inputs are invalid/empty.
|
|
48
|
+
Examples: "2022-01-01", "2022-01-01 (updated 2022-01-02)", "updated 2022-01-01"
|
|
49
|
+
|
|
50
|
+
Examples:
|
|
51
|
+
>>> format_created_updated_label("2022-01-01", "2022-01-02")
|
|
52
|
+
\'2022-01-01 (updated 2022-01-02)\'
|
|
53
|
+
>>> format_created_updated_label("2022-01-01", "2022-01-01")
|
|
54
|
+
\'2022-01-01\'
|
|
55
|
+
>>> format_created_updated_label(None, "2022-01-01")
|
|
56
|
+
\'updated 2022-01-01\'
|
|
57
|
+
>>> format_created_updated_label("2022-01-01", None)
|
|
58
|
+
\'2022-01-01\'
|
|
59
|
+
'''
|
|
60
|
+
def is_valid_date_string(date_str: str, fmt: str = ...) -> bool:
|
|
61
|
+
'''Validate that a date string matches the provided strftime format.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
date_str: The date string to validate. Must be a non-empty string.
|
|
65
|
+
fmt: The strftime format pattern to validate against.
|
|
66
|
+
Defaults to YYYY-MM-DD format.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
bool: True if the date string matches the format, False otherwise.
|
|
70
|
+
|
|
71
|
+
Raises:
|
|
72
|
+
ValueError: If the format string is empty or invalid, or if date_str is not a string.
|
|
73
|
+
|
|
74
|
+
Examples:
|
|
75
|
+
>>> is_valid_date_string("2022-01-01")
|
|
76
|
+
True
|
|
77
|
+
>>> is_valid_date_string("2022-13-01")
|
|
78
|
+
False
|
|
79
|
+
>>> is_valid_date_string("01-01-2022", "%m-%d-%Y")
|
|
80
|
+
True
|
|
81
|
+
>>> is_valid_date_string("", "%Y-%m-%d")
|
|
82
|
+
False
|
|
83
|
+
'''
|
|
84
|
+
def next_day_iso(date_str: str) -> str:
|
|
85
|
+
"""Return the ISO date string for the day after the given ``YYYY-MM-DD`` date.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
date_str: A date string in ``YYYY-MM-DD`` format.
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
str: The next day's date in ``YYYY-MM-DD`` format.
|
|
92
|
+
|
|
93
|
+
Raises:
|
|
94
|
+
ValueError: If ``date_str`` is not a valid ``YYYY-MM-DD`` date string.
|
|
95
|
+
"""
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
|
|
3
|
+
__all__ = ['get_timezone_aware_now', 'ensure_utc_datetime']
|
|
4
|
+
|
|
5
|
+
def get_timezone_aware_now(timezone: str, fallback_timezone: str = 'UTC') -> tuple[datetime, str, bool]:
|
|
6
|
+
'''Return a timezone-aware datetime alongside a timezone label.
|
|
7
|
+
|
|
8
|
+
This function creates a timezone-aware datetime object using the modern
|
|
9
|
+
zoneinfo module (Python 3.9+). It gracefully falls back to UTC if the
|
|
10
|
+
requested timezone is invalid.
|
|
11
|
+
|
|
12
|
+
Args:
|
|
13
|
+
timezone: Desired timezone name in IANA format (e.g., "America/New_York",
|
|
14
|
+
"Europe/London", "Asia/Tokyo"). Must be a non-empty string.
|
|
15
|
+
fallback_timezone: Fallback timezone name to use when the primary
|
|
16
|
+
timezone is invalid. Defaults to "UTC". Must be a non-empty string.
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
tuple[datetime, str, bool]: A 3-tuple containing:
|
|
20
|
+
- now: A timezone-aware datetime object representing the current time
|
|
21
|
+
- timezone_label: A human-readable timezone label (e.g., "EST", "UTC")
|
|
22
|
+
- used_fallback: Boolean indicating whether the fallback timezone was used
|
|
23
|
+
|
|
24
|
+
Raises:
|
|
25
|
+
ValueError: If timezone or fallback_timezone are empty/invalid, or if both
|
|
26
|
+
the requested timezone and fallback timezone are invalid.
|
|
27
|
+
|
|
28
|
+
Examples:
|
|
29
|
+
>>> now, label, fallback = get_timezone_aware_now("America/New_York")
|
|
30
|
+
>>> print(f"Current time: {now}, Timezone: {label}, Used fallback: {fallback}")
|
|
31
|
+
Current time: 2024-01-15 10:30:00-05:00, Timezone: EST, Used fallback: False
|
|
32
|
+
|
|
33
|
+
>>> now, label, fallback = get_timezone_aware_now("Invalid/Timezone")
|
|
34
|
+
>>> print(f"Used fallback: {fallback}, Label: {label}")
|
|
35
|
+
Used fallback: True, Label: UTC
|
|
36
|
+
'''
|
|
37
|
+
def ensure_utc_datetime(value: datetime) -> datetime:
|
|
38
|
+
"""Normalize a datetime to UTC (attaching UTC to naive values).
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
value: Datetime to normalize.
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
datetime: Timezone-aware datetime expressed in UTC.
|
|
45
|
+
|
|
46
|
+
Raises:
|
|
47
|
+
TypeError: If ``value`` is not a ``datetime`` instance.
|
|
48
|
+
"""
|
aip_agents/utils/env_loader.pyi
CHANGED
|
@@ -3,8 +3,8 @@ from _typeshed import Incomplete
|
|
|
3
3
|
logger: Incomplete
|
|
4
4
|
|
|
5
5
|
def load_local_env(override: bool = True) -> None:
|
|
6
|
-
"""Load
|
|
6
|
+
"""Load environment variables from a .env file if python-dotenv is available.
|
|
7
7
|
|
|
8
8
|
Args:
|
|
9
|
-
override: Whether to override existing environment variables.
|
|
9
|
+
override (bool, optional): Whether to override existing environment variables. Defaults to True.
|
|
10
10
|
"""
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from aip_agents.schema.a2a import A2AStreamEventType as A2AStreamEventType
|
|
3
|
+
from aip_agents.utils.logger import get_logger as get_logger
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
logger: Incomplete
|
|
7
|
+
|
|
8
|
+
class EventHandlerRegistry:
|
|
9
|
+
"""Registry for tracking known streaming events with pass-through behaviour."""
|
|
10
|
+
def __init__(self) -> None:
|
|
11
|
+
"""Initialize the event handler registry with known event types."""
|
|
12
|
+
def handle(self, event_type: A2AStreamEventType | str | None, payload: dict[str, Any]) -> dict[str, Any]:
|
|
13
|
+
"""Return the payload unchanged while logging unknown events.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
event_type (A2AStreamEventType | str | None): The type of the streaming event.
|
|
17
|
+
payload (dict[str, Any]): The event payload data.
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
dict[str, Any]: The payload unchanged (pass-through).
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
DEFAULT_EVENT_HANDLER_REGISTRY: Incomplete
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
__all__ = ['FinalResponseMetadataOptions', 'assemble_final_response']
|
|
6
|
+
|
|
7
|
+
@dataclass(slots=True)
|
|
8
|
+
class FinalResponseMetadataOptions:
|
|
9
|
+
"""Container for optional metadata fields on final response events."""
|
|
10
|
+
step_id: str | None = ...
|
|
11
|
+
previous_step_ids: list[str] | None = ...
|
|
12
|
+
tool_info: dict[str, Any] | None = ...
|
|
13
|
+
thinking_and_activity_info: dict[str, Any] | None = ...
|
|
14
|
+
completion_reason: str | None = ...
|
|
15
|
+
timeout_seconds: float | None = ...
|
|
16
|
+
message: dict[str, Any] | None = ...
|
|
17
|
+
partial_result: str | None = ...
|
|
18
|
+
metadata_extra: dict[str, Any] | None = ...
|
|
19
|
+
|
|
20
|
+
def assemble_final_response(*, content: str, artifacts: list[dict[str, Any]] | None = None, metadata_options: FinalResponseMetadataOptions | None = None, status: str = 'success', task_state: str = 'completed', extra_fields: dict[str, Any] | None = None, timestamp: datetime | None = None) -> dict[str, Any]:
|
|
21
|
+
'''Create a final response event with optional artifacts and overrides.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
content: Human readable message for the final response.
|
|
25
|
+
artifacts: Optional list of artifact dictionaries to attach.
|
|
26
|
+
metadata_options: Metadata overrides passed through to the underlying builder.
|
|
27
|
+
status: Top-level status string; defaults to ``"success"``.
|
|
28
|
+
task_state: State string describing the task; defaults to ``"completed"``.
|
|
29
|
+
extra_fields: Additional top-level fields to merge onto the event.
|
|
30
|
+
timestamp: Explicit timestamp for the event. Defaults to ``datetime.now(UTC)``.
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
dict[str, Any]: Final response event payload ready for downstream streaming.
|
|
34
|
+
'''
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from aip_agents.utils.logger import get_logger as get_logger
|
|
3
|
+
from collections.abc import Awaitable as Awaitable
|
|
4
|
+
from gllm_inference.lm_invoker.lm_invoker import BaseLMInvoker
|
|
5
|
+
from typing import Any, TypeVar
|
|
6
|
+
|
|
7
|
+
logger: Incomplete
|
|
8
|
+
FORMATTER_ENV_VAR: str
|
|
9
|
+
T = TypeVar('T')
|
|
10
|
+
|
|
11
|
+
class FormatterInvokerUnavailableError(RuntimeError):
|
|
12
|
+
"""Raised when no formatter LLM invoker can be resolved."""
|
|
13
|
+
class FormatterInvocationError(RuntimeError):
|
|
14
|
+
"""Raised when invoking the formatter LLM fails."""
|
|
15
|
+
|
|
16
|
+
class FormatterLLMClient:
|
|
17
|
+
"""Stateful helper that manages formatter invoker resolution and execution."""
|
|
18
|
+
def __init__(self) -> None:
|
|
19
|
+
"""Initialize the formatter LLM client with caching and thread safety."""
|
|
20
|
+
def seed_default(self, default_model_id: str | None) -> None:
|
|
21
|
+
"""Populate ``DEFAULT_MODEL_FORMATTER`` when unset.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
default_model_id: Preferred formatter model id to use as a fallback.
|
|
25
|
+
"""
|
|
26
|
+
def resolve_invoker(self, *, reset_cache: bool = False) -> BaseLMInvoker | None:
|
|
27
|
+
"""Return the cached formatter invoker, optionally refreshing it.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
reset_cache: When True, clear the cached invoker before resolving.
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
BaseLMInvoker | None: Cached invoker if the formatter is configured, otherwise None.
|
|
34
|
+
"""
|
|
35
|
+
async def invoke(self, *args: Any, invoker: BaseLMInvoker | None = None, timeout: float | None = None, **kwargs: Any) -> Any:
|
|
36
|
+
"""Dispatch formatter prompts asynchronously with timeout/error handling.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
*args: Positional arguments forwarded to the invoker.
|
|
40
|
+
invoker: Explicit invoker instance to reuse instead of resolving one.
|
|
41
|
+
timeout: Optional timeout (seconds) enforced with ``asyncio.timeout``.
|
|
42
|
+
**kwargs: Keyword arguments forwarded to the invoker.
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
Any: Result returned by the formatter LLM.
|
|
46
|
+
|
|
47
|
+
Raises:
|
|
48
|
+
FormatterInvokerUnavailableError: If no formatter model is configured.
|
|
49
|
+
FormatterInvocationError: When the invocation fails or exceeds the timeout.
|
|
50
|
+
"""
|
|
51
|
+
def invoke_blocking(self, *args: Any, invoker: BaseLMInvoker | None = None, timeout: float | None = None, **kwargs: Any) -> Any:
|
|
52
|
+
"""Invoke the formatter LLM from synchronous contexts.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
*args: Positional arguments forwarded to ``invoke``.
|
|
56
|
+
invoker: Optional invoker to reuse.
|
|
57
|
+
timeout: Optional timeout (seconds) for the async invocation.
|
|
58
|
+
**kwargs: Keyword arguments forwarded to ``invoke``.
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
Any: Result returned by the formatter LLM.
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
def get_formatter_llm_client() -> FormatterLLMClient:
|
|
65
|
+
"""Return the process-wide formatter LLM client."""
|
|
66
|
+
def seed_formatter_llm_default(default_model_id: str | None) -> None:
|
|
67
|
+
"""Convenience wrapper for seeding the formatter default model.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
default_model_id: Formatter model identifier to seed when missing.
|
|
71
|
+
"""
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
from collections.abc import Sequence
|
|
1
2
|
from gllm_inference.schema import LMOutput, Message, ToolCall as GllmToolCall
|
|
2
3
|
from langchain_core.messages import AIMessage, BaseMessage as BaseMessage
|
|
3
4
|
from langchain_core.messages.tool import ToolCall as LangChainToolCall
|
|
4
|
-
from typing import Sequence
|
|
5
5
|
|
|
6
6
|
def convert_langchain_messages_to_gllm_messages(messages: Sequence[BaseMessage], instruction: str) -> list[Message]:
|
|
7
7
|
"""Convert LangChain messages to gllm-inference Message format.
|
|
@@ -2,8 +2,8 @@ from _typeshed import Incomplete
|
|
|
2
2
|
from a2a.types import AgentCard as AgentCard
|
|
3
3
|
from aip_agents.utils.a2a_connector import A2AConnector as A2AConnector
|
|
4
4
|
from aip_agents.utils.langgraph.tool_managers.base_tool_manager import BaseLangGraphToolManager as BaseLangGraphToolManager
|
|
5
|
-
from aip_agents.utils.
|
|
6
|
-
from langchain_core.tools import BaseTool
|
|
5
|
+
from aip_agents.utils.logger import get_logger as get_logger
|
|
6
|
+
from langchain_core.tools import BaseTool
|
|
7
7
|
|
|
8
8
|
logger: Incomplete
|
|
9
9
|
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import abc
|
|
2
1
|
from _typeshed import Incomplete
|
|
3
2
|
from abc import ABC, abstractmethod
|
|
4
|
-
from aip_agents.utils.
|
|
3
|
+
from aip_agents.utils.logger import get_logger as get_logger
|
|
5
4
|
from langchain_core.tools import BaseTool as BaseTool
|
|
6
5
|
from typing import Any
|
|
7
6
|
|
|
8
7
|
logger: Incomplete
|
|
9
8
|
|
|
10
|
-
class BaseLangGraphToolManager(ABC
|
|
9
|
+
class BaseLangGraphToolManager(ABC):
|
|
11
10
|
"""Base class for managing specialized tools in LangGraph agents.
|
|
12
11
|
|
|
13
12
|
This abstract base class provides a common interface for tool managers
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
from _typeshed import Incomplete
|
|
2
2
|
from aip_agents.agent.base_agent import BaseAgent as BaseAgent
|
|
3
|
+
from aip_agents.schema.step_limit import MaxDelegationDepthExceededError as MaxDelegationDepthExceededError
|
|
3
4
|
from aip_agents.types import A2AEvent as A2AEvent, A2AStreamEventType as A2AStreamEventType
|
|
4
5
|
from aip_agents.utils.artifact_helpers import extract_artifacts_from_agent_response as extract_artifacts_from_agent_response
|
|
5
6
|
from aip_agents.utils.langgraph.tool_managers.base_tool_manager import BaseLangGraphToolManager as BaseLangGraphToolManager
|
|
6
|
-
from aip_agents.utils.
|
|
7
|
-
from aip_agents.utils.metadata_helper import MetadataFieldKeys as MetadataFieldKeys
|
|
7
|
+
from aip_agents.utils.logger import get_logger as get_logger
|
|
8
|
+
from aip_agents.utils.metadata_helper import MetadataFieldKeys as MetadataFieldKeys, get_next_step_number as get_next_step_number
|
|
9
|
+
from aip_agents.utils.pii.pii_helper import anonymize_final_response_content as anonymize_final_response_content, extract_pii_mapping_from_agent_response as extract_pii_mapping_from_agent_response
|
|
8
10
|
from aip_agents.utils.reference_helper import extract_references_from_agent_response as extract_references_from_agent_response
|
|
9
|
-
from aip_agents.utils.
|
|
10
|
-
from
|
|
11
|
-
from langchain_core.tools import BaseTool
|
|
12
|
-
from langgraph.types import StreamWriter as StreamWriter
|
|
11
|
+
from aip_agents.utils.step_limit_manager import StepLimitManager as StepLimitManager
|
|
12
|
+
from aip_agents.utils.token_usage_helper import STEP_USAGE_KEY as STEP_USAGE_KEY, TOTAL_USAGE_KEY as TOTAL_USAGE_KEY, USAGE_METADATA_KEY as USAGE_METADATA_KEY, extract_token_usage_from_agent_response as extract_token_usage_from_agent_response
|
|
13
|
+
from langchain_core.tools import BaseTool
|
|
13
14
|
|
|
14
15
|
logger: Incomplete
|
|
15
16
|
OUTPUT_KEY: str
|
|
@@ -30,8 +31,13 @@ class DelegationToolManager(BaseLangGraphToolManager):
|
|
|
30
31
|
Simplified version following legacy BaseLangChainAgent patterns.
|
|
31
32
|
"""
|
|
32
33
|
registered_agents: list[BaseAgent]
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
parent_agent: Incomplete
|
|
35
|
+
def __init__(self, parent_agent: BaseAgent | None = None) -> None:
|
|
36
|
+
"""Initialize the delegation tool manager.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
parent_agent: The parent agent that creates delegation tools, used for parent step lookup.
|
|
40
|
+
"""
|
|
35
41
|
created_tools: Incomplete
|
|
36
42
|
def register_resources(self, agents: list[BaseAgent]) -> list[BaseTool]:
|
|
37
43
|
"""Register internal agents for delegation and convert them to tools.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from _typeshed import Incomplete
|
|
2
2
|
from aip_agents.storage.providers.base import BaseStorageProvider as BaseStorageProvider, StorageError as StorageError
|
|
3
3
|
from aip_agents.storage.providers.memory import InMemoryStorageProvider as InMemoryStorageProvider
|
|
4
|
-
from aip_agents.utils.
|
|
4
|
+
from aip_agents.utils.logger import get_logger as get_logger
|
|
5
5
|
from dataclasses import dataclass
|
|
6
6
|
from datetime import datetime, timedelta
|
|
7
7
|
from typing import Any
|
|
@@ -91,7 +91,14 @@ class ToolOutput:
|
|
|
91
91
|
def is_metadata_only(self) -> bool:
|
|
92
92
|
"""Check if this instance contains only metadata without data."""
|
|
93
93
|
def is_expired(self, max_age: timedelta) -> bool:
|
|
94
|
-
"""Check if this output has expired based on the given maximum age.
|
|
94
|
+
"""Check if this output has expired based on the given maximum age.
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
max_age (timedelta): The maximum age allowed before expiration.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
bool: True if the output has expired, False otherwise.
|
|
101
|
+
"""
|
|
95
102
|
def get_data_preview(self, max_length: int = 200, storage_provider: BaseStorageProvider | None = None, thread_id: str | None = None) -> str | None:
|
|
96
103
|
"""Get a truncated string representation of the stored data.
|
|
97
104
|
|
|
@@ -109,6 +116,12 @@ class ToolOutput:
|
|
|
109
116
|
Returns a new ToolOutput instance with the same metadata but with
|
|
110
117
|
data field populated. Useful for converting metadata-only instances
|
|
111
118
|
to complete instances.
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
data (Any): The actual output data to populate.
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
ToolOutput: A new instance with data populated.
|
|
112
125
|
"""
|
|
113
126
|
|
|
114
127
|
@dataclass
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from _typeshed import Incomplete
|
|
3
|
+
|
|
4
|
+
LOGGER_NAME: str
|
|
5
|
+
LOG_LEVEL: Incomplete
|
|
6
|
+
|
|
7
|
+
class _GoogleAdkLogFilter(logging.Filter):
|
|
8
|
+
"""Suppress noisy Google ADK model registry logs.
|
|
9
|
+
|
|
10
|
+
Google ADK emits a burst of INFO logs when registering Gemini model patterns.
|
|
11
|
+
They are redundant (class is unchanged) and clutter our startup output, so we
|
|
12
|
+
drop them at the logging infrastructure level instead of touching ADK internals.
|
|
13
|
+
"""
|
|
14
|
+
SUPPRESSED_PREFIX: str
|
|
15
|
+
def filter(self, record: logging.LogRecord) -> bool:
|
|
16
|
+
"""Return False when the log should be discarded.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
record (logging.LogRecord): The log record to filter.
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
bool: True if the log should be processed, False if it should be discarded.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
LOG_FILTERS: Incomplete
|
|
26
|
+
logger_manager: Incomplete
|
|
27
|
+
root_logger: Incomplete
|
|
28
|
+
|
|
29
|
+
def get_logger(name: str = ..., level: int = ...) -> logging.Logger:
|
|
30
|
+
"""Get a logger instance.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
name (str): The name of the logger. Defaults to AIPAgentsLogger.
|
|
34
|
+
level (int): The level of the logger. Defaults to INFO.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
logging.Logger: The logger instance.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
logger: Incomplete
|
|
41
|
+
THIRD_PARTY_LOGGER_NAMES: Incomplete
|
|
42
|
+
|
|
43
|
+
class LoggerManager:
|
|
44
|
+
"""A singleton class to manage logging configuration.
|
|
45
|
+
|
|
46
|
+
This class is deprecated and will be removed in a future version.
|
|
47
|
+
Use get_logger() function directly instead.
|
|
48
|
+
"""
|
|
49
|
+
def __new__(cls):
|
|
50
|
+
"""Initialize the singleton instance."""
|
|
51
|
+
def get_logger(self, name: str = ..., level: int = ...) -> logging.Logger:
|
|
52
|
+
"""Get a logger instance.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
name (str): The name of the logger. Defaults to AIPAgentsLogger.
|
|
56
|
+
level (int): The level of the logger. Defaults to INFO.
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
logging.Logger: The logger instance.
|
|
60
|
+
"""
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
from aip_agents.utils.metadata.activity_metadata_helper import DEFAULT_ACTIVITY_INFO as DEFAULT_ACTIVITY_INFO, _format_tool_or_subagent_name as _format_tool_or_subagent_name, create_tool_activity_info as create_tool_activity_info
|
|
2
|
+
from aip_agents.utils.metadata.schemas import Activity as Activity, ActivityDataType as ActivityDataType, Thinking as Thinking
|
|
3
|
+
from aip_agents.utils.metadata.thinking_metadata_helper import FINAL_THINKING_INFO as FINAL_THINKING_INFO
|
|
4
|
+
|
|
5
|
+
__all__ = ['Activity', 'ActivityDataType', 'Thinking', 'create_tool_activity_info', 'DEFAULT_ACTIVITY_INFO', '_format_tool_or_subagent_name', 'FINAL_THINKING_INFO']
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from aip_agents.schema.hitl import ApprovalDecisionType as ApprovalDecisionType
|
|
3
|
+
from aip_agents.utils.logger import get_logger as get_logger
|
|
4
|
+
from aip_agents.utils.metadata.activity_narrative import ActivityNarrativeBuilder as ActivityNarrativeBuilder, DELEGATE_PREFIX as DELEGATE_PREFIX, HITL_DECISION_MESSAGES as HITL_DECISION_MESSAGES, HITL_PENDING_DESCRIPTION as HITL_PENDING_DESCRIPTION, HITL_PENDING_TITLE as HITL_PENDING_TITLE
|
|
5
|
+
from aip_agents.utils.metadata.schemas.activity_schema import Activity as Activity
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
logger: Incomplete
|
|
9
|
+
DEFAULT_ACTIVITY_MESSAGE: str
|
|
10
|
+
TOOL_EXECUTION_RUNNING_TEMPLATE: str
|
|
11
|
+
TOOL_EXECUTION_COMPLETE_TEMPLATE: str
|
|
12
|
+
SUBAGENT_DELEGATION_TEMPLATE: str
|
|
13
|
+
SUBAGENT_COMPLETE_TEMPLATE: str
|
|
14
|
+
MIXED_EXECUTION_TEMPLATE: str
|
|
15
|
+
DEFAULT_ACTIVITY_INFO: Incomplete
|
|
16
|
+
|
|
17
|
+
def create_tool_activity_info(original_metadata: dict[str, Any] | None) -> dict[str, str]:
|
|
18
|
+
'''Create activity info payload with optional LLM narrative overrides.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
original_metadata: The original metadata dictionary containing tool_info and hitl data.
|
|
22
|
+
|
|
23
|
+
Returns:
|
|
24
|
+
A dict with data_type="activity" and data_value as a JSON string.
|
|
25
|
+
'''
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
from aip_agents.utils.metadata.activity_narrative.builder import ActivityNarrativeBuilder as ActivityNarrativeBuilder, _formatter_llm_client as _formatter_llm_client
|
|
2
|
+
from aip_agents.utils.metadata.activity_narrative.constants import DELEGATE_PREFIX as DELEGATE_PREFIX, HITL_DECISION_MESSAGES as HITL_DECISION_MESSAGES, HITL_PENDING_DESCRIPTION as HITL_PENDING_DESCRIPTION, HITL_PENDING_TITLE as HITL_PENDING_TITLE, OUTPUT_EXCERPT_MAX_CHARS as OUTPUT_EXCERPT_MAX_CHARS, SYSTEM_PROMPT as SYSTEM_PROMPT
|
|
3
|
+
from aip_agents.utils.metadata.activity_narrative.context import ActivityContext as ActivityContext, ActivityPhase as ActivityPhase
|
|
4
|
+
from aip_agents.utils.metadata.activity_narrative.formatters import ArgsFormatter as ArgsFormatter, OutputFormatter as OutputFormatter, SensitiveInfoFilter as SensitiveInfoFilter
|
|
5
|
+
from aip_agents.utils.metadata.activity_narrative.utils import _format_tool_or_subagent_name as _format_tool_or_subagent_name
|
|
6
|
+
|
|
7
|
+
__all__ = ['ActivityNarrativeBuilder', 'ActivityContext', 'ActivityPhase', 'ArgsFormatter', 'OutputFormatter', 'SensitiveInfoFilter', 'DELEGATE_PREFIX', 'HITL_DECISION_MESSAGES', 'HITL_PENDING_DESCRIPTION', 'HITL_PENDING_TITLE', 'OUTPUT_EXCERPT_MAX_CHARS', 'SYSTEM_PROMPT', '_format_tool_or_subagent_name', '_formatter_llm_client']
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from aip_agents.schema.hitl import ApprovalDecisionType as ApprovalDecisionType, HitlMetadata as HitlMetadata
|
|
3
|
+
from aip_agents.utils.formatter_llm_client import FormatterInvocationError as FormatterInvocationError, FormatterInvokerUnavailableError as FormatterInvokerUnavailableError, get_formatter_llm_client as get_formatter_llm_client
|
|
4
|
+
from aip_agents.utils.logger import get_logger as get_logger
|
|
5
|
+
from aip_agents.utils.metadata.activity_narrative.constants import DELEGATE_PREFIX as DELEGATE_PREFIX, HITL_DECISION_MESSAGES as HITL_DECISION_MESSAGES, HITL_PENDING_DESCRIPTION as HITL_PENDING_DESCRIPTION, HITL_PENDING_TITLE as HITL_PENDING_TITLE, OUTPUT_EXCERPT_MAX_CHARS as OUTPUT_EXCERPT_MAX_CHARS, SYSTEM_PROMPT as SYSTEM_PROMPT
|
|
6
|
+
from aip_agents.utils.metadata.activity_narrative.context import ActivityContext as ActivityContext, ActivityPhase as ActivityPhase
|
|
7
|
+
from aip_agents.utils.metadata.activity_narrative.formatters import ArgsFormatter as ArgsFormatter, OutputFormatter as OutputFormatter, SensitiveInfoFilter as SensitiveInfoFilter
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
logger: Incomplete
|
|
11
|
+
|
|
12
|
+
class ActivityNarrativeBuilder:
|
|
13
|
+
"""Generate structured activity payloads via formatter LLM.
|
|
14
|
+
|
|
15
|
+
High-level flow:
|
|
16
|
+
1. Gather raw metadata about a tool/delegate event and normalize it into an ``ActivityContext``.
|
|
17
|
+
2. Sanitize arguments and outputs so no sensitive values reach downstream renderers or the formatter model.
|
|
18
|
+
3. Prompt the shared formatter with phase-specific instructions (e.g., describe intent on start, summarize results on end).
|
|
19
|
+
4. If the formatter responds with usable heading/body text, surface it; otherwise fall back to deterministic templates
|
|
20
|
+
built from the sanitized context.
|
|
21
|
+
|
|
22
|
+
This approach keeps SSE activity cards readable when the formatter is healthy while still providing sensible copy when
|
|
23
|
+
the formatter is unavailable or returns low-quality text.
|
|
24
|
+
"""
|
|
25
|
+
def __init__(self) -> None:
|
|
26
|
+
"""Initialize the activity narrative builder."""
|
|
27
|
+
def build_payload(self, metadata: dict[str, Any] | None) -> dict[str, Any] | None:
|
|
28
|
+
"""Build enriched payload for the provided metadata.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
metadata: The metadata dictionary containing tool_info, hitl, and other context.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
Dictionary payload with a rendered message, or None when not available.
|
|
35
|
+
"""
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from aip_agents.schema.hitl import ApprovalDecisionType
|
|
2
|
+
|
|
3
|
+
__all__ = ['SYSTEM_PROMPT', 'DELEGATE_PREFIX', 'OUTPUT_EXCERPT_MAX_CHARS', 'HITL_PENDING_TITLE', 'HITL_PENDING_DESCRIPTION', 'HITL_DECISION_MESSAGES']
|
|
4
|
+
|
|
5
|
+
SYSTEM_PROMPT: str
|
|
6
|
+
DELEGATE_PREFIX: str
|
|
7
|
+
OUTPUT_EXCERPT_MAX_CHARS: int
|
|
8
|
+
HITL_PENDING_TITLE: str
|
|
9
|
+
HITL_PENDING_DESCRIPTION: str
|
|
10
|
+
HITL_DECISION_MESSAGES: dict[ApprovalDecisionType, tuple[str, str]]
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from aip_agents.schema.hitl import ApprovalDecisionType, HitlMetadata
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from enum import StrEnum
|
|
4
|
+
|
|
5
|
+
__all__ = ['ActivityContext', 'ActivityPhase']
|
|
6
|
+
|
|
7
|
+
class ActivityPhase(StrEnum):
|
|
8
|
+
"""Lifecycle phases for tool, delegate, and HITL events."""
|
|
9
|
+
TOOL_START: str
|
|
10
|
+
TOOL_END: str
|
|
11
|
+
DELEGATE_START: str
|
|
12
|
+
DELEGATE_END: str
|
|
13
|
+
HITL_PENDING: str
|
|
14
|
+
HITL_RESOLVED: str
|
|
15
|
+
JSONScalar = str | int | float | bool | None
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class ActivityContext:
|
|
19
|
+
"""Structured representation of an activity event."""
|
|
20
|
+
phase: ActivityPhase
|
|
21
|
+
agent_name: str | None
|
|
22
|
+
subject_name: str | None
|
|
23
|
+
sanitized_args: dict[str, JSONValue] | None
|
|
24
|
+
sanitized_output: JSONValue | None
|
|
25
|
+
arguments_excerpt: str | None
|
|
26
|
+
output_excerpt: str | None
|
|
27
|
+
error_excerpt: str | None
|
|
28
|
+
step_id: str | None = ...
|
|
29
|
+
is_delegate: bool = ...
|
|
30
|
+
hitl_metadata: HitlMetadata | None = ...
|
|
31
|
+
hitl_decision: ApprovalDecisionType | None = ...
|
|
32
|
+
default_heading: str | None = ...
|