glaip-sdk 0.6.5b5__py3-none-any.whl → 0.6.5b9__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.
@@ -0,0 +1,188 @@
1
+ """A2A event stream processing utilities.
2
+
3
+ This module provides helpers for processing the A2AEvent stream emitted by
4
+ agent execution backends (e.g., `arun_a2a_stream()`).
5
+
6
+ The MVP implementation focuses on extracting final response text;
7
+ full A2AConnector-equivalent normalization is deferred to follow-up PRs.
8
+
9
+ Authors:
10
+ Christian Trisno Sen Long Chen (christian.t.s.l.chen@gdplabs.id)
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ from dataclasses import dataclass
16
+ from typing import Any
17
+
18
+ from gllm_core.utils import LoggerManager
19
+
20
+ logger = LoggerManager().get_logger(__name__)
21
+
22
+ # A2A event type constants (matching aip_agents.schema.a2a.A2AStreamEventType)
23
+ EVENT_TYPE_FINAL_RESPONSE = "final_response"
24
+ EVENT_TYPE_STATUS_UPDATE = "status_update"
25
+ EVENT_TYPE_TOOL_CALL = "tool_call"
26
+ EVENT_TYPE_TOOL_RESULT = "tool_result"
27
+ EVENT_TYPE_ERROR = "error"
28
+
29
+
30
+ @dataclass(frozen=True, slots=True)
31
+ class A2AEventStreamProcessor:
32
+ """Processor for `arun_a2a_stream()` event dictionaries.
33
+
34
+ The SDK uses lightweight dictionaries to represent A2A stream events.
35
+ This helper centralizes event-type normalization and MVP final-text extraction.
36
+
37
+ Example:
38
+ >>> processor = A2AEventStreamProcessor()
39
+ >>> events = [{"event_type": "final_response", "content": "Hello!", "is_final": True}]
40
+ >>> result = processor.extract_final_response(events)
41
+ >>> print(result)
42
+ Hello!
43
+ """
44
+
45
+ def extract_final_response(self, events: list[dict[str, Any]]) -> str:
46
+ """Extract the final response text from a list of A2AEvents.
47
+
48
+ Scans the event list for the final_response event and returns its content.
49
+ If no final_response is found, raises a RuntimeError.
50
+
51
+ Args:
52
+ events: List of A2AEvent dictionaries from arun_a2a_stream().
53
+
54
+ Returns:
55
+ The content string from the final_response event.
56
+
57
+ Raises:
58
+ RuntimeError: If no final_response event is found in the stream.
59
+ """
60
+ for event in reversed(events):
61
+ if self._is_final_response_event(event):
62
+ content = event.get("content", "")
63
+ logger.debug("Extracted final response: %d characters", len(str(content)))
64
+ return str(content)
65
+
66
+ # Fallback: check for events with is_final=True
67
+ for event in reversed(events):
68
+ if event.get("is_final", False):
69
+ content = event.get("content", "")
70
+ if content:
71
+ logger.debug("Extracted final from is_final flag: %d chars", len(str(content)))
72
+ return str(content)
73
+
74
+ raise RuntimeError(
75
+ "No final response received from the agent. The agent execution completed without producing a final answer."
76
+ )
77
+
78
+ def get_event_type(self, event: dict[str, Any]) -> str:
79
+ """Get the normalized event type string from an A2AEvent.
80
+
81
+ Args:
82
+ event: An A2AEvent dictionary.
83
+
84
+ Returns:
85
+ The event type as a lowercase string.
86
+ """
87
+ event_type = event.get("event_type", "unknown")
88
+ if isinstance(event_type, str):
89
+ return event_type.lower()
90
+ # Handle enum types (A2AStreamEventType)
91
+ return getattr(event_type, "value", str(event_type)).lower()
92
+
93
+ def is_tool_event(self, event: dict[str, Any]) -> bool:
94
+ """Check if an event is a tool-related event.
95
+
96
+ Args:
97
+ event: An A2AEvent dictionary.
98
+
99
+ Returns:
100
+ True if this is a tool_call or tool_result event.
101
+ """
102
+ event_type = self.get_event_type(event)
103
+ return event_type in (EVENT_TYPE_TOOL_CALL, EVENT_TYPE_TOOL_RESULT)
104
+
105
+ def is_error_event(self, event: dict[str, Any]) -> bool:
106
+ """Check if an event is an error event.
107
+
108
+ Args:
109
+ event: An A2AEvent dictionary.
110
+
111
+ Returns:
112
+ True if this is an error event.
113
+ """
114
+ return self.get_event_type(event) == EVENT_TYPE_ERROR
115
+
116
+ def _is_final_response_event(self, event: dict[str, Any]) -> bool:
117
+ """Check if an event is a final_response event.
118
+
119
+ Args:
120
+ event: An A2AEvent dictionary.
121
+
122
+ Returns:
123
+ True if this is a final_response event, False otherwise.
124
+ """
125
+ return self.get_event_type(event) == EVENT_TYPE_FINAL_RESPONSE
126
+
127
+
128
+ # Default processor instance for convenience functions
129
+ _DEFAULT_PROCESSOR = A2AEventStreamProcessor()
130
+
131
+
132
+ def extract_final_response(events: list[dict[str, Any]]) -> str:
133
+ """Extract the final response text from a list of A2AEvents.
134
+
135
+ Convenience function that uses the default A2AEventStreamProcessor.
136
+
137
+ Args:
138
+ events: List of A2AEvent dictionaries from arun_a2a_stream().
139
+
140
+ Returns:
141
+ The content string from the final_response event.
142
+
143
+ Raises:
144
+ RuntimeError: If no final_response event is found in the stream.
145
+ """
146
+ return _DEFAULT_PROCESSOR.extract_final_response(events)
147
+
148
+
149
+ def get_event_type(event: dict[str, Any]) -> str:
150
+ """Get the normalized event type string from an A2AEvent.
151
+
152
+ Convenience function that uses the default A2AEventStreamProcessor.
153
+
154
+ Args:
155
+ event: An A2AEvent dictionary.
156
+
157
+ Returns:
158
+ The event type as a lowercase string.
159
+ """
160
+ return _DEFAULT_PROCESSOR.get_event_type(event)
161
+
162
+
163
+ def is_tool_event(event: dict[str, Any]) -> bool:
164
+ """Check if an event is a tool-related event.
165
+
166
+ Convenience function that uses the default A2AEventStreamProcessor.
167
+
168
+ Args:
169
+ event: An A2AEvent dictionary.
170
+
171
+ Returns:
172
+ True if this is a tool_call or tool_result event.
173
+ """
174
+ return _DEFAULT_PROCESSOR.is_tool_event(event)
175
+
176
+
177
+ def is_error_event(event: dict[str, Any]) -> bool:
178
+ """Check if an event is an error event.
179
+
180
+ Convenience function that uses the default A2AEventStreamProcessor.
181
+
182
+ Args:
183
+ event: An A2AEvent dictionary.
184
+
185
+ Returns:
186
+ True if this is an error event.
187
+ """
188
+ return _DEFAULT_PROCESSOR.is_error_event(event)
@@ -304,3 +304,119 @@ def normalize_runtime_config_keys(
304
304
  logger.warning("Unknown field '%s' in runtime_config, ignoring", field)
305
305
 
306
306
  return result
307
+
308
+
309
+ # =============================================================================
310
+ # LOCAL MODE UTILITIES
311
+ # =============================================================================
312
+ # The functions below are for local execution mode where resources are NOT
313
+ # deployed and have no UUIDs. They resolve keys to names (not IDs).
314
+ # =============================================================================
315
+
316
+
317
+ def _get_name_from_class(cls: type) -> str:
318
+ """Extract name from a class, handling Pydantic models.
319
+
320
+ Args:
321
+ cls: The class to extract name from.
322
+
323
+ Returns:
324
+ The resolved name string.
325
+ """
326
+ # Try class-level name attribute first
327
+ class_name = getattr(cls, "name", None)
328
+ if class_name:
329
+ return class_name
330
+
331
+ # For Pydantic models, check model_fields for default value
332
+ model_fields = getattr(cls, "model_fields", None)
333
+ if model_fields and "name" in model_fields:
334
+ field_info = model_fields["name"]
335
+ default = getattr(field_info, "default", None)
336
+ if default and isinstance(default, str):
337
+ return default
338
+
339
+ # Fallback to class __name__
340
+ return cls.__name__
341
+
342
+
343
+ def get_name_from_key(key: object) -> str | None:
344
+ """Resolve config key to name for local mode (no registry needed).
345
+
346
+ Supports instances, classes, and string names. UUID strings are not
347
+ supported in local mode and return None with a warning.
348
+
349
+ Args:
350
+ key: Tool, MCP, or Agent instance/class/string.
351
+
352
+ Returns:
353
+ The resolved name string, or None if UUID (not applicable locally).
354
+
355
+ Raises:
356
+ ValueError: If the key cannot be resolved to a valid name.
357
+ """
358
+ # Instance with name attribute
359
+ if hasattr(key, "name"):
360
+ name = getattr(key, "name", None)
361
+ if name:
362
+ return name
363
+ raise ValueError(f"Unable to resolve config key: {key!r}")
364
+
365
+ # Class type (not instance)
366
+ if isinstance(key, type):
367
+ return _get_name_from_class(key)
368
+
369
+ # String key
370
+ if isinstance(key, str):
371
+ if is_uuid(key):
372
+ logger.warning("UUID '%s' not supported in local mode, skipping", key)
373
+ return None
374
+ return key
375
+
376
+ raise ValueError(f"Unable to resolve config key: {key!r}")
377
+
378
+
379
+ def normalize_local_config_keys(config: dict[object, object]) -> dict[str, object]:
380
+ """Normalize all keys in a config dict to names for local mode.
381
+
382
+ Converts instance/class/string keys to string names without using
383
+ registry. UUID keys are skipped with a warning.
384
+
385
+ Args:
386
+ config: Dict with instance/class/string keys and any values.
387
+
388
+ Returns:
389
+ Dict with string name keys only. UUID keys are omitted.
390
+ """
391
+ if not config:
392
+ return {}
393
+
394
+ result: dict[str, object] = {}
395
+ for key, value in config.items():
396
+ name = get_name_from_key(key)
397
+ if name is not None:
398
+ result[name] = value
399
+ return result
400
+
401
+
402
+ def merge_configs(*configs: dict | None) -> dict:
403
+ """Merge multiple config dicts with priority ordering.
404
+
405
+ Later configs override earlier ones for the same key. None configs
406
+ are skipped gracefully.
407
+
408
+ Args:
409
+ *configs: Config dicts in priority order (lowest priority first).
410
+
411
+ Returns:
412
+ Merged config dict with later values overriding earlier ones.
413
+
414
+ Example:
415
+ >>> merge_configs({"a": 1}, {"a": 2, "b": 3})
416
+ {"a": 2, "b": 3}
417
+ """
418
+ result: dict = {}
419
+ for config in configs:
420
+ if config:
421
+ result.update(config)
422
+ return result
@@ -0,0 +1,33 @@
1
+ """Shared utilities for tool type detection.
2
+
3
+ Authors:
4
+ Christian Trisno Sen Long Chen (christian.t.s.l.chen@gdplabs.id)
5
+ """
6
+
7
+ from typing import Any
8
+
9
+
10
+ def is_langchain_tool(ref: Any) -> bool:
11
+ """Check if ref is a LangChain BaseTool class or instance.
12
+
13
+ Shared by:
14
+ - ToolRegistry._is_custom_tool() (for upload detection)
15
+ - LangChainToolAdapter._is_langchain_tool() (for adaptation)
16
+
17
+ Args:
18
+ ref: Object to check.
19
+
20
+ Returns:
21
+ True if ref is a LangChain BaseTool class or instance.
22
+ """
23
+ try:
24
+ from langchain_core.tools import BaseTool # noqa: PLC0415
25
+
26
+ if isinstance(ref, type) and issubclass(ref, BaseTool):
27
+ return True
28
+ if isinstance(ref, BaseTool):
29
+ return True
30
+ except ImportError:
31
+ pass
32
+
33
+ return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: glaip-sdk
3
- Version: 0.6.5b5
3
+ Version: 0.6.5b9
4
4
  Summary: Python SDK for GL AIP (GDP Labs AI Agent Package) - Simplified CLI Design
5
5
  License: MIT
6
6
  Author: Raymond Christopher
@@ -11,7 +11,11 @@ Classifier: Programming Language :: Python :: 3
11
11
  Classifier: Programming Language :: Python :: 3.11
12
12
  Classifier: Programming Language :: Python :: 3.12
13
13
  Provides-Extra: dev
14
- Requires-Dist: aip-agents-binary (>=0.5.0)
14
+ Provides-Extra: memory
15
+ Provides-Extra: privacy
16
+ Requires-Dist: aip-agents-binary (==0.5.0b2)
17
+ Requires-Dist: aip-agents[memory] (==0.5.0b2) ; (python_version >= "3.11" and python_version < "3.13") and (extra == "memory")
18
+ Requires-Dist: aip-agents[privacy] (==0.5.0b2) ; (python_version >= "3.11" and python_version < "3.13") and (extra == "privacy")
15
19
  Requires-Dist: click (>=8.2.0,<8.3.0)
16
20
  Requires-Dist: gllm-core-binary (>=0.1.0)
17
21
  Requires-Dist: gllm-tools-binary (>=0.1.3)
@@ -1,7 +1,7 @@
1
1
  glaip_sdk/__init__.py,sha256=0PAFfodqAEdggIiV1Es_JryDokZrhYLFFIXosqdguJU,420
2
2
  glaip_sdk/_version.py,sha256=5CHGCxx_36fgmMWuEx6jJ2CzzM-i9eBFyQWFwBi23XE,2259
3
3
  glaip_sdk/agents/__init__.py,sha256=VfYov56edbWuySXFEbWJ_jLXgwnFzPk1KB-9-mfsUCc,776
4
- glaip_sdk/agents/base.py,sha256=OXoosHYh_J3ZCDJXNYNS78vaMbSOC5F4bk1DE31XcMc,37874
4
+ glaip_sdk/agents/base.py,sha256=xCu4vZ2EOXbpsY38Cbebdqz-7ZNmZK9_wo8DxyZh7eA,39577
5
5
  glaip_sdk/branding.py,sha256=tLqYCIHMkUf8p2smpuAGNptwaKUN38G4mlh0A0DOl_w,7823
6
6
  glaip_sdk/cli/__init__.py,sha256=xCCfuF1Yc7mpCDcfhHZTX0vizvtrDSLeT8MJ3V7m5A0,156
7
7
  glaip_sdk/cli/account_store.py,sha256=TK4iTV93Q1uD9mCY_2ZMT6EazHKU2jX0qhgWfEM4V-4,18459
@@ -87,11 +87,24 @@ glaip_sdk/registry/__init__.py,sha256=mjvElYE-wwmbriGe-c6qy4on0ccEuWxW_EWWrSbptC
87
87
  glaip_sdk/registry/agent.py,sha256=F0axW4BIUODqnttIOzxnoS5AqQkLZ1i48FTeZNnYkhA,5203
88
88
  glaip_sdk/registry/base.py,sha256=0x2ZBhiERGUcf9mQeWlksSYs5TxDG6FxBYQToYZa5D4,4143
89
89
  glaip_sdk/registry/mcp.py,sha256=kNJmiijIbZL9Btx5o2tFtbaT-WG6O4Xf_nl3wz356Ow,7978
90
- glaip_sdk/registry/tool.py,sha256=Y3mubiT84TOGByxOab1gF5ROBzcak_6o__JEGiv7uyM,7871
90
+ glaip_sdk/registry/tool.py,sha256=Aq6eryE9hOF9XFnjaBwfnrQgii5uyMdMkLaqm9D9BEk,7765
91
91
  glaip_sdk/rich_components.py,sha256=44Z0V1ZQleVh9gUDGwRR5mriiYFnVGOhm7fFxZYbP8c,4052
92
+ glaip_sdk/runner/__init__.py,sha256=8RrngoGfpF8x9X27RPdX4gJjch75ZvhtVt_6UV0ULLQ,1615
93
+ glaip_sdk/runner/base.py,sha256=KIjcSAyDCP9_mn2H4rXR5gu1FZlwD9pe0gkTBmr6Yi4,2663
94
+ glaip_sdk/runner/deps.py,sha256=3ZDWyvWu4LFJOGHd18tv3VzVo8NY5gb1VeZIelMknyI,3934
95
+ glaip_sdk/runner/langgraph.py,sha256=OPuD44EERJgrlQoM8iGEgGV5pA7e-WeCPHMSe4znYPs,21840
96
+ glaip_sdk/runner/mcp_adapter/__init__.py,sha256=Rdttfg3N6kg3-DaTCKqaGXKByZyBt0Mwf6FV8s_5kI8,462
97
+ glaip_sdk/runner/mcp_adapter/base_mcp_adapter.py,sha256=ic56fKgb3zgVZZQm3ClWUZi7pE1t4EVq8mOg6AM6hdA,1374
98
+ glaip_sdk/runner/mcp_adapter/langchain_mcp_adapter.py,sha256=88moaeTDW7KPxu6qh8mK4pr6oqpOLKLgXX66gFB-5J0,5715
99
+ glaip_sdk/runner/mcp_adapter/mcp_config_builder.py,sha256=fQcRaueDuyUzXUSVn9N8QxfaYNIteEO_R_uibx_0Icw,3440
100
+ glaip_sdk/runner/tool_adapter/__init__.py,sha256=scv8sSPxSWjlSNEace03R230YbmWgphLgqINKvDjWmM,480
101
+ glaip_sdk/runner/tool_adapter/base_tool_adapter.py,sha256=nL--eicV0St5_0PZZSEhRurHDZHNwhGN2cKOUh0C5IY,1400
102
+ glaip_sdk/runner/tool_adapter/langchain_tool_adapter.py,sha256=tmRYyPhih0a4_8c7Cg7ariYP2AEtHW69TRxqukwa2Ko,5438
92
103
  glaip_sdk/tools/__init__.py,sha256=rhGzEqQFCzeMrxmikBuNrMz4PyYczwic28boDKVmoHs,585
93
104
  glaip_sdk/tools/base.py,sha256=bvumLJ-DiQTmuYKgq2yCnlwrTZ9nYXpOwWU0e1vWR5g,15185
94
105
  glaip_sdk/utils/__init__.py,sha256=ntohV7cxlY2Yksi2nFuFm_Mg2XVJbBbSJVRej7Mi9YE,2770
106
+ glaip_sdk/utils/a2a/__init__.py,sha256=_X8AvDOsHeppo5n7rP5TeisVxlAdkZDTFReBk_9lmxo,876
107
+ glaip_sdk/utils/a2a/event_processor.py,sha256=9Mjvvd4_4VDYeOkAI7_vF7N7_Dn0Kn23ramKyK32b3c,5993
95
108
  glaip_sdk/utils/agent_config.py,sha256=RhcHsSOVwOaSC2ggnPuHn36Aa0keGJhs8KGb2InvzRk,7262
96
109
  glaip_sdk/utils/bundler.py,sha256=fQWAv0e5qNjF1Lah-FGoA9W5Q59YaHbQfX_4ZB84YRw,9120
97
110
  glaip_sdk/utils/client.py,sha256=otPUOIDvLCCsvFBNR8YMZFtRrORggmvvlFjl3YeeTqQ,3121
@@ -135,11 +148,12 @@ glaip_sdk/utils/rendering/viewer/__init__.py,sha256=XrxmE2cMAozqrzo1jtDFm8HqNtvD
135
148
  glaip_sdk/utils/rendering/viewer/presenter.py,sha256=mlLMTjnyeyPVtsyrAbz1BJu9lFGQSlS-voZ-_Cuugv0,5725
136
149
  glaip_sdk/utils/resource_refs.py,sha256=vF34kyAtFBLnaKnQVrsr2st1JiSxVbIZ4yq0DelJvCI,5966
137
150
  glaip_sdk/utils/run_renderer.py,sha256=d_VMI6LbvHPUUeRmGqh5wK_lHqDEIAcym2iqpbtDad0,1365
138
- glaip_sdk/utils/runtime_config.py,sha256=Y6frWR_PjD3CV2Jl3AqKxhhsJCkrxSuX27jw0-2aX2M,10124
151
+ glaip_sdk/utils/runtime_config.py,sha256=SPvc2qF7qGio745kMwOOtzXY1-pHI3Vi3BJHcHFhwiE,13634
139
152
  glaip_sdk/utils/serialization.py,sha256=z-qpvWLSBrGK3wbUclcA1UIKLXJedTnMSwPdq-FF4lo,13308
140
153
  glaip_sdk/utils/sync.py,sha256=3VKqs1UfNGWSobgRXohBKP7mMMzdUW3SU0bJQ1uxOgw,4872
154
+ glaip_sdk/utils/tool_detection.py,sha256=g410GNug_PhLye8rd9UU-LVFIKq3jHPbmSItEkLxPTc,807
141
155
  glaip_sdk/utils/validation.py,sha256=hB_k3lvHdIFUiSwHStrC0Eqnhx0OG2UvwqASeem0HuQ,6859
142
- glaip_sdk-0.6.5b5.dist-info/METADATA,sha256=MDnV4n4ApUDbCHo-g-bHigYTvXehQWzMxlNQdfYMYJI,7622
143
- glaip_sdk-0.6.5b5.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
144
- glaip_sdk-0.6.5b5.dist-info/entry_points.txt,sha256=EGs8NO8J1fdFMWA3CsF7sKBEvtHb_fujdCoNPhfMouE,47
145
- glaip_sdk-0.6.5b5.dist-info/RECORD,,
156
+ glaip_sdk-0.6.5b9.dist-info/METADATA,sha256=B-iwONbryPtYPCW-0YHWqgSu_9FBuQBhjcFzCiUslYc,7927
157
+ glaip_sdk-0.6.5b9.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
158
+ glaip_sdk-0.6.5b9.dist-info/entry_points.txt,sha256=EGs8NO8J1fdFMWA3CsF7sKBEvtHb_fujdCoNPhfMouE,47
159
+ glaip_sdk-0.6.5b9.dist-info/RECORD,,