glaip-sdk 0.6.25__py3-none-any.whl → 0.6.26__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.
- glaip_sdk/cli/commands/agents/__init__.py +119 -0
- glaip_sdk/cli/commands/agents/_common.py +561 -0
- glaip_sdk/cli/commands/agents/create.py +151 -0
- glaip_sdk/cli/commands/agents/delete.py +64 -0
- glaip_sdk/cli/commands/agents/get.py +89 -0
- glaip_sdk/cli/commands/agents/list.py +129 -0
- glaip_sdk/cli/commands/agents/run.py +264 -0
- glaip_sdk/cli/commands/agents/sync_langflow.py +72 -0
- glaip_sdk/cli/commands/agents/update.py +112 -0
- glaip_sdk/cli/commands/mcps/__init__.py +98 -0
- glaip_sdk/cli/commands/mcps/_common.py +490 -0
- glaip_sdk/cli/commands/mcps/connect.py +82 -0
- glaip_sdk/cli/commands/mcps/create.py +153 -0
- glaip_sdk/cli/commands/mcps/delete.py +73 -0
- glaip_sdk/cli/commands/mcps/get.py +212 -0
- glaip_sdk/cli/commands/mcps/list.py +69 -0
- glaip_sdk/cli/commands/mcps/tools.py +235 -0
- glaip_sdk/cli/commands/mcps/update.py +146 -0
- glaip_sdk/cli/commands/shared/__init__.py +21 -0
- glaip_sdk/cli/commands/shared/formatters.py +91 -0
- glaip_sdk/cli/commands/tools/__init__.py +69 -0
- glaip_sdk/cli/commands/tools/_common.py +80 -0
- glaip_sdk/cli/commands/tools/create.py +228 -0
- glaip_sdk/cli/commands/tools/delete.py +61 -0
- glaip_sdk/cli/commands/tools/get.py +103 -0
- glaip_sdk/cli/commands/tools/list.py +69 -0
- glaip_sdk/cli/commands/tools/script.py +49 -0
- glaip_sdk/cli/commands/tools/update.py +102 -0
- glaip_sdk/cli/commands/transcripts/__init__.py +90 -0
- glaip_sdk/cli/commands/transcripts/_common.py +9 -0
- glaip_sdk/cli/commands/transcripts/clear.py +5 -0
- glaip_sdk/cli/commands/transcripts/detail.py +5 -0
- glaip_sdk/client/_agent_payloads.py +32 -500
- glaip_sdk/client/agents.py +1 -1
- glaip_sdk/client/main.py +1 -1
- glaip_sdk/client/mcps.py +44 -13
- glaip_sdk/client/payloads/agent/__init__.py +23 -0
- glaip_sdk/client/payloads/agent/requests.py +495 -0
- glaip_sdk/client/payloads/agent/responses.py +43 -0
- glaip_sdk/client/tools.py +38 -3
- glaip_sdk/tools/base.py +41 -10
- glaip_sdk/utils/import_resolver.py +40 -2
- {glaip_sdk-0.6.25.dist-info → glaip_sdk-0.6.26.dist-info}/METADATA +1 -1
- {glaip_sdk-0.6.25.dist-info → glaip_sdk-0.6.26.dist-info}/RECORD +48 -16
- glaip_sdk/cli/commands/agents.py +0 -1502
- glaip_sdk/cli/commands/mcps.py +0 -1355
- glaip_sdk/cli/commands/tools.py +0 -575
- /glaip_sdk/cli/commands/{transcripts.py → transcripts_original.py} +0 -0
- {glaip_sdk-0.6.25.dist-info → glaip_sdk-0.6.26.dist-info}/WHEEL +0 -0
- {glaip_sdk-0.6.25.dist-info → glaip_sdk-0.6.26.dist-info}/entry_points.txt +0 -0
- {glaip_sdk-0.6.25.dist-info → glaip_sdk-0.6.26.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""Transcript CLI commands package.
|
|
2
|
+
|
|
3
|
+
Authors:
|
|
4
|
+
Raymond Christopher (raymond.christopher@gdplabs.id)
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from glaip_sdk.cli.commands.transcripts._common import transcripts_group
|
|
8
|
+
from glaip_sdk.cli.commands.transcripts.clear import transcripts_clear
|
|
9
|
+
from glaip_sdk.cli.commands.transcripts.detail import transcripts_detail
|
|
10
|
+
|
|
11
|
+
# Import helper functions from original file for backward compatibility
|
|
12
|
+
# NOTE: Transcripts migration is deferred per spec (see resource-command-alignment/spec.md).
|
|
13
|
+
# NOTE: Migration is tracked in ../observability/transcript-storage-viewer-services/spec.md (Phase 0).
|
|
14
|
+
# This package currently re-exports from transcripts_original.py until the migration is completed.
|
|
15
|
+
from glaip_sdk.cli.commands.transcripts_original import ( # noqa: E402, type: ignore
|
|
16
|
+
_abbreviate_path,
|
|
17
|
+
_build_table,
|
|
18
|
+
_build_viewer_context,
|
|
19
|
+
_coerce_timestamp_to_float,
|
|
20
|
+
_collect_targets,
|
|
21
|
+
_confirm_deletion,
|
|
22
|
+
_decode_transcript,
|
|
23
|
+
_emit_warnings,
|
|
24
|
+
_format_duration,
|
|
25
|
+
_format_timestamp,
|
|
26
|
+
_format_timestamp_display,
|
|
27
|
+
_handle_clear_result,
|
|
28
|
+
_launch_transcript_viewer,
|
|
29
|
+
_load_transcript_text,
|
|
30
|
+
_maybe_launch_transcript_viewer,
|
|
31
|
+
_parse_event_received_timestamp,
|
|
32
|
+
_parse_transcript_line,
|
|
33
|
+
_print_snapshot,
|
|
34
|
+
_render_deletion_preview,
|
|
35
|
+
_render_detail_view,
|
|
36
|
+
_render_history_overview,
|
|
37
|
+
_render_transcript_display,
|
|
38
|
+
_resolve_transcript_path,
|
|
39
|
+
_row_label,
|
|
40
|
+
_should_exit_for_targets,
|
|
41
|
+
_should_use_transcript_viewer,
|
|
42
|
+
_transcripts_payload,
|
|
43
|
+
_validate_clear_options,
|
|
44
|
+
console,
|
|
45
|
+
sys,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
# Import functions from other modules for test compatibility
|
|
49
|
+
from glaip_sdk.cli.transcript.history import load_history_snapshot # noqa: E402
|
|
50
|
+
from glaip_sdk.cli.transcript.viewer import run_viewer_session # noqa: E402
|
|
51
|
+
from glaip_sdk.utils.rendering.layout.panels import create_final_panel # noqa: E402
|
|
52
|
+
|
|
53
|
+
__all__ = [
|
|
54
|
+
"transcripts_group",
|
|
55
|
+
"transcripts_clear",
|
|
56
|
+
"transcripts_detail",
|
|
57
|
+
"_abbreviate_path",
|
|
58
|
+
"_build_table",
|
|
59
|
+
"_build_viewer_context",
|
|
60
|
+
"_coerce_timestamp_to_float",
|
|
61
|
+
"_collect_targets",
|
|
62
|
+
"_confirm_deletion",
|
|
63
|
+
"_decode_transcript",
|
|
64
|
+
"_emit_warnings",
|
|
65
|
+
"_format_duration",
|
|
66
|
+
"_format_timestamp",
|
|
67
|
+
"_format_timestamp_display",
|
|
68
|
+
"_handle_clear_result",
|
|
69
|
+
"_launch_transcript_viewer",
|
|
70
|
+
"_load_transcript_text",
|
|
71
|
+
"_maybe_launch_transcript_viewer",
|
|
72
|
+
"_parse_event_received_timestamp",
|
|
73
|
+
"_parse_transcript_line",
|
|
74
|
+
"_print_snapshot",
|
|
75
|
+
"_render_deletion_preview",
|
|
76
|
+
"_render_detail_view",
|
|
77
|
+
"_render_history_overview",
|
|
78
|
+
"_render_transcript_display",
|
|
79
|
+
"_resolve_transcript_path",
|
|
80
|
+
"_row_label",
|
|
81
|
+
"_should_exit_for_targets",
|
|
82
|
+
"_should_use_transcript_viewer",
|
|
83
|
+
"_transcripts_payload",
|
|
84
|
+
"_validate_clear_options",
|
|
85
|
+
"console",
|
|
86
|
+
"sys",
|
|
87
|
+
"load_history_snapshot",
|
|
88
|
+
"run_viewer_session",
|
|
89
|
+
"create_final_panel",
|
|
90
|
+
]
|
|
@@ -1,427 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
"""Shared helpers for Agent client payload construction and query handling."""
|
|
1
|
+
"""Backward-compatible shim for agent payloads.
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
This module provides backward compatibility for imports from glaip_sdk.client._agent_payloads.
|
|
4
|
+
New code should import from glaip_sdk.client.payloads.agent package directly.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
from dataclasses import dataclass, field
|
|
9
|
-
from typing import Any
|
|
6
|
+
This file contains code that is duplicated in glaip_sdk.client.payloads.agent.__init__
|
|
7
|
+
for backward compatibility. The duplication is intentional.
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
DEFAULT_AGENT_TYPE,
|
|
15
|
-
DEFAULT_AGENT_VERSION,
|
|
16
|
-
DEFAULT_MODEL,
|
|
17
|
-
)
|
|
18
|
-
from glaip_sdk.payload_schemas.agent import AgentImportOperation, get_import_field_plan
|
|
19
|
-
from glaip_sdk.utils.client_utils import extract_ids
|
|
20
|
-
|
|
21
|
-
_LM_CONFLICT_KEYS = {
|
|
22
|
-
"lm_provider",
|
|
23
|
-
"lm_name",
|
|
24
|
-
"lm_base_url",
|
|
25
|
-
"lm_hyperparameters",
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def _copy_structure(value: Any) -> Any:
|
|
30
|
-
"""Return a defensive copy for mutable payload structures."""
|
|
31
|
-
if isinstance(value, (dict, list, tuple)):
|
|
32
|
-
return deepcopy(value)
|
|
33
|
-
return value
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def _sanitize_agent_config(
|
|
37
|
-
agent_config: Mapping[str, Any] | None,
|
|
38
|
-
) -> dict[str, Any] | None:
|
|
39
|
-
"""Remove legacy LM keys that conflict with modern language model fields."""
|
|
40
|
-
if agent_config is None:
|
|
41
|
-
return None
|
|
42
|
-
|
|
43
|
-
sanitized = deepcopy(agent_config)
|
|
44
|
-
for key in _LM_CONFLICT_KEYS:
|
|
45
|
-
sanitized.pop(key, None)
|
|
46
|
-
return sanitized
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
def _merge_execution_timeout(
|
|
50
|
-
agent_config: dict[str, Any] | None,
|
|
51
|
-
timeout: int | None,
|
|
52
|
-
) -> dict[str, Any] | None:
|
|
53
|
-
"""Merge execution timeout into agent_config if provided."""
|
|
54
|
-
if timeout is None:
|
|
55
|
-
return agent_config
|
|
56
|
-
|
|
57
|
-
merged = agent_config or {}
|
|
58
|
-
merged.setdefault("execution_timeout", timeout)
|
|
59
|
-
return merged
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
def merge_payload_fields(
|
|
63
|
-
payload: MutableMapping[str, Any],
|
|
64
|
-
extra_fields: Mapping[str, Any] | None,
|
|
65
|
-
operation: AgentImportOperation,
|
|
66
|
-
) -> None:
|
|
67
|
-
"""Merge additional fields into payload respecting schema hints."""
|
|
68
|
-
if not extra_fields:
|
|
69
|
-
return
|
|
70
|
-
|
|
71
|
-
for key, value in extra_fields.items():
|
|
72
|
-
plan = get_import_field_plan(key, operation)
|
|
73
|
-
if not plan.copy or value is None:
|
|
74
|
-
continue
|
|
75
|
-
|
|
76
|
-
copied_value = _copy_structure(value)
|
|
77
|
-
if plan.sanitize and isinstance(copied_value, dict):
|
|
78
|
-
copied_value = _sanitize_agent_config(copied_value)
|
|
79
|
-
|
|
80
|
-
payload[key] = copied_value
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
def resolve_language_model_fields(
|
|
84
|
-
*,
|
|
85
|
-
model: str | None,
|
|
86
|
-
language_model_id: str | None,
|
|
87
|
-
provider: str | None,
|
|
88
|
-
model_name: str | None,
|
|
89
|
-
default_provider: str = DEFAULT_AGENT_PROVIDER,
|
|
90
|
-
default_model: str = DEFAULT_MODEL,
|
|
91
|
-
) -> dict[str, Any]:
|
|
92
|
-
"""Resolve mutually exclusive language model specification fields."""
|
|
93
|
-
if language_model_id:
|
|
94
|
-
return {"language_model_id": language_model_id}
|
|
95
|
-
|
|
96
|
-
resolved_model = model_name or model or default_model
|
|
97
|
-
resolved_provider = provider if provider is not None else default_provider
|
|
98
|
-
|
|
99
|
-
result: dict[str, Any] = {}
|
|
100
|
-
if resolved_model is not None:
|
|
101
|
-
result["model_name"] = resolved_model
|
|
102
|
-
if resolved_provider:
|
|
103
|
-
result["provider"] = resolved_provider
|
|
104
|
-
return result
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
def _extract_ids_or_empty(items: Sequence[str | Any] | None) -> list[str]:
|
|
108
|
-
"""Extract IDs, returning an empty list when no IDs are present."""
|
|
109
|
-
if items is None:
|
|
110
|
-
return []
|
|
111
|
-
|
|
112
|
-
try:
|
|
113
|
-
iterable = list(items)
|
|
114
|
-
except TypeError:
|
|
115
|
-
return []
|
|
116
|
-
|
|
117
|
-
extracted = extract_ids(iterable)
|
|
118
|
-
return extracted or []
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
def _extract_existing_ids(source: Any, attribute: str) -> list[str]:
|
|
122
|
-
"""Extract IDs from an attribute on the current agent instance."""
|
|
123
|
-
if source is None:
|
|
124
|
-
return []
|
|
125
|
-
value = getattr(source, attribute, None)
|
|
126
|
-
if not value:
|
|
127
|
-
return []
|
|
128
|
-
return _extract_ids_or_empty(value)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
def _resolve_relation_ids(
|
|
132
|
-
new_items: Sequence[str | Any] | None,
|
|
133
|
-
current_agent: Any,
|
|
134
|
-
attribute: str,
|
|
135
|
-
) -> list[str]:
|
|
136
|
-
"""Resolve relationship IDs favouring explicit values when provided."""
|
|
137
|
-
if new_items is not None:
|
|
138
|
-
return _extract_ids_or_empty(new_items)
|
|
139
|
-
return _extract_existing_ids(current_agent, attribute)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
def _pick_optional(
|
|
143
|
-
new_value: Any,
|
|
144
|
-
fallback: Any,
|
|
145
|
-
*,
|
|
146
|
-
transform: Callable[[Any], Any] | None = None,
|
|
147
|
-
) -> Any | None:
|
|
148
|
-
"""Return new_value when present, otherwise fallback, applying transform."""
|
|
149
|
-
value = new_value if new_value is not None else fallback
|
|
150
|
-
if value is None:
|
|
151
|
-
return None
|
|
152
|
-
return transform(value) if transform else value
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
def _existing_language_model_fields(current_agent: Any) -> dict[str, Any]:
|
|
156
|
-
"""Derive language model fields from the current agent or defaults."""
|
|
157
|
-
result: dict[str, Any] = {}
|
|
158
|
-
|
|
159
|
-
language_model_id = getattr(current_agent, "language_model_id", None)
|
|
160
|
-
if language_model_id:
|
|
161
|
-
result["language_model_id"] = language_model_id
|
|
162
|
-
return result
|
|
163
|
-
|
|
164
|
-
agent_config = getattr(current_agent, "agent_config", None)
|
|
165
|
-
if isinstance(agent_config, Mapping):
|
|
166
|
-
provider = agent_config.get("lm_provider")
|
|
167
|
-
model_name = agent_config.get("lm_name")
|
|
168
|
-
if provider:
|
|
169
|
-
result["provider"] = provider
|
|
170
|
-
if model_name:
|
|
171
|
-
result["model_name"] = model_name
|
|
172
|
-
|
|
173
|
-
if not result:
|
|
174
|
-
if DEFAULT_AGENT_PROVIDER:
|
|
175
|
-
result["provider"] = DEFAULT_AGENT_PROVIDER
|
|
176
|
-
result["model_name"] = DEFAULT_MODEL
|
|
177
|
-
|
|
178
|
-
return result
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
@dataclass(slots=True)
|
|
182
|
-
class AgentListParams:
|
|
183
|
-
"""Structured query parameters for listing agents."""
|
|
184
|
-
|
|
185
|
-
agent_type: str | None = None
|
|
186
|
-
framework: str | None = None
|
|
187
|
-
name: str | None = None
|
|
188
|
-
version: str | None = None
|
|
189
|
-
limit: int | None = None
|
|
190
|
-
page: int | None = None
|
|
191
|
-
include_deleted: bool | None = None
|
|
192
|
-
created_at_start: str | None = None
|
|
193
|
-
created_at_end: str | None = None
|
|
194
|
-
updated_at_start: str | None = None
|
|
195
|
-
updated_at_end: str | None = None
|
|
196
|
-
sync_langflow_agents: bool | None = None
|
|
197
|
-
metadata: Mapping[str, str] | None = None
|
|
198
|
-
|
|
199
|
-
def to_query_params(self) -> dict[str, Any]:
|
|
200
|
-
"""Convert the dataclass to API-ready query params."""
|
|
201
|
-
params = self._base_filter_params()
|
|
202
|
-
self._apply_pagination_params(params)
|
|
203
|
-
self._apply_timestamp_filters(params)
|
|
204
|
-
self._apply_metadata_filters(params)
|
|
205
|
-
|
|
206
|
-
return params
|
|
207
|
-
|
|
208
|
-
def _base_filter_params(self) -> dict[str, Any]:
|
|
209
|
-
"""Build base filter parameters from non-None fields.
|
|
210
|
-
|
|
211
|
-
Returns:
|
|
212
|
-
Dictionary of filter parameters with non-None values.
|
|
213
|
-
"""
|
|
214
|
-
return {
|
|
215
|
-
key: value
|
|
216
|
-
for key, value in (
|
|
217
|
-
("agent_type", self.agent_type),
|
|
218
|
-
("framework", self.framework),
|
|
219
|
-
("name", self.name),
|
|
220
|
-
("version", self.version),
|
|
221
|
-
)
|
|
222
|
-
if value is not None
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
def _apply_pagination_params(self, params: dict[str, Any]) -> None:
|
|
226
|
-
"""Apply pagination parameters to the params dictionary.
|
|
227
|
-
|
|
228
|
-
Args:
|
|
229
|
-
params: Dictionary to update with pagination parameters.
|
|
230
|
-
"""
|
|
231
|
-
if self.limit is not None:
|
|
232
|
-
if not 1 <= self.limit <= 100:
|
|
233
|
-
raise ValueError("limit must be between 1 and 100 inclusive")
|
|
234
|
-
params["limit"] = self.limit
|
|
9
|
+
Authors:
|
|
10
|
+
Raymond Christopher (raymond.christopher@gdplabs.id)
|
|
11
|
+
"""
|
|
235
12
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
raise ValueError("page must be >= 1")
|
|
239
|
-
params["page"] = self.page
|
|
13
|
+
# pylint: disable=duplicate-code
|
|
14
|
+
import warnings
|
|
240
15
|
|
|
241
|
-
|
|
242
|
-
params["include_deleted"] = str(self.include_deleted).lower()
|
|
16
|
+
_warned = False
|
|
243
17
|
|
|
244
|
-
if self.sync_langflow_agents is not None:
|
|
245
|
-
params["sync_langflow_agents"] = str(self.sync_langflow_agents).lower()
|
|
246
18
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
"updated_at_start": self.updated_at_start,
|
|
257
|
-
"updated_at_end": self.updated_at_end,
|
|
258
|
-
}
|
|
259
|
-
for key, value in timestamp_filters.items():
|
|
260
|
-
if value is not None:
|
|
261
|
-
params[key] = value
|
|
262
|
-
|
|
263
|
-
def _apply_metadata_filters(self, params: dict[str, Any]) -> None:
|
|
264
|
-
"""Apply metadata filter parameters to the params dictionary.
|
|
265
|
-
|
|
266
|
-
Args:
|
|
267
|
-
params: Dictionary to update with metadata filter parameters.
|
|
268
|
-
"""
|
|
269
|
-
if not self.metadata:
|
|
270
|
-
return
|
|
271
|
-
for key, value in self.metadata.items():
|
|
272
|
-
if value is not None:
|
|
273
|
-
params[f"metadata.{key}"] = value
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
@dataclass(slots=True)
|
|
277
|
-
class AgentListResult:
|
|
278
|
-
"""Structured response for list_agents that retains pagination metadata."""
|
|
279
|
-
|
|
280
|
-
items: list[Any] = field(default_factory=list)
|
|
281
|
-
total: int | None = None
|
|
282
|
-
page: int | None = None
|
|
283
|
-
limit: int | None = None
|
|
284
|
-
has_next: bool | None = None
|
|
285
|
-
has_prev: bool | None = None
|
|
286
|
-
message: str | None = None
|
|
287
|
-
|
|
288
|
-
def __len__(self) -> int: # pragma: no cover - simple delegation
|
|
289
|
-
"""Return the number of items in the result list."""
|
|
290
|
-
return len(self.items)
|
|
291
|
-
|
|
292
|
-
def __iter__(self): # pragma: no cover - simple delegation
|
|
293
|
-
"""Return an iterator over the items in the result list."""
|
|
294
|
-
return iter(self.items)
|
|
295
|
-
|
|
296
|
-
def __getitem__(self, index: int) -> Any: # pragma: no cover - simple delegation
|
|
297
|
-
"""Get an item from the result list by index.
|
|
298
|
-
|
|
299
|
-
Args:
|
|
300
|
-
index: Index of the item to retrieve.
|
|
301
|
-
|
|
302
|
-
Returns:
|
|
303
|
-
The item at the specified index.
|
|
304
|
-
"""
|
|
305
|
-
return self.items[index]
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
@dataclass(slots=True)
|
|
309
|
-
class AgentCreateRequest:
|
|
310
|
-
"""Declarative representation of an agent creation payload."""
|
|
311
|
-
|
|
312
|
-
name: str
|
|
313
|
-
instruction: str
|
|
314
|
-
model: str | None = DEFAULT_MODEL
|
|
315
|
-
language_model_id: str | None = None
|
|
316
|
-
provider: str | None = None
|
|
317
|
-
model_name: str | None = None
|
|
318
|
-
agent_type: str = DEFAULT_AGENT_TYPE
|
|
319
|
-
framework: str = DEFAULT_AGENT_FRAMEWORK
|
|
320
|
-
version: str = DEFAULT_AGENT_VERSION
|
|
321
|
-
account_id: str | None = None
|
|
322
|
-
description: str | None = None
|
|
323
|
-
metadata: Mapping[str, Any] | None = None
|
|
324
|
-
tools: Sequence[str | Any] | None = None
|
|
325
|
-
tool_configs: Mapping[str, Any] | None = None
|
|
326
|
-
agents: Sequence[str | Any] | None = None
|
|
327
|
-
mcps: Sequence[str | Any] | None = None
|
|
328
|
-
agent_config: Mapping[str, Any] | None = None
|
|
329
|
-
timeout: int | None = None
|
|
330
|
-
a2a_profile: Mapping[str, Any] | None = None
|
|
331
|
-
extras: Mapping[str, Any] | None = None
|
|
332
|
-
|
|
333
|
-
def to_payload(self) -> dict[str, Any]:
|
|
334
|
-
"""Materialise the request as a dict suitable for API submission."""
|
|
335
|
-
payload: dict[str, Any] = {
|
|
336
|
-
"name": self.name.strip(),
|
|
337
|
-
"instruction": self.instruction.strip(),
|
|
338
|
-
"type": self.agent_type,
|
|
339
|
-
"framework": self.framework,
|
|
340
|
-
"version": self.version,
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
payload.update(
|
|
344
|
-
resolve_language_model_fields(
|
|
345
|
-
model=self.model,
|
|
346
|
-
language_model_id=self.language_model_id,
|
|
347
|
-
provider=self.provider,
|
|
348
|
-
model_name=self.model_name,
|
|
349
|
-
)
|
|
19
|
+
def _warn_deprecated_import() -> None:
|
|
20
|
+
"""Emit deprecation warning for importing from _agent_payloads.py shim."""
|
|
21
|
+
global _warned
|
|
22
|
+
if not _warned:
|
|
23
|
+
warnings.warn(
|
|
24
|
+
"Importing from glaip_sdk.client._agent_payloads is deprecated. "
|
|
25
|
+
"Import from glaip_sdk.client.payloads.agent package directly instead.",
|
|
26
|
+
DeprecationWarning,
|
|
27
|
+
stacklevel=3,
|
|
350
28
|
)
|
|
29
|
+
_warned = True
|
|
351
30
|
|
|
352
|
-
if self.account_id is not None:
|
|
353
|
-
payload["account_id"] = self.account_id
|
|
354
|
-
if self.description is not None:
|
|
355
|
-
payload["description"] = self.description
|
|
356
|
-
if self.metadata is not None:
|
|
357
|
-
payload["metadata"] = _copy_structure(self.metadata)
|
|
358
|
-
|
|
359
|
-
if self.a2a_profile is not None:
|
|
360
|
-
payload["a2a_profile"] = _copy_structure(self.a2a_profile)
|
|
361
|
-
|
|
362
|
-
tool_ids = extract_ids(list(self.tools) if self.tools is not None else None)
|
|
363
|
-
if tool_ids:
|
|
364
|
-
payload["tools"] = tool_ids
|
|
365
|
-
|
|
366
|
-
agent_ids = extract_ids(list(self.agents) if self.agents is not None else None)
|
|
367
|
-
if agent_ids:
|
|
368
|
-
payload["agents"] = agent_ids
|
|
369
|
-
|
|
370
|
-
mcp_ids = extract_ids(list(self.mcps) if self.mcps is not None else None)
|
|
371
|
-
if mcp_ids:
|
|
372
|
-
payload["mcps"] = mcp_ids
|
|
373
|
-
|
|
374
|
-
if self.tool_configs is not None:
|
|
375
|
-
payload["tool_configs"] = _copy_structure(self.tool_configs)
|
|
376
|
-
|
|
377
|
-
effective_agent_config = _sanitize_agent_config(self.agent_config)
|
|
378
|
-
effective_agent_config = _merge_execution_timeout(effective_agent_config, self.timeout)
|
|
379
|
-
if effective_agent_config:
|
|
380
|
-
payload["agent_config"] = effective_agent_config
|
|
381
31
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
instruction: str | None = None
|
|
392
|
-
description: str | None = None
|
|
393
|
-
model: str | None = None
|
|
394
|
-
language_model_id: str | None = None
|
|
395
|
-
provider: str | None = None
|
|
396
|
-
model_name: str | None = None
|
|
397
|
-
agent_type: str | None = None
|
|
398
|
-
framework: str | None = None
|
|
399
|
-
version: str | None = None
|
|
400
|
-
account_id: str | None = None
|
|
401
|
-
metadata: Mapping[str, Any] | None = None
|
|
402
|
-
tools: Sequence[str | Any] | None = None
|
|
403
|
-
tool_configs: Mapping[str, Any] | None = None
|
|
404
|
-
agents: Sequence[str | Any] | None = None
|
|
405
|
-
mcps: Sequence[str | Any] | None = None
|
|
406
|
-
agent_config: Mapping[str, Any] | None = None
|
|
407
|
-
a2a_profile: Mapping[str, Any] | None = None
|
|
408
|
-
extras: Mapping[str, Any] | None = None
|
|
409
|
-
|
|
410
|
-
def to_payload(self, current_agent: Any) -> dict[str, Any]:
|
|
411
|
-
"""Materialise the request using current agent data as fallbacks."""
|
|
412
|
-
payload = _build_base_update_payload(self, current_agent)
|
|
413
|
-
payload.update(_resolve_update_language_model_fields(self, current_agent))
|
|
414
|
-
payload.update(_collect_optional_update_fields(self, current_agent))
|
|
415
|
-
payload.update(_collect_relationship_fields(self, current_agent))
|
|
416
|
-
|
|
417
|
-
agent_config_value = _resolve_agent_config_update(self, current_agent)
|
|
418
|
-
if agent_config_value is not None:
|
|
419
|
-
payload["agent_config"] = agent_config_value
|
|
420
|
-
|
|
421
|
-
merge_payload_fields(payload, self.extras, "update")
|
|
422
|
-
return payload
|
|
32
|
+
# Import from new package structure
|
|
33
|
+
from glaip_sdk.client.payloads.agent import ( # noqa: E402
|
|
34
|
+
AgentCreateRequest,
|
|
35
|
+
AgentListParams,
|
|
36
|
+
AgentListResult,
|
|
37
|
+
AgentUpdateRequest,
|
|
38
|
+
merge_payload_fields,
|
|
39
|
+
resolve_language_model_fields,
|
|
40
|
+
)
|
|
423
41
|
|
|
42
|
+
_warn_deprecated_import()
|
|
424
43
|
|
|
44
|
+
# Re-export everything
|
|
425
45
|
__all__ = [
|
|
426
46
|
"AgentCreateRequest",
|
|
427
47
|
"AgentListParams",
|
|
@@ -430,91 +50,3 @@ __all__ = [
|
|
|
430
50
|
"merge_payload_fields",
|
|
431
51
|
"resolve_language_model_fields",
|
|
432
52
|
]
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
def _build_base_update_payload(request: AgentUpdateRequest, current_agent: Any) -> dict[str, Any]:
|
|
436
|
-
"""Populate immutable agent update fields using request data or existing agent defaults."""
|
|
437
|
-
# Support both "agent_type" (runtime class) and "type" (API response) attributes
|
|
438
|
-
current_type = getattr(current_agent, "agent_type", None) or getattr(current_agent, "type", None)
|
|
439
|
-
return {
|
|
440
|
-
"name": (request.name.strip() if request.name is not None else getattr(current_agent, "name", None)),
|
|
441
|
-
"instruction": (
|
|
442
|
-
request.instruction.strip()
|
|
443
|
-
if request.instruction is not None
|
|
444
|
-
else getattr(current_agent, "instruction", None)
|
|
445
|
-
),
|
|
446
|
-
"type": request.agent_type or current_type or DEFAULT_AGENT_TYPE,
|
|
447
|
-
"framework": request.framework or getattr(current_agent, "framework", None) or DEFAULT_AGENT_FRAMEWORK,
|
|
448
|
-
"version": request.version or getattr(current_agent, "version", None) or DEFAULT_AGENT_VERSION,
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
def _resolve_update_language_model_fields(request: AgentUpdateRequest, current_agent: Any) -> dict[str, Any]:
|
|
453
|
-
"""Resolve the language-model portion of an update request with sensible fallbacks."""
|
|
454
|
-
fields = resolve_language_model_fields(
|
|
455
|
-
model=request.model,
|
|
456
|
-
language_model_id=request.language_model_id,
|
|
457
|
-
provider=request.provider,
|
|
458
|
-
model_name=request.model_name,
|
|
459
|
-
)
|
|
460
|
-
if not fields:
|
|
461
|
-
fields = _existing_language_model_fields(current_agent)
|
|
462
|
-
return fields
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
def _collect_optional_update_fields(request: AgentUpdateRequest, current_agent: Any) -> dict[str, Any]:
|
|
466
|
-
"""Collect optional agent fields, preserving current values when updates are absent."""
|
|
467
|
-
result: dict[str, Any] = {}
|
|
468
|
-
|
|
469
|
-
for field_name, value in (
|
|
470
|
-
("account_id", request.account_id),
|
|
471
|
-
("description", request.description),
|
|
472
|
-
):
|
|
473
|
-
resolved_value = _pick_optional(value, getattr(current_agent, field_name, None))
|
|
474
|
-
if resolved_value is not None:
|
|
475
|
-
result[field_name] = resolved_value
|
|
476
|
-
|
|
477
|
-
metadata_value = _pick_optional(
|
|
478
|
-
request.metadata,
|
|
479
|
-
getattr(current_agent, "metadata", None),
|
|
480
|
-
transform=_copy_structure,
|
|
481
|
-
)
|
|
482
|
-
if metadata_value is not None:
|
|
483
|
-
result["metadata"] = metadata_value
|
|
484
|
-
|
|
485
|
-
profile_value = _pick_optional(
|
|
486
|
-
request.a2a_profile,
|
|
487
|
-
getattr(current_agent, "a2a_profile", None),
|
|
488
|
-
transform=_copy_structure,
|
|
489
|
-
)
|
|
490
|
-
if profile_value is not None:
|
|
491
|
-
result["a2a_profile"] = profile_value
|
|
492
|
-
|
|
493
|
-
tool_configs_value = _pick_optional(
|
|
494
|
-
request.tool_configs,
|
|
495
|
-
getattr(current_agent, "tool_configs", None),
|
|
496
|
-
transform=_copy_structure,
|
|
497
|
-
)
|
|
498
|
-
if tool_configs_value is not None:
|
|
499
|
-
result["tool_configs"] = tool_configs_value
|
|
500
|
-
|
|
501
|
-
return result
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
def _collect_relationship_fields(request: AgentUpdateRequest, current_agent: Any) -> dict[str, Any]:
|
|
505
|
-
"""Return relationship identifiers (tools/agents/mcps) for an update request."""
|
|
506
|
-
return {
|
|
507
|
-
"tools": _resolve_relation_ids(request.tools, current_agent, "tools"),
|
|
508
|
-
"agents": _resolve_relation_ids(request.agents, current_agent, "agents"),
|
|
509
|
-
"mcps": _resolve_relation_ids(request.mcps, current_agent, "mcps"),
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
def _resolve_agent_config_update(request: AgentUpdateRequest, current_agent: Any) -> dict[str, Any] | None:
|
|
514
|
-
"""Determine the agent_config payload to send, if any."""
|
|
515
|
-
effective_agent_config = _sanitize_agent_config(request.agent_config)
|
|
516
|
-
if effective_agent_config is not None:
|
|
517
|
-
return effective_agent_config
|
|
518
|
-
if getattr(current_agent, "agent_config", None):
|
|
519
|
-
return _sanitize_agent_config(current_agent.agent_config)
|
|
520
|
-
return None
|
glaip_sdk/client/agents.py
CHANGED
glaip_sdk/client/main.py
CHANGED
|
@@ -19,7 +19,7 @@ from glaip_sdk.client.tools import ToolClient
|
|
|
19
19
|
|
|
20
20
|
if TYPE_CHECKING: # pragma: no cover
|
|
21
21
|
from glaip_sdk.agents import Agent
|
|
22
|
-
from glaip_sdk.client.
|
|
22
|
+
from glaip_sdk.client.payloads.agent import AgentListResult
|
|
23
23
|
from glaip_sdk.mcps import MCP
|
|
24
24
|
from glaip_sdk.tools import Tool
|
|
25
25
|
|