glaip-sdk 0.1.0__py3-none-any.whl → 0.6.10__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.
Files changed (156) hide show
  1. glaip_sdk/__init__.py +5 -2
  2. glaip_sdk/_version.py +10 -3
  3. glaip_sdk/agents/__init__.py +27 -0
  4. glaip_sdk/agents/base.py +1191 -0
  5. glaip_sdk/branding.py +15 -6
  6. glaip_sdk/cli/account_store.py +540 -0
  7. glaip_sdk/cli/agent_config.py +2 -6
  8. glaip_sdk/cli/auth.py +265 -45
  9. glaip_sdk/cli/commands/__init__.py +2 -2
  10. glaip_sdk/cli/commands/accounts.py +746 -0
  11. glaip_sdk/cli/commands/agents.py +251 -173
  12. glaip_sdk/cli/commands/common_config.py +101 -0
  13. glaip_sdk/cli/commands/configure.py +735 -143
  14. glaip_sdk/cli/commands/mcps.py +266 -134
  15. glaip_sdk/cli/commands/models.py +13 -9
  16. glaip_sdk/cli/commands/tools.py +67 -88
  17. glaip_sdk/cli/commands/transcripts.py +755 -0
  18. glaip_sdk/cli/commands/update.py +3 -8
  19. glaip_sdk/cli/config.py +49 -7
  20. glaip_sdk/cli/constants.py +38 -0
  21. glaip_sdk/cli/context.py +8 -0
  22. glaip_sdk/cli/core/__init__.py +79 -0
  23. glaip_sdk/cli/core/context.py +124 -0
  24. glaip_sdk/cli/core/output.py +846 -0
  25. glaip_sdk/cli/core/prompting.py +649 -0
  26. glaip_sdk/cli/core/rendering.py +187 -0
  27. glaip_sdk/cli/display.py +45 -32
  28. glaip_sdk/cli/hints.py +57 -0
  29. glaip_sdk/cli/io.py +14 -17
  30. glaip_sdk/cli/main.py +232 -143
  31. glaip_sdk/cli/masking.py +21 -33
  32. glaip_sdk/cli/mcp_validators.py +5 -15
  33. glaip_sdk/cli/pager.py +12 -19
  34. glaip_sdk/cli/parsers/__init__.py +1 -3
  35. glaip_sdk/cli/parsers/json_input.py +11 -22
  36. glaip_sdk/cli/resolution.py +3 -9
  37. glaip_sdk/cli/rich_helpers.py +1 -3
  38. glaip_sdk/cli/slash/__init__.py +0 -9
  39. glaip_sdk/cli/slash/accounts_controller.py +578 -0
  40. glaip_sdk/cli/slash/accounts_shared.py +75 -0
  41. glaip_sdk/cli/slash/agent_session.py +65 -29
  42. glaip_sdk/cli/slash/prompt.py +24 -10
  43. glaip_sdk/cli/slash/remote_runs_controller.py +566 -0
  44. glaip_sdk/cli/slash/session.py +807 -225
  45. glaip_sdk/cli/slash/tui/__init__.py +9 -0
  46. glaip_sdk/cli/slash/tui/accounts.tcss +86 -0
  47. glaip_sdk/cli/slash/tui/accounts_app.py +876 -0
  48. glaip_sdk/cli/slash/tui/background_tasks.py +72 -0
  49. glaip_sdk/cli/slash/tui/loading.py +58 -0
  50. glaip_sdk/cli/slash/tui/remote_runs_app.py +628 -0
  51. glaip_sdk/cli/transcript/__init__.py +12 -52
  52. glaip_sdk/cli/transcript/cache.py +258 -60
  53. glaip_sdk/cli/transcript/capture.py +72 -21
  54. glaip_sdk/cli/transcript/history.py +815 -0
  55. glaip_sdk/cli/transcript/launcher.py +1 -3
  56. glaip_sdk/cli/transcript/viewer.py +79 -499
  57. glaip_sdk/cli/update_notifier.py +177 -24
  58. glaip_sdk/cli/utils.py +242 -1308
  59. glaip_sdk/cli/validators.py +16 -18
  60. glaip_sdk/client/__init__.py +2 -1
  61. glaip_sdk/client/_agent_payloads.py +53 -37
  62. glaip_sdk/client/agent_runs.py +147 -0
  63. glaip_sdk/client/agents.py +320 -92
  64. glaip_sdk/client/base.py +78 -35
  65. glaip_sdk/client/main.py +19 -10
  66. glaip_sdk/client/mcps.py +123 -15
  67. glaip_sdk/client/run_rendering.py +136 -101
  68. glaip_sdk/client/shared.py +21 -0
  69. glaip_sdk/client/tools.py +163 -34
  70. glaip_sdk/client/validators.py +20 -48
  71. glaip_sdk/config/constants.py +11 -0
  72. glaip_sdk/exceptions.py +1 -3
  73. glaip_sdk/mcps/__init__.py +21 -0
  74. glaip_sdk/mcps/base.py +345 -0
  75. glaip_sdk/models/__init__.py +90 -0
  76. glaip_sdk/models/agent.py +47 -0
  77. glaip_sdk/models/agent_runs.py +116 -0
  78. glaip_sdk/models/common.py +42 -0
  79. glaip_sdk/models/mcp.py +33 -0
  80. glaip_sdk/models/tool.py +33 -0
  81. glaip_sdk/payload_schemas/__init__.py +1 -13
  82. glaip_sdk/payload_schemas/agent.py +1 -3
  83. glaip_sdk/registry/__init__.py +55 -0
  84. glaip_sdk/registry/agent.py +164 -0
  85. glaip_sdk/registry/base.py +139 -0
  86. glaip_sdk/registry/mcp.py +253 -0
  87. glaip_sdk/registry/tool.py +232 -0
  88. glaip_sdk/rich_components.py +58 -2
  89. glaip_sdk/runner/__init__.py +59 -0
  90. glaip_sdk/runner/base.py +84 -0
  91. glaip_sdk/runner/deps.py +115 -0
  92. glaip_sdk/runner/langgraph.py +706 -0
  93. glaip_sdk/runner/mcp_adapter/__init__.py +13 -0
  94. glaip_sdk/runner/mcp_adapter/base_mcp_adapter.py +43 -0
  95. glaip_sdk/runner/mcp_adapter/langchain_mcp_adapter.py +257 -0
  96. glaip_sdk/runner/mcp_adapter/mcp_config_builder.py +95 -0
  97. glaip_sdk/runner/tool_adapter/__init__.py +18 -0
  98. glaip_sdk/runner/tool_adapter/base_tool_adapter.py +44 -0
  99. glaip_sdk/runner/tool_adapter/langchain_tool_adapter.py +219 -0
  100. glaip_sdk/tools/__init__.py +22 -0
  101. glaip_sdk/tools/base.py +435 -0
  102. glaip_sdk/utils/__init__.py +58 -12
  103. glaip_sdk/utils/a2a/__init__.py +34 -0
  104. glaip_sdk/utils/a2a/event_processor.py +188 -0
  105. glaip_sdk/utils/agent_config.py +4 -14
  106. glaip_sdk/utils/bundler.py +267 -0
  107. glaip_sdk/utils/client.py +111 -0
  108. glaip_sdk/utils/client_utils.py +46 -28
  109. glaip_sdk/utils/datetime_helpers.py +58 -0
  110. glaip_sdk/utils/discovery.py +78 -0
  111. glaip_sdk/utils/display.py +25 -21
  112. glaip_sdk/utils/export.py +143 -0
  113. glaip_sdk/utils/general.py +1 -36
  114. glaip_sdk/utils/import_export.py +15 -16
  115. glaip_sdk/utils/import_resolver.py +492 -0
  116. glaip_sdk/utils/instructions.py +101 -0
  117. glaip_sdk/utils/rendering/__init__.py +115 -1
  118. glaip_sdk/utils/rendering/formatting.py +7 -35
  119. glaip_sdk/utils/rendering/layout/__init__.py +64 -0
  120. glaip_sdk/utils/rendering/{renderer → layout}/panels.py +10 -3
  121. glaip_sdk/utils/rendering/{renderer → layout}/progress.py +73 -12
  122. glaip_sdk/utils/rendering/layout/summary.py +74 -0
  123. glaip_sdk/utils/rendering/layout/transcript.py +606 -0
  124. glaip_sdk/utils/rendering/models.py +3 -6
  125. glaip_sdk/utils/rendering/renderer/__init__.py +9 -49
  126. glaip_sdk/utils/rendering/renderer/base.py +258 -1577
  127. glaip_sdk/utils/rendering/renderer/config.py +1 -5
  128. glaip_sdk/utils/rendering/renderer/debug.py +30 -34
  129. glaip_sdk/utils/rendering/renderer/factory.py +138 -0
  130. glaip_sdk/utils/rendering/renderer/stream.py +10 -51
  131. glaip_sdk/utils/rendering/renderer/summary_window.py +79 -0
  132. glaip_sdk/utils/rendering/renderer/thinking.py +273 -0
  133. glaip_sdk/utils/rendering/renderer/toggle.py +1 -3
  134. glaip_sdk/utils/rendering/renderer/tool_panels.py +442 -0
  135. glaip_sdk/utils/rendering/renderer/transcript_mode.py +162 -0
  136. glaip_sdk/utils/rendering/state.py +204 -0
  137. glaip_sdk/utils/rendering/step_tree_state.py +1 -3
  138. glaip_sdk/utils/rendering/steps/__init__.py +34 -0
  139. glaip_sdk/utils/rendering/{steps.py → steps/event_processor.py} +76 -517
  140. glaip_sdk/utils/rendering/steps/format.py +176 -0
  141. glaip_sdk/utils/rendering/steps/manager.py +387 -0
  142. glaip_sdk/utils/rendering/timing.py +36 -0
  143. glaip_sdk/utils/rendering/viewer/__init__.py +21 -0
  144. glaip_sdk/utils/rendering/viewer/presenter.py +184 -0
  145. glaip_sdk/utils/resource_refs.py +29 -26
  146. glaip_sdk/utils/runtime_config.py +425 -0
  147. glaip_sdk/utils/serialization.py +32 -46
  148. glaip_sdk/utils/sync.py +142 -0
  149. glaip_sdk/utils/tool_detection.py +33 -0
  150. glaip_sdk/utils/validation.py +20 -28
  151. {glaip_sdk-0.1.0.dist-info → glaip_sdk-0.6.10.dist-info}/METADATA +42 -4
  152. glaip_sdk-0.6.10.dist-info/RECORD +159 -0
  153. {glaip_sdk-0.1.0.dist-info → glaip_sdk-0.6.10.dist-info}/WHEEL +1 -1
  154. glaip_sdk/models.py +0 -259
  155. glaip_sdk-0.1.0.dist-info/RECORD +0 -82
  156. {glaip_sdk-0.1.0.dist-info → glaip_sdk-0.6.10.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,253 @@
1
+ """MCP registry for glaip_sdk.
2
+
3
+ This module provides the MCPRegistry that caches MCPs (Model Context Protocols)
4
+ to avoid redundant API calls when deploying agents with MCPs.
5
+
6
+ Authors:
7
+ Christian Trisno Sen Long Chen (christian.t.s.l.chen@gdplabs.id)
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import logging
13
+ from typing import TYPE_CHECKING, Any
14
+
15
+ from glaip_sdk.registry.base import BaseRegistry
16
+ from glaip_sdk.utils.resource_refs import is_uuid
17
+
18
+ if TYPE_CHECKING:
19
+ from glaip_sdk.mcps import MCP
20
+
21
+ logger = logging.getLogger(__name__)
22
+
23
+
24
+ class MCPRegistry(BaseRegistry["MCP"]):
25
+ """Registry for MCPs (Model Context Protocols).
26
+
27
+ Resolves MCP references to glaip_sdk.models.MCP objects.
28
+ Caches results to avoid redundant API calls.
29
+
30
+ Handles:
31
+ - glaip_sdk.models.MCP → return as-is (uses mcp.id)
32
+ - String names/IDs → lookup on platform, cache, return MCP
33
+
34
+ Attributes:
35
+ _cache: Internal cache mapping names to MCP objects.
36
+
37
+ Example:
38
+ >>> registry = get_mcp_registry()
39
+ >>> mcp = registry.resolve("arxiv-mcp")
40
+ >>> print(mcp.id)
41
+ """
42
+
43
+ def _extract_name(self, ref: Any) -> str:
44
+ """Extract MCP name from a reference.
45
+
46
+ Args:
47
+ ref: An MCP object, dict, or string name.
48
+
49
+ Returns:
50
+ The extracted MCP name.
51
+
52
+ Raises:
53
+ ValueError: If name cannot be extracted from the reference.
54
+ """
55
+ # String name
56
+ if isinstance(ref, str):
57
+ return ref
58
+
59
+ # Dict from API response - extract name or id
60
+ if isinstance(ref, dict):
61
+ return ref.get("name") or ref.get("id") or ""
62
+
63
+ # Already resolved MCP (glaip_sdk.models.MCP)
64
+ if hasattr(ref, "id") and hasattr(ref, "name") and not isinstance(ref, type):
65
+ return ref.name or ref.id
66
+
67
+ raise ValueError(f"Cannot extract name from: {ref}")
68
+
69
+ def _resolve_and_cache(self, ref: Any, name: str) -> MCP:
70
+ """Resolve MCP reference - find by name/ID or create if needed.
71
+
72
+ Args:
73
+ ref: The MCP reference to resolve.
74
+ name: The extracted MCP name.
75
+
76
+ Returns:
77
+ The resolved glaip_sdk.models.MCP object.
78
+
79
+ Raises:
80
+ ValueError: If the MCP cannot be resolved.
81
+ """
82
+ # MCP object (check if already has ID)
83
+ if hasattr(ref, "id") and hasattr(ref, "name") and not isinstance(ref, type):
84
+ if ref.id is not None:
85
+ # Already resolved MCP with ID - just cache and return
86
+ logger.debug("Caching already resolved MCP: %s", name)
87
+ self._cache[name] = ref
88
+ return ref
89
+
90
+ # MCP without ID - need to look up or create
91
+ return self._lookup_or_create_mcp(ref, name)
92
+
93
+ # Dict from API response - use ID directly if available
94
+ if isinstance(ref, dict):
95
+ mcp_id = ref.get("id")
96
+ if mcp_id:
97
+ from glaip_sdk.mcps.base import MCP # noqa: PLC0415
98
+
99
+ mcp = MCP(id=mcp_id, name=ref.get("name", ""))
100
+ self._cache[name] = mcp
101
+ return mcp
102
+ raise ValueError(f"MCP dict missing 'id': {ref}")
103
+
104
+ # String name - look up on platform
105
+ if isinstance(ref, str):
106
+ return self._lookup_mcp_by_name(name)
107
+
108
+ raise ValueError(f"Could not resolve MCP reference: {ref}")
109
+
110
+ def _lookup_or_create_mcp(self, ref: Any, name: str) -> MCP:
111
+ """Look up or create an MCP from a reference.
112
+
113
+ Args:
114
+ ref: The MCP reference with config details.
115
+ name: The extracted MCP name.
116
+
117
+ Returns:
118
+ The resolved or created glaip_sdk.models.MCP object.
119
+ """
120
+ # Check if this MCP is lookup-only (e.g., from MCP.from_native)
121
+ if getattr(ref, "_lookup_only", False):
122
+ return self._lookup_native_mcp(name)
123
+
124
+ return self._upsert_mcp_from_ref(ref, name)
125
+
126
+ def _lookup_native_mcp(self, name: str) -> MCP:
127
+ """Look up a native MCP that must exist on the platform.
128
+
129
+ Used for MCP.from_native() references that should not be created.
130
+
131
+ Args:
132
+ name: The MCP name to look up.
133
+
134
+ Returns:
135
+ The found MCP.
136
+
137
+ Raises:
138
+ ValueError: If MCP not found or multiple found.
139
+ """
140
+ from glaip_sdk.utils.client import get_client # noqa: PLC0415
141
+
142
+ client = get_client()
143
+ logger.info("Looking up native MCP: %s", name)
144
+
145
+ results = client.find_mcps(name)
146
+ exact_matches = [mcp for mcp in results if getattr(mcp, "name", None) == name]
147
+ if len(exact_matches) == 1:
148
+ mcp = exact_matches[0]
149
+ self._cache[name] = mcp
150
+ return mcp
151
+ if len(exact_matches) > 1:
152
+ raise ValueError(f"Multiple MCPs found with name '{name}'")
153
+ raise ValueError(f"MCP not found on platform: {name}")
154
+
155
+ def _upsert_mcp_from_ref(self, ref: Any, name: str) -> MCP:
156
+ """Create or update an MCP from a reference with config.
157
+
158
+ Args:
159
+ ref: The MCP reference with config details.
160
+ name: The extracted MCP name.
161
+
162
+ Returns:
163
+ The created or updated MCP.
164
+ """
165
+ from glaip_sdk.utils.client import get_client # noqa: PLC0415
166
+
167
+ client = get_client()
168
+ logger.info("Upserting MCP: %s", name)
169
+
170
+ mcp = client.mcps.upsert_mcp(
171
+ name,
172
+ description=getattr(ref, "description", None),
173
+ config=getattr(ref, "config", None),
174
+ transport=getattr(ref, "transport", None),
175
+ metadata=getattr(ref, "metadata", None),
176
+ authentication=getattr(ref, "authentication", None),
177
+ )
178
+ self._cache[name] = mcp
179
+ return mcp
180
+
181
+ def _lookup_mcp_by_name(self, name: str) -> MCP:
182
+ """Look up MCP by name or ID on the platform.
183
+
184
+ Args:
185
+ name: The MCP name or ID to look up.
186
+
187
+ Returns:
188
+ The resolved glaip_sdk.models.MCP object.
189
+
190
+ Raises:
191
+ ValueError: If the MCP cannot be found.
192
+ """
193
+ # Lazy imports to avoid circular dependency
194
+ from glaip_sdk.utils.client import get_client # noqa: PLC0415
195
+
196
+ client = get_client()
197
+ logger.info("Looking up MCP by name: %s", name)
198
+
199
+ # Check if it's a valid UUID
200
+ if is_uuid(name):
201
+ mcp = client.get_mcp_by_id(name)
202
+ if mcp:
203
+ self._cache[name] = mcp
204
+ return mcp
205
+ else:
206
+ results = client.find_mcps(name)
207
+ exact_matches = [mcp for mcp in results if getattr(mcp, "name", None) == name]
208
+ if len(exact_matches) == 1:
209
+ mcp = exact_matches[0]
210
+ self._cache[name] = mcp
211
+ return mcp
212
+ if len(exact_matches) > 1:
213
+ raise ValueError(f"Multiple MCPs found with name '{name}'")
214
+
215
+ raise ValueError(f"MCP not found on platform: {name}")
216
+
217
+
218
+ class _MCPRegistrySingleton:
219
+ """Singleton holder for MCPRegistry to avoid global statement."""
220
+
221
+ _instance: MCPRegistry | None = None
222
+
223
+ @classmethod
224
+ def get_instance(cls) -> MCPRegistry:
225
+ """Get or create the singleton instance.
226
+
227
+ Returns:
228
+ The global MCPRegistry instance.
229
+ """
230
+ if cls._instance is None:
231
+ cls._instance = MCPRegistry()
232
+ return cls._instance
233
+
234
+ @classmethod
235
+ def reset(cls) -> None:
236
+ """Reset the singleton instance (for testing)."""
237
+ cls._instance = None
238
+
239
+
240
+ def get_mcp_registry() -> MCPRegistry:
241
+ """Get the singleton MCPRegistry instance.
242
+
243
+ Returns a global MCPRegistry that caches MCPs across the session.
244
+
245
+ Returns:
246
+ The global MCPRegistry instance.
247
+
248
+ Example:
249
+ >>> from glaip_sdk.registry import get_mcp_registry
250
+ >>> registry = get_mcp_registry()
251
+ >>> mcp = registry.resolve("arxiv-mcp")
252
+ """
253
+ return _MCPRegistrySingleton.get_instance()
@@ -0,0 +1,232 @@
1
+ """Tool registry for glaip_sdk.
2
+
3
+ This module provides the ToolRegistry that caches deployed tools
4
+ to avoid redundant API calls when deploying agents with tools.
5
+
6
+ Authors:
7
+ Christian Trisno Sen Long Chen (christian.t.s.l.chen@gdplabs.id)
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import logging
13
+ from typing import TYPE_CHECKING, Any
14
+
15
+ from glaip_sdk.registry.base import BaseRegistry
16
+
17
+ if TYPE_CHECKING:
18
+ from glaip_sdk.tools import Tool
19
+
20
+ logger = logging.getLogger(__name__)
21
+
22
+
23
+ class ToolRegistry(BaseRegistry["Tool"]):
24
+ """Registry for tools.
25
+
26
+ Resolves tool references to glaip_sdk.models.Tool objects.
27
+ Caches results to avoid redundant API calls and duplicate uploads.
28
+
29
+ Handles:
30
+ - Tool classes (LangChain BaseTool subclasses) → upload, cache, return Tool
31
+ - glaip_sdk.models.Tool → return as-is (uses tool.id)
32
+ - String names → lookup on platform, cache, return Tool
33
+
34
+ Attributes:
35
+ _cache: Internal cache mapping names to Tool objects.
36
+
37
+ Example:
38
+ >>> registry = get_tool_registry()
39
+ >>> tool = registry.resolve(WebSearchTool)
40
+ >>> print(tool.id)
41
+ """
42
+
43
+ def _get_name_from_model_fields(self, ref: type) -> str | None:
44
+ """Extract name from Pydantic model_fields if available."""
45
+ model_fields = getattr(ref, "model_fields", {})
46
+ if "name" not in model_fields:
47
+ return None
48
+ field_info = model_fields["name"]
49
+ default = getattr(field_info, "default", None)
50
+ return default if isinstance(default, str) else None
51
+
52
+ def _get_string_attr(self, obj: Any, attr: str) -> str | None:
53
+ """Get attribute if it's a string, otherwise None."""
54
+ value = getattr(obj, attr, None)
55
+ return value if isinstance(value, str) else None
56
+
57
+ def _extract_name(self, ref: Any) -> str:
58
+ """Extract tool name from a reference.
59
+
60
+ Args:
61
+ ref: A tool class, instance, dict, or string name.
62
+
63
+ Returns:
64
+ The extracted tool name.
65
+
66
+ Raises:
67
+ ValueError: If name cannot be extracted from the reference.
68
+ """
69
+ if isinstance(ref, str):
70
+ return ref
71
+
72
+ # Dict from API response - extract name or id
73
+ if isinstance(ref, dict):
74
+ return ref.get("name") or ref.get("id") or ""
75
+
76
+ # Tool instance (not a class) with name attribute
77
+ if not isinstance(ref, type):
78
+ name = self._get_string_attr(ref, "name")
79
+ if name:
80
+ return name
81
+
82
+ # Tool class - try direct attribute first, then model_fields
83
+ if isinstance(ref, type):
84
+ name = self._get_string_attr(ref, "name") or self._get_name_from_model_fields(ref)
85
+ if name:
86
+ return name
87
+
88
+ raise ValueError(f"Cannot extract name from: {ref}")
89
+
90
+ def _resolve_and_cache(self, ref: Any, name: str) -> Tool:
91
+ """Resolve tool reference - upload if class, find if string/native.
92
+
93
+ Args:
94
+ ref: The tool reference to resolve.
95
+ name: The extracted tool name.
96
+
97
+ Returns:
98
+ The resolved glaip_sdk.models.Tool object.
99
+
100
+ Raises:
101
+ ValueError: If the tool cannot be resolved.
102
+ """
103
+ # Lazy imports to avoid circular dependency
104
+ from glaip_sdk.utils.discovery import find_tool # noqa: PLC0415
105
+ from glaip_sdk.utils.sync import update_or_create_tool # noqa: PLC0415
106
+
107
+ # Already deployed tool (glaip_sdk.models.Tool with ID) - just cache and return
108
+ if hasattr(ref, "id") and hasattr(ref, "name") and not isinstance(ref, type):
109
+ if ref.id is not None:
110
+ logger.debug("Caching already deployed tool: %s", name)
111
+ self._cache[name] = ref
112
+ return ref
113
+
114
+ # Tool without ID (e.g., Tool.from_native()) - look up on platform
115
+ logger.info("Looking up native tool: %s", name)
116
+ tool = find_tool(name)
117
+ if tool:
118
+ self._cache[name] = tool
119
+ return tool
120
+ raise ValueError(f"Native tool not found on platform: {name}")
121
+
122
+ # Custom tool class - upload it
123
+ if self._is_custom_tool(ref):
124
+ logger.info("Uploading custom tool: %s", name)
125
+ tool = update_or_create_tool(ref)
126
+ self._cache[name] = tool
127
+ if tool.id:
128
+ self._cache[tool.id] = tool
129
+ return tool
130
+
131
+ # Dict from API response - use ID directly if available
132
+ if isinstance(ref, dict):
133
+ tool_id = ref.get("id")
134
+ if tool_id:
135
+ from glaip_sdk.tools.base import Tool # noqa: PLC0415
136
+
137
+ tool = Tool(id=tool_id, name=ref.get("name", ""))
138
+ self._cache[name] = tool
139
+ return tool
140
+ raise ValueError(f"Tool dict missing 'id': {ref}")
141
+
142
+ # String name - look up on platform (could be native or existing tool)
143
+ if isinstance(ref, str):
144
+ logger.info("Looking up tool by name: %s", name)
145
+ tool = find_tool(name)
146
+ if tool:
147
+ self._cache[name] = tool
148
+ return tool
149
+ raise ValueError(f"Tool not found on platform: {name}")
150
+
151
+ raise ValueError(f"Could not resolve tool reference: {ref}")
152
+
153
+ def _is_custom_tool(self, ref: Any) -> bool:
154
+ """Check if reference is a custom tool class/instance.
155
+
156
+ Args:
157
+ ref: The reference to check.
158
+
159
+ Returns:
160
+ True if ref is a custom tool that needs uploading.
161
+ """
162
+ try:
163
+ from glaip_sdk.utils.tool_detection import ( # noqa: PLC0415
164
+ is_langchain_tool,
165
+ )
166
+ except ImportError:
167
+ return False
168
+
169
+ return is_langchain_tool(ref)
170
+
171
+ def resolve(self, ref: Any) -> Tool:
172
+ """Resolve a tool reference to a platform Tool object.
173
+
174
+ Overrides base resolve to handle SDK tools differently.
175
+
176
+ Args:
177
+ ref: The tool reference to resolve.
178
+
179
+ Returns:
180
+ The resolved glaip_sdk.models.Tool object.
181
+ """
182
+ # Check if it's a Tool instance (not a class)
183
+ if hasattr(ref, "id") and hasattr(ref, "name") and not isinstance(ref, type):
184
+ # If Tool has an ID, it's already deployed - return as-is
185
+ if ref.id is not None:
186
+ name = self._extract_name(ref)
187
+ if name not in self._cache:
188
+ self._cache[name] = ref
189
+ return ref
190
+
191
+ # Tool without ID (e.g., from Tool.from_native()) - needs platform lookup
192
+ # Fall through to normal resolution
193
+
194
+ return super().resolve(ref)
195
+
196
+
197
+ class _ToolRegistrySingleton:
198
+ """Singleton holder for ToolRegistry to avoid global statement."""
199
+
200
+ _instance: ToolRegistry | None = None
201
+
202
+ @classmethod
203
+ def get_instance(cls) -> ToolRegistry:
204
+ """Get or create the singleton instance.
205
+
206
+ Returns:
207
+ The global ToolRegistry instance.
208
+ """
209
+ if cls._instance is None:
210
+ cls._instance = ToolRegistry()
211
+ return cls._instance
212
+
213
+ @classmethod
214
+ def reset(cls) -> None:
215
+ """Reset the singleton instance (for testing)."""
216
+ cls._instance = None
217
+
218
+
219
+ def get_tool_registry() -> ToolRegistry:
220
+ """Get the singleton ToolRegistry instance.
221
+
222
+ Returns a global ToolRegistry that caches tools across the session.
223
+
224
+ Returns:
225
+ The global ToolRegistry instance.
226
+
227
+ Example:
228
+ >>> from glaip_sdk.registry import get_tool_registry
229
+ >>> registry = get_tool_registry()
230
+ >>> tool = registry.resolve("web_search")
231
+ """
232
+ return _ToolRegistrySingleton.get_instance()
@@ -1,10 +1,15 @@
1
- """Custom Rich components with copy-friendly defaults."""
1
+ """Custom Rich components with copy-friendly defaults.
2
+
3
+ Authors:
4
+ Raymond Christopher (raymond.christopher@gdplabs.id)
5
+ """
2
6
 
3
7
  from __future__ import annotations
4
8
 
5
9
  from rich import box
6
10
  from rich.panel import Panel
7
11
  from rich.table import Table
12
+ from rich.text import Text
8
13
 
9
14
 
10
15
  class AIPPanel(Panel):
@@ -66,4 +71,55 @@ class AIPGrid(Table):
66
71
  )
67
72
 
68
73
 
69
- __all__ = ["AIPPanel", "AIPTable", "AIPGrid"]
74
+ class RemoteRunsTable(AIPTable):
75
+ """Rich Table for displaying remote agent runs with pagination support."""
76
+
77
+ def __init__(self, *args, **kwargs):
78
+ """Initialize RemoteRunsTable with columns for run display.
79
+
80
+ Args:
81
+ *args: Positional arguments passed to AIPTable
82
+ **kwargs: Keyword arguments passed to AIPTable
83
+ """
84
+ kwargs.setdefault("row_styles", ("dim", "none"))
85
+ kwargs.setdefault("show_header", True)
86
+ super().__init__(*args, **kwargs)
87
+ # Add columns for run display
88
+ self.add_column("", width=2, no_wrap=True) # Selection gutter
89
+ self.add_column("Run UUID", style="cyan", width=36, no_wrap=True)
90
+ self.add_column("Type", style="yellow", width=8, no_wrap=True)
91
+ self.add_column("Status", style="magenta", width=12, no_wrap=True)
92
+ self.add_column("Started (UTC)", style="dim", width=20, no_wrap=True)
93
+ self.add_column("Completed (UTC)", style="dim", width=20, no_wrap=True)
94
+ self.add_column("Duration", style="green", width=10, no_wrap=True)
95
+ self.add_column("Input Preview", style="white", width=40, overflow="ellipsis")
96
+
97
+ def add_run_row(
98
+ self,
99
+ run_uuid: str,
100
+ run_type: str,
101
+ status: str,
102
+ started: str,
103
+ completed: str,
104
+ duration: str,
105
+ preview: str,
106
+ *,
107
+ selected: bool = False,
108
+ ) -> None:
109
+ """Append a run row with optional selection styling."""
110
+ gutter = Text("› ", style="bold bright_cyan") if selected else Text(" ")
111
+ row_style = "reverse" if selected else None
112
+ self.add_row(
113
+ gutter,
114
+ run_uuid,
115
+ run_type,
116
+ status,
117
+ started,
118
+ completed,
119
+ duration,
120
+ preview,
121
+ style=row_style,
122
+ )
123
+
124
+
125
+ __all__ = ["AIPPanel", "AIPTable", "AIPGrid", "RemoteRunsTable"]
@@ -0,0 +1,59 @@
1
+ """Local agent execution runners.
2
+
3
+ This module provides runners for executing glaip-sdk agents locally
4
+ without requiring the AIP backend server. The primary runner is
5
+ LangGraphRunner which uses the aip-agents library.
6
+
7
+ To use local execution, install with the [local] extra:
8
+ pip install "glaip-sdk[local]"
9
+
10
+ Authors:
11
+ Christian Trisno Sen Long Chen (christian.t.s.l.chen@gdplabs.id)
12
+
13
+ Example:
14
+ >>> from glaip_sdk.runner import get_default_runner
15
+ >>> from glaip_sdk.agents import Agent
16
+ >>>
17
+ >>> agent = Agent(name="my-agent", instruction="You are helpful.")
18
+ >>> runner = get_default_runner()
19
+ >>> result = runner.run(agent, "Hello!")
20
+ """
21
+
22
+ from glaip_sdk.runner.deps import (
23
+ LOCAL_RUNTIME_AVAILABLE,
24
+ check_local_runtime_available,
25
+ get_local_runtime_missing_message,
26
+ )
27
+ from glaip_sdk.runner.langgraph import LangGraphRunner
28
+
29
+ # Default runner instance
30
+ _default_runner: LangGraphRunner | None = None
31
+
32
+
33
+ def get_default_runner() -> LangGraphRunner:
34
+ """Get the default runner instance for local agent execution.
35
+
36
+ Returns:
37
+ The default LangGraphRunner instance.
38
+
39
+ Raises:
40
+ RuntimeError: If local runtime dependencies are not available.
41
+ """
42
+ global _default_runner
43
+
44
+ if not check_local_runtime_available():
45
+ raise RuntimeError(get_local_runtime_missing_message())
46
+
47
+ if _default_runner is None:
48
+ _default_runner = LangGraphRunner()
49
+
50
+ return _default_runner
51
+
52
+
53
+ __all__ = [
54
+ "LOCAL_RUNTIME_AVAILABLE",
55
+ "LangGraphRunner",
56
+ "check_local_runtime_available",
57
+ "get_default_runner",
58
+ "get_local_runtime_missing_message",
59
+ ]
@@ -0,0 +1,84 @@
1
+ """Abstract base class for agent execution runners.
2
+
3
+ Authors:
4
+ Christian Trisno Sen Long Chen (christian.t.s.l.chen@gdplabs.id)
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from abc import ABC, abstractmethod
10
+ from typing import TYPE_CHECKING, Any
11
+
12
+ if TYPE_CHECKING:
13
+ from glaip_sdk.agents.base import Agent
14
+
15
+
16
+ class BaseRunner(ABC):
17
+ """Abstract base class for agent execution runners.
18
+
19
+ Runners are responsible for executing glaip-sdk Agent instances
20
+ and returning results. Different runner implementations may use
21
+ different execution backends (LangGraph, Google ADK, etc.).
22
+ """
23
+
24
+ @abstractmethod
25
+ def run(
26
+ self,
27
+ agent: Agent,
28
+ message: str,
29
+ verbose: bool = False,
30
+ runtime_config: dict[str, Any] | None = None,
31
+ chat_history: list[dict[str, str]] | None = None,
32
+ **kwargs: Any,
33
+ ) -> str:
34
+ """Execute agent synchronously and return final response text.
35
+
36
+ Args:
37
+ agent: The glaip_sdk Agent to execute.
38
+ message: The user message to send to the agent.
39
+ verbose: If True, emit debug trace output during execution.
40
+ Defaults to False.
41
+ runtime_config: Optional runtime configuration for tools, MCPs, etc.
42
+ Defaults to None.
43
+ chat_history: Optional list of prior conversation messages.
44
+ Defaults to None.
45
+ **kwargs: Additional keyword arguments passed to the backend.
46
+
47
+ Returns:
48
+ The final response text from the agent.
49
+
50
+ Raises:
51
+ RuntimeError: If execution fails.
52
+ """
53
+ ...
54
+
55
+ @abstractmethod
56
+ async def arun(
57
+ self,
58
+ agent: Agent,
59
+ message: str,
60
+ verbose: bool = False,
61
+ runtime_config: dict[str, Any] | None = None,
62
+ chat_history: list[dict[str, str]] | None = None,
63
+ **kwargs: Any,
64
+ ) -> str:
65
+ """Execute agent asynchronously and return final response text.
66
+
67
+ Args:
68
+ agent: The glaip_sdk Agent to execute.
69
+ message: The user message to send to the agent.
70
+ verbose: If True, emit debug trace output during execution.
71
+ Defaults to False.
72
+ runtime_config: Optional runtime configuration for tools, MCPs, etc.
73
+ Defaults to None.
74
+ chat_history: Optional list of prior conversation messages.
75
+ Defaults to None.
76
+ **kwargs: Additional keyword arguments passed to the backend.
77
+
78
+ Returns:
79
+ The final response text from the agent.
80
+
81
+ Raises:
82
+ RuntimeError: If execution fails.
83
+ """
84
+ ...