glaip-sdk 0.0.20__py3-none-any.whl → 0.7.7__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 (216) hide show
  1. glaip_sdk/__init__.py +44 -4
  2. glaip_sdk/_version.py +10 -3
  3. glaip_sdk/agents/__init__.py +27 -0
  4. glaip_sdk/agents/base.py +1250 -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 +271 -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/__init__.py +119 -0
  12. glaip_sdk/cli/commands/agents/_common.py +561 -0
  13. glaip_sdk/cli/commands/agents/create.py +151 -0
  14. glaip_sdk/cli/commands/agents/delete.py +64 -0
  15. glaip_sdk/cli/commands/agents/get.py +89 -0
  16. glaip_sdk/cli/commands/agents/list.py +129 -0
  17. glaip_sdk/cli/commands/agents/run.py +264 -0
  18. glaip_sdk/cli/commands/agents/sync_langflow.py +72 -0
  19. glaip_sdk/cli/commands/agents/update.py +112 -0
  20. glaip_sdk/cli/commands/common_config.py +104 -0
  21. glaip_sdk/cli/commands/configure.py +734 -143
  22. glaip_sdk/cli/commands/mcps/__init__.py +94 -0
  23. glaip_sdk/cli/commands/mcps/_common.py +459 -0
  24. glaip_sdk/cli/commands/mcps/connect.py +82 -0
  25. glaip_sdk/cli/commands/mcps/create.py +152 -0
  26. glaip_sdk/cli/commands/mcps/delete.py +73 -0
  27. glaip_sdk/cli/commands/mcps/get.py +212 -0
  28. glaip_sdk/cli/commands/mcps/list.py +69 -0
  29. glaip_sdk/cli/commands/mcps/tools.py +235 -0
  30. glaip_sdk/cli/commands/mcps/update.py +190 -0
  31. glaip_sdk/cli/commands/models.py +14 -12
  32. glaip_sdk/cli/commands/shared/__init__.py +21 -0
  33. glaip_sdk/cli/commands/shared/formatters.py +91 -0
  34. glaip_sdk/cli/commands/tools/__init__.py +69 -0
  35. glaip_sdk/cli/commands/tools/_common.py +80 -0
  36. glaip_sdk/cli/commands/tools/create.py +228 -0
  37. glaip_sdk/cli/commands/tools/delete.py +61 -0
  38. glaip_sdk/cli/commands/tools/get.py +103 -0
  39. glaip_sdk/cli/commands/tools/list.py +69 -0
  40. glaip_sdk/cli/commands/tools/script.py +49 -0
  41. glaip_sdk/cli/commands/tools/update.py +102 -0
  42. glaip_sdk/cli/commands/transcripts/__init__.py +90 -0
  43. glaip_sdk/cli/commands/transcripts/_common.py +9 -0
  44. glaip_sdk/cli/commands/transcripts/clear.py +5 -0
  45. glaip_sdk/cli/commands/transcripts/detail.py +5 -0
  46. glaip_sdk/cli/commands/transcripts_original.py +756 -0
  47. glaip_sdk/cli/commands/update.py +164 -23
  48. glaip_sdk/cli/config.py +49 -7
  49. glaip_sdk/cli/constants.py +38 -0
  50. glaip_sdk/cli/context.py +8 -0
  51. glaip_sdk/cli/core/__init__.py +79 -0
  52. glaip_sdk/cli/core/context.py +124 -0
  53. glaip_sdk/cli/core/output.py +851 -0
  54. glaip_sdk/cli/core/prompting.py +649 -0
  55. glaip_sdk/cli/core/rendering.py +187 -0
  56. glaip_sdk/cli/display.py +45 -32
  57. glaip_sdk/cli/entrypoint.py +20 -0
  58. glaip_sdk/cli/hints.py +57 -0
  59. glaip_sdk/cli/io.py +14 -17
  60. glaip_sdk/cli/main.py +344 -167
  61. glaip_sdk/cli/masking.py +21 -33
  62. glaip_sdk/cli/mcp_validators.py +5 -15
  63. glaip_sdk/cli/pager.py +15 -22
  64. glaip_sdk/cli/parsers/__init__.py +1 -3
  65. glaip_sdk/cli/parsers/json_input.py +11 -22
  66. glaip_sdk/cli/resolution.py +5 -10
  67. glaip_sdk/cli/rich_helpers.py +1 -3
  68. glaip_sdk/cli/slash/__init__.py +0 -9
  69. glaip_sdk/cli/slash/accounts_controller.py +580 -0
  70. glaip_sdk/cli/slash/accounts_shared.py +75 -0
  71. glaip_sdk/cli/slash/agent_session.py +65 -29
  72. glaip_sdk/cli/slash/prompt.py +24 -10
  73. glaip_sdk/cli/slash/remote_runs_controller.py +566 -0
  74. glaip_sdk/cli/slash/session.py +827 -232
  75. glaip_sdk/cli/slash/tui/__init__.py +34 -0
  76. glaip_sdk/cli/slash/tui/accounts.tcss +88 -0
  77. glaip_sdk/cli/slash/tui/accounts_app.py +933 -0
  78. glaip_sdk/cli/slash/tui/background_tasks.py +72 -0
  79. glaip_sdk/cli/slash/tui/clipboard.py +147 -0
  80. glaip_sdk/cli/slash/tui/context.py +59 -0
  81. glaip_sdk/cli/slash/tui/keybind_registry.py +235 -0
  82. glaip_sdk/cli/slash/tui/loading.py +58 -0
  83. glaip_sdk/cli/slash/tui/remote_runs_app.py +628 -0
  84. glaip_sdk/cli/slash/tui/terminal.py +402 -0
  85. glaip_sdk/cli/slash/tui/theme/__init__.py +15 -0
  86. glaip_sdk/cli/slash/tui/theme/catalog.py +79 -0
  87. glaip_sdk/cli/slash/tui/theme/manager.py +86 -0
  88. glaip_sdk/cli/slash/tui/theme/tokens.py +55 -0
  89. glaip_sdk/cli/slash/tui/toast.py +123 -0
  90. glaip_sdk/cli/transcript/__init__.py +12 -52
  91. glaip_sdk/cli/transcript/cache.py +258 -60
  92. glaip_sdk/cli/transcript/capture.py +72 -21
  93. glaip_sdk/cli/transcript/history.py +815 -0
  94. glaip_sdk/cli/transcript/launcher.py +1 -3
  95. glaip_sdk/cli/transcript/viewer.py +79 -329
  96. glaip_sdk/cli/update_notifier.py +385 -24
  97. glaip_sdk/cli/validators.py +16 -18
  98. glaip_sdk/client/__init__.py +3 -1
  99. glaip_sdk/client/_schedule_payloads.py +89 -0
  100. glaip_sdk/client/agent_runs.py +147 -0
  101. glaip_sdk/client/agents.py +370 -100
  102. glaip_sdk/client/base.py +78 -35
  103. glaip_sdk/client/hitl.py +136 -0
  104. glaip_sdk/client/main.py +25 -10
  105. glaip_sdk/client/mcps.py +166 -27
  106. glaip_sdk/client/payloads/agent/__init__.py +23 -0
  107. glaip_sdk/client/{_agent_payloads.py → payloads/agent/requests.py} +65 -74
  108. glaip_sdk/client/payloads/agent/responses.py +43 -0
  109. glaip_sdk/client/run_rendering.py +583 -79
  110. glaip_sdk/client/schedules.py +439 -0
  111. glaip_sdk/client/shared.py +21 -0
  112. glaip_sdk/client/tools.py +214 -56
  113. glaip_sdk/client/validators.py +20 -48
  114. glaip_sdk/config/constants.py +11 -0
  115. glaip_sdk/exceptions.py +1 -3
  116. glaip_sdk/hitl/__init__.py +48 -0
  117. glaip_sdk/hitl/base.py +64 -0
  118. glaip_sdk/hitl/callback.py +43 -0
  119. glaip_sdk/hitl/local.py +121 -0
  120. glaip_sdk/hitl/remote.py +523 -0
  121. glaip_sdk/icons.py +9 -3
  122. glaip_sdk/mcps/__init__.py +21 -0
  123. glaip_sdk/mcps/base.py +345 -0
  124. glaip_sdk/models/__init__.py +107 -0
  125. glaip_sdk/models/agent.py +47 -0
  126. glaip_sdk/models/agent_runs.py +117 -0
  127. glaip_sdk/models/common.py +42 -0
  128. glaip_sdk/models/mcp.py +33 -0
  129. glaip_sdk/models/schedule.py +224 -0
  130. glaip_sdk/models/tool.py +33 -0
  131. glaip_sdk/payload_schemas/__init__.py +1 -13
  132. glaip_sdk/payload_schemas/agent.py +1 -3
  133. glaip_sdk/registry/__init__.py +55 -0
  134. glaip_sdk/registry/agent.py +164 -0
  135. glaip_sdk/registry/base.py +139 -0
  136. glaip_sdk/registry/mcp.py +253 -0
  137. glaip_sdk/registry/tool.py +445 -0
  138. glaip_sdk/rich_components.py +58 -2
  139. glaip_sdk/runner/__init__.py +76 -0
  140. glaip_sdk/runner/base.py +84 -0
  141. glaip_sdk/runner/deps.py +112 -0
  142. glaip_sdk/runner/langgraph.py +872 -0
  143. glaip_sdk/runner/logging_config.py +77 -0
  144. glaip_sdk/runner/mcp_adapter/__init__.py +13 -0
  145. glaip_sdk/runner/mcp_adapter/base_mcp_adapter.py +43 -0
  146. glaip_sdk/runner/mcp_adapter/langchain_mcp_adapter.py +257 -0
  147. glaip_sdk/runner/mcp_adapter/mcp_config_builder.py +95 -0
  148. glaip_sdk/runner/tool_adapter/__init__.py +18 -0
  149. glaip_sdk/runner/tool_adapter/base_tool_adapter.py +44 -0
  150. glaip_sdk/runner/tool_adapter/langchain_tool_adapter.py +242 -0
  151. glaip_sdk/schedules/__init__.py +22 -0
  152. glaip_sdk/schedules/base.py +291 -0
  153. glaip_sdk/tools/__init__.py +22 -0
  154. glaip_sdk/tools/base.py +468 -0
  155. glaip_sdk/utils/__init__.py +59 -12
  156. glaip_sdk/utils/a2a/__init__.py +34 -0
  157. glaip_sdk/utils/a2a/event_processor.py +188 -0
  158. glaip_sdk/utils/agent_config.py +4 -14
  159. glaip_sdk/utils/bundler.py +403 -0
  160. glaip_sdk/utils/client.py +111 -0
  161. glaip_sdk/utils/client_utils.py +46 -28
  162. glaip_sdk/utils/datetime_helpers.py +58 -0
  163. glaip_sdk/utils/discovery.py +78 -0
  164. glaip_sdk/utils/display.py +25 -21
  165. glaip_sdk/utils/export.py +143 -0
  166. glaip_sdk/utils/general.py +1 -36
  167. glaip_sdk/utils/import_export.py +15 -16
  168. glaip_sdk/utils/import_resolver.py +524 -0
  169. glaip_sdk/utils/instructions.py +101 -0
  170. glaip_sdk/utils/rendering/__init__.py +115 -1
  171. glaip_sdk/utils/rendering/formatting.py +38 -23
  172. glaip_sdk/utils/rendering/layout/__init__.py +64 -0
  173. glaip_sdk/utils/rendering/{renderer → layout}/panels.py +10 -3
  174. glaip_sdk/utils/rendering/{renderer → layout}/progress.py +73 -12
  175. glaip_sdk/utils/rendering/layout/summary.py +74 -0
  176. glaip_sdk/utils/rendering/layout/transcript.py +606 -0
  177. glaip_sdk/utils/rendering/models.py +18 -8
  178. glaip_sdk/utils/rendering/renderer/__init__.py +9 -51
  179. glaip_sdk/utils/rendering/renderer/base.py +534 -882
  180. glaip_sdk/utils/rendering/renderer/config.py +4 -10
  181. glaip_sdk/utils/rendering/renderer/debug.py +30 -34
  182. glaip_sdk/utils/rendering/renderer/factory.py +138 -0
  183. glaip_sdk/utils/rendering/renderer/stream.py +13 -54
  184. glaip_sdk/utils/rendering/renderer/summary_window.py +79 -0
  185. glaip_sdk/utils/rendering/renderer/thinking.py +273 -0
  186. glaip_sdk/utils/rendering/renderer/toggle.py +182 -0
  187. glaip_sdk/utils/rendering/renderer/tool_panels.py +442 -0
  188. glaip_sdk/utils/rendering/renderer/transcript_mode.py +162 -0
  189. glaip_sdk/utils/rendering/state.py +204 -0
  190. glaip_sdk/utils/rendering/step_tree_state.py +100 -0
  191. glaip_sdk/utils/rendering/steps/__init__.py +34 -0
  192. glaip_sdk/utils/rendering/steps/event_processor.py +778 -0
  193. glaip_sdk/utils/rendering/steps/format.py +176 -0
  194. glaip_sdk/utils/rendering/{steps.py → steps/manager.py} +122 -26
  195. glaip_sdk/utils/rendering/timing.py +36 -0
  196. glaip_sdk/utils/rendering/viewer/__init__.py +21 -0
  197. glaip_sdk/utils/rendering/viewer/presenter.py +184 -0
  198. glaip_sdk/utils/resource_refs.py +29 -26
  199. glaip_sdk/utils/runtime_config.py +425 -0
  200. glaip_sdk/utils/serialization.py +32 -46
  201. glaip_sdk/utils/sync.py +162 -0
  202. glaip_sdk/utils/tool_detection.py +301 -0
  203. glaip_sdk/utils/tool_storage_provider.py +140 -0
  204. glaip_sdk/utils/validation.py +20 -28
  205. {glaip_sdk-0.0.20.dist-info → glaip_sdk-0.7.7.dist-info}/METADATA +78 -23
  206. glaip_sdk-0.7.7.dist-info/RECORD +213 -0
  207. {glaip_sdk-0.0.20.dist-info → glaip_sdk-0.7.7.dist-info}/WHEEL +2 -1
  208. glaip_sdk-0.7.7.dist-info/entry_points.txt +2 -0
  209. glaip_sdk-0.7.7.dist-info/top_level.txt +1 -0
  210. glaip_sdk/cli/commands/agents.py +0 -1412
  211. glaip_sdk/cli/commands/mcps.py +0 -1225
  212. glaip_sdk/cli/commands/tools.py +0 -597
  213. glaip_sdk/cli/utils.py +0 -1330
  214. glaip_sdk/models.py +0 -259
  215. glaip_sdk-0.0.20.dist-info/RECORD +0 -80
  216. glaip_sdk-0.0.20.dist-info/entry_points.txt +0 -3
@@ -0,0 +1,872 @@
1
+ """LangGraph-based runner for local agent execution.
2
+
3
+ This module provides the LangGraphRunner which executes glaip-sdk agents
4
+ locally via the aip-agents LangGraphReactAgent, without requiring the AIP server.
5
+
6
+ Authors:
7
+ Christian Trisno Sen Long Chen (christian.t.s.l.chen@gdplabs.id)
8
+
9
+ Example:
10
+ >>> from glaip_sdk.runner import LangGraphRunner
11
+ >>> from glaip_sdk.agents import Agent
12
+ >>>
13
+ >>> runner = LangGraphRunner()
14
+ >>> agent = Agent(name="my-agent", instruction="You are helpful.")
15
+ >>> result = runner.run(agent, "Hello, world!")
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ import asyncio
21
+ import inspect
22
+ import logging
23
+ from dataclasses import dataclass
24
+ from typing import TYPE_CHECKING, Any
25
+
26
+ from gllm_core.utils import LoggerManager
27
+
28
+ from glaip_sdk.client.run_rendering import AgentRunRenderingManager
29
+ from glaip_sdk.hitl import PauseResumeCallback
30
+ from glaip_sdk.runner.base import BaseRunner
31
+ from glaip_sdk.runner.deps import (
32
+ check_local_runtime_available,
33
+ get_local_runtime_missing_message,
34
+ )
35
+ from glaip_sdk.utils.tool_storage_provider import build_tool_output_manager
36
+
37
+ if TYPE_CHECKING:
38
+ from langchain_core.messages import BaseMessage
39
+
40
+ from glaip_sdk.agents.base import Agent
41
+
42
+
43
+ _AIP_LOGS_SWALLOWED = False
44
+
45
+
46
+ def _swallow_aip_logs(level: int = logging.ERROR) -> None:
47
+ """Consume noisy AIPAgents logs once (opt-in via runner flag)."""
48
+ global _AIP_LOGS_SWALLOWED
49
+ if _AIP_LOGS_SWALLOWED:
50
+ return
51
+ prefixes = ("aip_agents.",)
52
+
53
+ def _silence(name: str) -> None:
54
+ lg = logging.getLogger(name)
55
+ lg.handlers = [logging.NullHandler()]
56
+ lg.propagate = False
57
+ lg.setLevel(level)
58
+
59
+ # Silence any already-registered loggers under the given prefixes
60
+ for logger_name in logging.root.manager.loggerDict:
61
+ if any(logger_name.startswith(prefix) for prefix in prefixes):
62
+ _silence(logger_name)
63
+
64
+ # Also set the base prefix loggers so future children inherit silence
65
+ for prefix in prefixes:
66
+ _silence(prefix.rstrip("."))
67
+ _AIP_LOGS_SWALLOWED = True
68
+
69
+
70
+ logger = LoggerManager().get_logger(__name__)
71
+
72
+
73
+ def _convert_chat_history_to_messages(
74
+ chat_history: list[dict[str, str]] | None,
75
+ ) -> list[BaseMessage]:
76
+ """Convert chat history dicts to LangChain messages.
77
+
78
+ Args:
79
+ chat_history: List of dicts with "role" and "content" keys.
80
+ Supported roles: "user"/"human", "assistant"/"ai", "system".
81
+
82
+ Returns:
83
+ List of LangChain BaseMessage instances.
84
+ """
85
+ if not chat_history:
86
+ return []
87
+
88
+ from langchain_core.messages import AIMessage, HumanMessage, SystemMessage # noqa: PLC0415
89
+
90
+ messages: list[BaseMessage] = []
91
+ for msg in chat_history:
92
+ role = msg.get("role", "").lower()
93
+ content = msg.get("content", "")
94
+
95
+ if role in ("user", "human"):
96
+ messages.append(HumanMessage(content=content))
97
+ elif role in ("assistant", "ai"):
98
+ messages.append(AIMessage(content=content))
99
+ elif role == "system":
100
+ messages.append(SystemMessage(content=content))
101
+ else:
102
+ # Default to human message for unknown roles
103
+ logger.warning("Unknown chat history role '%s', treating as user message", role)
104
+ messages.append(HumanMessage(content=content))
105
+
106
+ return messages
107
+
108
+
109
+ @dataclass(frozen=True, slots=True)
110
+ class LangGraphRunner(BaseRunner):
111
+ """Runner implementation using aip-agents LangGraphReactAgent.
112
+
113
+ Current behavior:
114
+ - Execute via `LangGraphReactAgent.arun_sse_stream()` (normalized SSE-compatible stream)
115
+ - Route all events through `AgentRunRenderingManager.async_process_stream_events`
116
+ for unified rendering between local and remote agents
117
+
118
+ Attributes:
119
+ default_model: Model name to use when agent.model is not set.
120
+ Defaults to "gpt-4o-mini".
121
+ """
122
+
123
+ default_model: str = "openai/gpt-4o-mini"
124
+
125
+ def run(
126
+ self,
127
+ agent: Agent,
128
+ message: str,
129
+ verbose: bool = False,
130
+ runtime_config: dict[str, Any] | None = None,
131
+ chat_history: list[dict[str, str]] | None = None,
132
+ *,
133
+ swallow_aip_logs: bool = True,
134
+ **kwargs: Any,
135
+ ) -> str:
136
+ """Execute agent synchronously and return final response text.
137
+
138
+ Args:
139
+ agent: The glaip_sdk Agent to execute.
140
+ message: The user message to send to the agent.
141
+ verbose: If True, emit debug trace output during execution.
142
+ Defaults to False.
143
+ runtime_config: Optional runtime configuration for tools, MCPs, etc.
144
+ Defaults to None. (Implemented in PR-04+)
145
+ chat_history: Optional list of prior conversation messages.
146
+ Each message is a dict with "role" and "content" keys.
147
+ Defaults to None.
148
+ swallow_aip_logs: When True (default), silence noisy logs from aip-agents,
149
+ gllm_inference, OpenAILMInvoker, and httpx. Set to False to honor user
150
+ logging configuration.
151
+ **kwargs: Additional keyword arguments passed to the backend.
152
+
153
+ Returns:
154
+ The final response text from the agent.
155
+
156
+ Raises:
157
+ RuntimeError: If the local runtime dependencies are not available.
158
+ RuntimeError: If no final response is received from the agent.
159
+ """
160
+ if not check_local_runtime_available():
161
+ raise RuntimeError(get_local_runtime_missing_message())
162
+
163
+ try:
164
+ asyncio.get_running_loop()
165
+ except RuntimeError:
166
+ pass
167
+ else:
168
+ raise RuntimeError(
169
+ "LangGraphRunner.run() cannot be called from a running event loop. "
170
+ "Use 'await LangGraphRunner.arun(...)' instead."
171
+ )
172
+
173
+ coro = self._arun_internal(
174
+ agent=agent,
175
+ message=message,
176
+ verbose=verbose,
177
+ runtime_config=runtime_config,
178
+ chat_history=chat_history,
179
+ swallow_aip_logs=swallow_aip_logs,
180
+ **kwargs,
181
+ )
182
+
183
+ return asyncio.run(coro)
184
+
185
+ async def arun(
186
+ self,
187
+ agent: Agent,
188
+ message: str,
189
+ verbose: bool = False,
190
+ runtime_config: dict[str, Any] | None = None,
191
+ chat_history: list[dict[str, str]] | None = None,
192
+ *,
193
+ swallow_aip_logs: bool = True,
194
+ **kwargs: Any,
195
+ ) -> str:
196
+ """Execute agent asynchronously and return final response text.
197
+
198
+ Args:
199
+ agent: The glaip_sdk Agent to execute.
200
+ message: The user message to send to the agent.
201
+ verbose: If True, emit debug trace output during execution.
202
+ Defaults to False.
203
+ runtime_config: Optional runtime configuration for tools, MCPs, etc.
204
+ Defaults to None. (Implemented in PR-04+)
205
+ chat_history: Optional list of prior conversation messages.
206
+ Each message is a dict with "role" and "content" keys.
207
+ Defaults to None.
208
+ swallow_aip_logs: When True (default), silence noisy AIPAgents logs.
209
+ **kwargs: Additional keyword arguments passed to the backend.
210
+
211
+ Returns:
212
+ The final response text from the agent.
213
+
214
+ Raises:
215
+ RuntimeError: If no final response is received from the agent.
216
+ """
217
+ return await self._arun_internal(
218
+ agent=agent,
219
+ message=message,
220
+ verbose=verbose,
221
+ runtime_config=runtime_config,
222
+ chat_history=chat_history,
223
+ swallow_aip_logs=swallow_aip_logs,
224
+ **kwargs,
225
+ )
226
+
227
+ async def _arun_internal(
228
+ self,
229
+ agent: Agent,
230
+ message: str,
231
+ verbose: bool = False,
232
+ runtime_config: dict[str, Any] | None = None,
233
+ chat_history: list[dict[str, str]] | None = None,
234
+ *,
235
+ swallow_aip_logs: bool = True,
236
+ **kwargs: Any,
237
+ ) -> str:
238
+ """Internal async implementation of agent execution.
239
+
240
+ Args:
241
+ agent: The glaip_sdk Agent to execute.
242
+ message: The user message to send to the agent.
243
+ verbose: If True, emit debug trace output during execution.
244
+ runtime_config: Optional runtime configuration for tools, MCPs, etc.
245
+ chat_history: Optional list of prior conversation messages.
246
+ swallow_aip_logs: When True (default), silence noisy AIPAgents logs.
247
+ **kwargs: Additional keyword arguments passed to the backend.
248
+
249
+ Returns:
250
+ The final response text from the agent.
251
+ """
252
+ # Optionally swallow noisy AIPAgents logs
253
+ if swallow_aip_logs:
254
+ _swallow_aip_logs()
255
+
256
+ # POC/MVP: Create pause/resume callback for interactive HITL input
257
+ pause_resume_callback = PauseResumeCallback()
258
+
259
+ # Build the local LangGraphReactAgent from the glaip_sdk Agent
260
+ local_agent = self.build_langgraph_agent(
261
+ agent, runtime_config=runtime_config, pause_resume_callback=pause_resume_callback
262
+ )
263
+
264
+ # Convert chat history to LangChain messages for the agent
265
+ langchain_messages = _convert_chat_history_to_messages(chat_history)
266
+ if langchain_messages:
267
+ kwargs["messages"] = langchain_messages
268
+ logger.debug(
269
+ "Passing %d chat history messages to agent '%s'",
270
+ len(langchain_messages),
271
+ agent.name,
272
+ )
273
+
274
+ # Use shared render manager for unified processing
275
+ render_manager = AgentRunRenderingManager(logger)
276
+ renderer = render_manager.create_renderer(kwargs.get("renderer"), verbose=verbose)
277
+
278
+ # POC/MVP: Set renderer on callback so LocalPromptHandler can pause/resume Live
279
+ pause_resume_callback.set_renderer(renderer)
280
+
281
+ meta = render_manager.build_initial_metadata(agent.name, message, kwargs)
282
+ render_manager.start_renderer(renderer, meta)
283
+
284
+ try:
285
+ # Use shared async stream processor for unified event handling
286
+ (
287
+ final_text,
288
+ stats_usage,
289
+ started_monotonic,
290
+ finished_monotonic,
291
+ ) = await render_manager.async_process_stream_events(
292
+ local_agent.arun_sse_stream(message, **kwargs),
293
+ renderer,
294
+ meta,
295
+ skip_final_render=True,
296
+ )
297
+ except KeyboardInterrupt:
298
+ try:
299
+ renderer.close()
300
+ finally:
301
+ raise
302
+ except Exception:
303
+ try:
304
+ renderer.close()
305
+ finally:
306
+ raise
307
+
308
+ # Use shared finalizer to avoid code duplication
309
+ from glaip_sdk.client.run_rendering import finalize_render_manager # noqa: PLC0415
310
+
311
+ return finalize_render_manager(
312
+ render_manager, renderer, final_text, stats_usage, started_monotonic, finished_monotonic
313
+ )
314
+
315
+ def build_langgraph_agent(
316
+ self,
317
+ agent: Agent,
318
+ runtime_config: dict[str, Any] | None = None,
319
+ shared_tool_output_manager: Any | None = None,
320
+ *,
321
+ pause_resume_callback: Any | None = None,
322
+ ) -> Any:
323
+ """Build a LangGraphReactAgent from a glaip_sdk Agent definition.
324
+
325
+ Args:
326
+ agent: The glaip_sdk Agent to convert.
327
+ runtime_config: Optional runtime configuration with tool_configs,
328
+ mcp_configs, agent_config, and agent-specific overrides.
329
+ shared_tool_output_manager: Optional ToolOutputManager to reuse across
330
+ agents with tool_output_sharing enabled.
331
+ pause_resume_callback: Optional callback used to pause/resume the renderer
332
+ during interactive HITL prompts.
333
+
334
+ Returns:
335
+ A configured LangGraphReactAgent instance.
336
+
337
+ Raises:
338
+ ImportError: If aip-agents is not installed.
339
+ ValueError: If agent has unsupported tools, MCPs, or sub-agents for local mode.
340
+ """
341
+ from aip_agents.agent import LangGraphReactAgent # noqa: PLC0415
342
+
343
+ from glaip_sdk.runner.tool_adapter import LangChainToolAdapter # noqa: PLC0415
344
+
345
+ # Adapt tools for local execution
346
+ # NOTE: CLI parity waiver - local tool execution is SDK-only for MVP.
347
+ # See specs/f/local-agent-runtime/plan.md: "CLI parity is explicitly deferred
348
+ # and will require SDK Technical Lead sign-off per constitution principle IV."
349
+ langchain_tools: list[Any] = []
350
+ if agent.tools:
351
+ adapter = LangChainToolAdapter()
352
+ langchain_tools = adapter.adapt_tools(agent.tools)
353
+
354
+ # Normalize runtime config: merge global and agent-specific configs
355
+ normalized_config = self._normalize_runtime_config(runtime_config, agent)
356
+
357
+ # Merge tool_configs: agent definition < runtime config
358
+ tool_configs = self._merge_tool_configs(agent, normalized_config)
359
+
360
+ # Merge mcp_configs: agent definition < runtime config
361
+ mcp_configs = self._merge_mcp_configs(agent, normalized_config)
362
+
363
+ # Merge agent_config: agent definition < runtime config
364
+ merged_agent_config = self._merge_agent_config(agent, normalized_config)
365
+ agent_config_params, agent_config_kwargs = self._apply_agent_config(merged_agent_config)
366
+
367
+ tool_output_manager = self._resolve_tool_output_manager(
368
+ agent,
369
+ merged_agent_config,
370
+ shared_tool_output_manager,
371
+ )
372
+
373
+ # Build sub-agents recursively, sharing tool output manager when enabled.
374
+ sub_agent_instances = self._build_sub_agents(
375
+ agent.agents,
376
+ runtime_config,
377
+ shared_tool_output_manager=tool_output_manager,
378
+ )
379
+
380
+ # Build the LangGraphReactAgent with tools, sub-agents, and configs
381
+ local_agent = LangGraphReactAgent(
382
+ name=agent.name,
383
+ instruction=agent.instruction,
384
+ description=agent.description,
385
+ model=agent.model or self.default_model,
386
+ tools=langchain_tools,
387
+ agents=sub_agent_instances if sub_agent_instances else None,
388
+ tool_configs=tool_configs if tool_configs else None,
389
+ tool_output_manager=tool_output_manager,
390
+ **agent_config_params,
391
+ **agent_config_kwargs,
392
+ )
393
+
394
+ # Add MCP servers if configured
395
+ self._add_mcp_servers(local_agent, agent, mcp_configs)
396
+
397
+ # Inject local HITL manager only if hitl_enabled is True (master switch).
398
+ # This matches remote behavior: hitl_enabled gates the HITL plumbing.
399
+ # Tool-level HITL configs are only enforced when hitl_enabled=True.
400
+ self._inject_hitl_manager(local_agent, merged_agent_config, agent.name, pause_resume_callback)
401
+
402
+ logger.debug(
403
+ "Built local LangGraphReactAgent for agent '%s' with %d tools, %d sub-agents, and %d MCPs",
404
+ agent.name,
405
+ len(langchain_tools),
406
+ len(sub_agent_instances),
407
+ len(agent.mcps) if agent.mcps else 0,
408
+ )
409
+ return local_agent
410
+
411
+ def _resolve_tool_output_manager(
412
+ self,
413
+ agent: Agent,
414
+ merged_agent_config: dict[str, Any],
415
+ shared_tool_output_manager: Any | None,
416
+ ) -> Any | None:
417
+ """Resolve tool output manager for local agent execution."""
418
+ tool_output_sharing_enabled = merged_agent_config.get("tool_output_sharing", False)
419
+ if not tool_output_sharing_enabled:
420
+ return None
421
+ if shared_tool_output_manager is not None:
422
+ return shared_tool_output_manager
423
+ return build_tool_output_manager(agent.name, merged_agent_config)
424
+
425
+ def _inject_hitl_manager(
426
+ self,
427
+ local_agent: Any,
428
+ merged_agent_config: dict[str, Any],
429
+ agent_name: str,
430
+ pause_resume_callback: Any | None,
431
+ ) -> None:
432
+ """Inject HITL manager when enabled, mirroring remote gating behavior."""
433
+ hitl_enabled = merged_agent_config.get("hitl_enabled", False)
434
+ if hitl_enabled:
435
+ try:
436
+ from aip_agents.agent.hitl.manager import ApprovalManager # noqa: PLC0415
437
+ from glaip_sdk.hitl import LocalPromptHandler # noqa: PLC0415
438
+
439
+ local_agent.hitl_manager = ApprovalManager(
440
+ prompt_handler=LocalPromptHandler(pause_resume_callback=pause_resume_callback)
441
+ )
442
+ # Store callback reference for setting renderer later
443
+ if pause_resume_callback:
444
+ local_agent._pause_resume_callback = pause_resume_callback
445
+ logger.debug("HITL manager injected for agent '%s' (hitl_enabled=True)", agent_name)
446
+ except ImportError as e:
447
+ # Missing dependencies - fail fast
448
+ raise ImportError("Local HITL requires aip_agents. Install with: pip install 'glaip-sdk[local]'") from e
449
+ except Exception as e:
450
+ # Other errors during HITL setup - fail fast
451
+ raise RuntimeError(f"Failed to initialize HITL manager for agent '{agent_name}'") from e
452
+ else:
453
+ logger.debug("HITL manager not injected for agent '%s' (hitl_enabled=False)", agent_name)
454
+
455
+ def _build_sub_agents(
456
+ self,
457
+ sub_agents: list[Any] | None,
458
+ runtime_config: dict[str, Any] | None,
459
+ shared_tool_output_manager: Any | None = None,
460
+ ) -> list[Any]:
461
+ """Build sub-agent instances recursively.
462
+
463
+ Args:
464
+ sub_agents: List of sub-agent definitions.
465
+ runtime_config: Runtime config to pass to sub-agents.
466
+ shared_tool_output_manager: Optional ToolOutputManager to reuse across
467
+ agents with tool_output_sharing enabled.
468
+
469
+ Returns:
470
+ List of built sub-agent instances.
471
+
472
+ Raises:
473
+ ValueError: If sub-agent is platform-only.
474
+ """
475
+ if not sub_agents:
476
+ return []
477
+
478
+ sub_agent_instances = []
479
+ for sub_agent in sub_agents:
480
+ self._validate_sub_agent_for_local_mode(sub_agent)
481
+ sub_agent_instances.append(
482
+ self.build_langgraph_agent(
483
+ sub_agent,
484
+ runtime_config,
485
+ shared_tool_output_manager=shared_tool_output_manager,
486
+ )
487
+ )
488
+ return sub_agent_instances
489
+
490
+ def _add_mcp_servers(
491
+ self,
492
+ local_agent: Any,
493
+ agent: Agent,
494
+ merged_mcp_configs: dict[str, Any],
495
+ ) -> None:
496
+ """Add MCP servers to a built agent.
497
+
498
+ Args:
499
+ local_agent: The LangGraphReactAgent to add MCPs to.
500
+ agent: The glaip_sdk Agent with MCP definitions.
501
+ merged_mcp_configs: Merged mcp_configs (agent definition + runtime).
502
+ """
503
+ if not agent.mcps:
504
+ return
505
+
506
+ from glaip_sdk.runner.mcp_adapter import LangChainMCPAdapter # noqa: PLC0415
507
+
508
+ mcp_adapter = LangChainMCPAdapter()
509
+ base_mcp_configs = mcp_adapter.adapt_mcps(agent.mcps)
510
+
511
+ # Apply merged mcp_configs overrides (agent definition + runtime)
512
+ if merged_mcp_configs:
513
+ base_mcp_configs = self._apply_runtime_mcp_configs(base_mcp_configs, merged_mcp_configs)
514
+
515
+ if base_mcp_configs:
516
+ local_agent.add_mcp_server(base_mcp_configs)
517
+ logger.debug(
518
+ "Registered %d MCP server(s) for agent '%s'",
519
+ len(base_mcp_configs),
520
+ agent.name,
521
+ )
522
+
523
+ def _normalize_runtime_config(
524
+ self,
525
+ runtime_config: dict[str, Any] | None,
526
+ agent: Agent,
527
+ ) -> dict[str, Any]:
528
+ """Normalize runtime_config for local execution.
529
+
530
+ Merges global and agent-specific configs with proper priority.
531
+ Keys are resolved from instances/classes to string names.
532
+
533
+ Args:
534
+ runtime_config: Raw runtime config from user.
535
+ agent: The agent being built (for resolving agent-specific overrides).
536
+
537
+ Returns:
538
+ Normalized config with string keys and merged priorities.
539
+ """
540
+ from glaip_sdk.utils.runtime_config import ( # noqa: PLC0415
541
+ merge_configs,
542
+ normalize_local_config_keys,
543
+ )
544
+
545
+ if not runtime_config:
546
+ return {}
547
+
548
+ # 1. Extract global configs and normalize keys
549
+ global_tool_configs = normalize_local_config_keys(runtime_config.get("tool_configs", {}))
550
+ global_mcp_configs = normalize_local_config_keys(runtime_config.get("mcp_configs", {}))
551
+ global_agent_config = runtime_config.get("agent_config", {})
552
+
553
+ # 2. Extract agent-specific overrides (highest priority)
554
+ agent_specific = self._get_agent_specific_config(runtime_config, agent)
555
+ agent_tool_configs = normalize_local_config_keys(agent_specific.get("tool_configs", {}))
556
+ agent_mcp_configs = normalize_local_config_keys(agent_specific.get("mcp_configs", {}))
557
+ agent_config_override = agent_specific.get("agent_config", {})
558
+
559
+ # 3. Merge with priority: global < agent-specific
560
+ merged_result = {
561
+ "tool_configs": merge_configs(global_tool_configs, agent_tool_configs),
562
+ "mcp_configs": merge_configs(global_mcp_configs, agent_mcp_configs),
563
+ "agent_config": merge_configs(global_agent_config, agent_config_override),
564
+ }
565
+ return merged_result
566
+
567
+ def _get_agent_specific_config(
568
+ self,
569
+ runtime_config: dict[str, Any],
570
+ agent: Agent,
571
+ ) -> dict[str, Any]:
572
+ """Extract agent-specific config from runtime_config.
573
+
574
+ Args:
575
+ runtime_config: Runtime config that may contain agent-specific overrides.
576
+ agent: The agent to find config for.
577
+
578
+ Returns:
579
+ Agent-specific config dict, or empty dict if not found.
580
+ """
581
+ from glaip_sdk.utils.resource_refs import is_uuid # noqa: PLC0415
582
+ from glaip_sdk.utils.runtime_config import get_name_from_key # noqa: PLC0415
583
+
584
+ # Reserved keys at the top level
585
+ reserved_keys = {"tool_configs", "mcp_configs", "agent_config"}
586
+
587
+ # Try finding agent by instance, class, or name
588
+ for key, value in runtime_config.items():
589
+ if key in reserved_keys:
590
+ continue # Skip global configs
591
+
592
+ if isinstance(key, str) and is_uuid(key):
593
+ logger.warning(
594
+ "UUID agent override key '%s' is not supported in local mode; skipping. "
595
+ "Use agent name string or Agent instance as the key instead.",
596
+ key,
597
+ )
598
+ continue
599
+
600
+ # Check if this key matches the agent
601
+ try:
602
+ key_name = get_name_from_key(key)
603
+ except ValueError:
604
+ continue # Skip invalid keys
605
+
606
+ if key_name and key_name == agent.name:
607
+ return value if isinstance(value, dict) else {}
608
+
609
+ return {}
610
+
611
+ def _merge_tool_configs(
612
+ self,
613
+ agent: Agent,
614
+ normalized_config: dict[str, Any],
615
+ ) -> dict[str, Any]:
616
+ """Merge agent.tool_configs with runtime tool_configs.
617
+
618
+ Priority (lowest to highest):
619
+ 1. Agent definition (agent.tool_configs)
620
+ 2. Runtime config (normalized_config["tool_configs"])
621
+
622
+ Args:
623
+ agent: The agent with optional tool_configs property.
624
+ normalized_config: Normalized runtime config.
625
+
626
+ Returns:
627
+ Merged tool_configs dict.
628
+ """
629
+ from glaip_sdk.utils.runtime_config import ( # noqa: PLC0415
630
+ merge_configs,
631
+ normalize_local_config_keys,
632
+ )
633
+
634
+ # Get agent's tool_configs if defined
635
+ agent_tool_configs = {}
636
+ if hasattr(agent, "tool_configs") and agent.tool_configs:
637
+ agent_tool_configs = normalize_local_config_keys(agent.tool_configs)
638
+
639
+ # Get runtime tool_configs
640
+ runtime_tool_configs = normalized_config.get("tool_configs", {})
641
+
642
+ # Merge: agent definition < runtime config
643
+ return merge_configs(agent_tool_configs, runtime_tool_configs)
644
+
645
+ def _merge_mcp_configs(
646
+ self,
647
+ agent: Agent,
648
+ normalized_config: dict[str, Any],
649
+ ) -> dict[str, Any]:
650
+ """Merge agent.mcp_configs with runtime mcp_configs.
651
+
652
+ Priority (lowest to highest):
653
+ 1. Agent definition (agent.mcp_configs)
654
+ 2. Runtime config (normalized_config["mcp_configs"])
655
+
656
+ Args:
657
+ agent: The agent with optional mcp_configs property.
658
+ normalized_config: Normalized runtime config.
659
+
660
+ Returns:
661
+ Merged mcp_configs dict.
662
+ """
663
+ from glaip_sdk.utils.runtime_config import ( # noqa: PLC0415
664
+ merge_configs,
665
+ normalize_local_config_keys,
666
+ )
667
+
668
+ # Get agent's mcp_configs if defined
669
+ agent_mcp_configs = {}
670
+ if hasattr(agent, "mcp_configs") and agent.mcp_configs:
671
+ agent_mcp_configs = normalize_local_config_keys(agent.mcp_configs)
672
+
673
+ # Get runtime mcp_configs
674
+ runtime_mcp_configs = normalized_config.get("mcp_configs", {})
675
+
676
+ # Merge: agent definition < runtime config
677
+ return merge_configs(agent_mcp_configs, runtime_mcp_configs)
678
+
679
+ def _merge_agent_config(
680
+ self,
681
+ agent: Agent,
682
+ normalized_config: dict[str, Any],
683
+ ) -> dict[str, Any]:
684
+ """Merge agent.agent_config with runtime agent_config.
685
+
686
+ Priority (lowest to highest):
687
+ 1. Agent definition (agent.agent_config)
688
+ 2. Runtime config (normalized_config["agent_config"])
689
+
690
+ Args:
691
+ agent: The agent with optional agent_config property.
692
+ normalized_config: Normalized runtime config.
693
+
694
+ Returns:
695
+ Merged agent_config dict.
696
+ """
697
+ from glaip_sdk.utils.runtime_config import merge_configs # noqa: PLC0415
698
+
699
+ # Get agent's agent_config if defined
700
+ agent_agent_config = {}
701
+ if hasattr(agent, "agent_config") and agent.agent_config:
702
+ agent_agent_config = agent.agent_config
703
+
704
+ # Get runtime agent_config
705
+ runtime_agent_config = normalized_config.get("agent_config", {})
706
+
707
+ # Merge: agent definition < runtime config
708
+ return merge_configs(agent_agent_config, runtime_agent_config)
709
+
710
+ def _apply_agent_config(
711
+ self,
712
+ agent_config: dict[str, Any],
713
+ ) -> tuple[dict[str, Any], dict[str, Any]]:
714
+ """Extract and separate agent_config into direct params and kwargs.
715
+
716
+ Separates agent_config into parameters that go directly to LangGraphReactAgent
717
+ constructor vs those that go through **kwargs.
718
+
719
+ Args:
720
+ agent_config: Runtime agent configuration dict.
721
+
722
+ Returns:
723
+ Tuple of (direct_params, kwargs_params):
724
+ - direct_params: Parameters passed directly to LangGraphReactAgent.__init__()
725
+ - kwargs_params: Parameters passed via **kwargs to BaseAgent
726
+ """
727
+ direct_params = {}
728
+ kwargs_params = {}
729
+
730
+ # Direct constructor parameters
731
+ if "planning" in agent_config:
732
+ direct_params["planning"] = agent_config["planning"]
733
+
734
+ if "enable_a2a_token_streaming" in agent_config:
735
+ direct_params["enable_a2a_token_streaming"] = agent_config["enable_a2a_token_streaming"]
736
+
737
+ # Kwargs parameters (passed through **kwargs to BaseAgent)
738
+ if "enable_pii" in agent_config:
739
+ kwargs_params["enable_pii"] = agent_config["enable_pii"]
740
+
741
+ if "memory" in agent_config:
742
+ # Map "memory" to "memory_backend" for aip-agents compatibility
743
+ kwargs_params["memory_backend"] = agent_config["memory"]
744
+
745
+ # Additional memory-related settings
746
+ memory_settings = ["agent_id", "memory_namespace", "save_interaction_to_memory"]
747
+ for key in memory_settings:
748
+ if key in agent_config:
749
+ kwargs_params[key] = agent_config[key]
750
+
751
+ return direct_params, kwargs_params
752
+
753
+ def _apply_runtime_mcp_configs(
754
+ self,
755
+ base_configs: dict[str, Any],
756
+ runtime_overrides: dict[str, Any],
757
+ ) -> dict[str, Any]:
758
+ """Apply runtime mcp_configs overrides to base MCP configurations.
759
+
760
+ Merges runtime overrides into the base configs, handling authentication
761
+ conversion to headers using MCPConfigBuilder.
762
+
763
+ Args:
764
+ base_configs: Base MCP configs from adapter (server_name -> config).
765
+ runtime_overrides: Runtime mcp_configs overrides (server_name -> config).
766
+
767
+ Returns:
768
+ Merged MCP configs with authentication converted to headers.
769
+ """
770
+ return {
771
+ server_name: self._merge_single_mcp_config(server_name, base_config, runtime_overrides.get(server_name))
772
+ for server_name, base_config in base_configs.items()
773
+ }
774
+
775
+ def _merge_single_mcp_config(
776
+ self,
777
+ server_name: str,
778
+ base_config: dict[str, Any],
779
+ override: dict[str, Any] | None,
780
+ ) -> dict[str, Any]:
781
+ """Merge a single MCP config with runtime override.
782
+
783
+ Args:
784
+ server_name: Name of the MCP server.
785
+ base_config: Base config from adapter.
786
+ override: Optional runtime override config.
787
+
788
+ Returns:
789
+ Merged config dict.
790
+ """
791
+ merged = base_config.copy()
792
+
793
+ if not override:
794
+ return merged
795
+
796
+ from glaip_sdk.runner.mcp_adapter.mcp_config_builder import ( # noqa: PLC0415
797
+ MCPConfigBuilder,
798
+ )
799
+
800
+ # Handle authentication override
801
+ if "authentication" in override:
802
+ headers = MCPConfigBuilder.build_headers_from_auth(override["authentication"])
803
+ if headers:
804
+ merged["headers"] = headers
805
+ logger.debug("Applied runtime authentication headers for MCP '%s'", server_name)
806
+
807
+ # Merge other config keys (excluding authentication since we converted it)
808
+ for key, value in override.items():
809
+ if key != "authentication":
810
+ merged[key] = value
811
+
812
+ return merged
813
+
814
+ def _validate_sub_agent_for_local_mode(self, sub_agent: Any) -> None:
815
+ """Validate that a sub-agent reference is supported for local execution.
816
+
817
+ Args:
818
+ sub_agent: The sub-agent reference to validate.
819
+
820
+ Raises:
821
+ ValueError: If the sub-agent is not supported in local mode.
822
+ """
823
+ # String references are allowed by SDK API but not for local mode
824
+ if isinstance(sub_agent, str):
825
+ raise ValueError(
826
+ f"Sub-agent '{sub_agent}' is a string reference and cannot be used in local mode. "
827
+ "String sub-agent references are only supported for server execution. "
828
+ "For local mode, define the sub-agent with Agent(name=..., instruction=...)."
829
+ )
830
+
831
+ # Validate sub-agent is not a class
832
+ if inspect.isclass(sub_agent):
833
+ raise ValueError(
834
+ f"Sub-agent '{sub_agent.__name__}' is a class, not an instance. "
835
+ "Local mode requires Agent INSTANCES. "
836
+ "Did you forget to instantiate it? e.g., Agent(...), not Agent"
837
+ )
838
+
839
+ # Validate sub-agent is an Agent-like object (has required attributes)
840
+ if not hasattr(sub_agent, "name") or not hasattr(sub_agent, "instruction"):
841
+ raise ValueError(
842
+ f"Sub-agent {type(sub_agent).__name__} is not supported in local mode. "
843
+ "Local mode requires Agent instances with 'name' and 'instruction' attributes. "
844
+ "Define the sub-agent with Agent(name=..., instruction=...)."
845
+ )
846
+
847
+ # Validate sub-agent is not platform-only (from_id, from_native)
848
+ if getattr(sub_agent, "_lookup_only", False):
849
+ agent_name = getattr(sub_agent, "name", "<unknown>")
850
+ raise ValueError(
851
+ f"Sub-agent '{agent_name}' is not supported in local mode. "
852
+ "Platform agents (from_id, from_native) cannot be used as "
853
+ "sub-agents in local execution. "
854
+ "Define the sub-agent locally with Agent(name=..., instruction=...) instead."
855
+ )
856
+
857
+ def _log_event(self, event: dict[str, Any]) -> None:
858
+ """Log an A2AEvent for verbose debug output.
859
+
860
+ Args:
861
+ event: The A2AEvent dictionary to log.
862
+ """
863
+ event_type = event.get("event_type", "unknown")
864
+ content = event.get("content", "")
865
+ is_final = event.get("is_final", False)
866
+
867
+ # Truncate long content for readability
868
+ content_str = str(content) if content else ""
869
+ content_preview = content_str[:100] + "..." if len(content_str) > 100 else content_str
870
+
871
+ final_marker = "(final)" if is_final else ""
872
+ logger.info("[%s] %s %s", event_type, final_marker, content_preview)