execweave 1.0.0__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 (234) hide show
  1. execweave/__init__.py +3 -0
  2. execweave/__main__.py +5 -0
  3. execweave/_conversation_records_core.py +902 -0
  4. execweave/_dashboard_shell_base.py +148 -0
  5. execweave/_http_proxy_base.py +565 -0
  6. execweave/_http_proxy_bounded.py +560 -0
  7. execweave/_http_proxy_stage.py +509 -0
  8. execweave/acceptance_output.py +19 -0
  9. execweave/agent_bootstrap.py +395 -0
  10. execweave/agent_topology.py +313 -0
  11. execweave/agent_trace.py +1162 -0
  12. execweave/agy_preview_sanitize.py +102 -0
  13. execweave/analysis.py +427 -0
  14. execweave/anthropic.py +228 -0
  15. execweave/anthropic_cli.py +171 -0
  16. execweave/anthropic_full_fidelity.py +385 -0
  17. execweave/antigravity_adapter.py +112 -0
  18. execweave/antigravity_adapter_base.py +479 -0
  19. execweave/antigravity_full_fidelity.py +656 -0
  20. execweave/antigravity_full_fidelity_base.py +172 -0
  21. execweave/antigravity_full_fidelity_collaboration_base.py +451 -0
  22. execweave/antigravity_hook_cli.py +209 -0
  23. execweave/antigravity_record.py +96 -0
  24. execweave/antigravity_subagent_linkage.py +449 -0
  25. execweave/antigravity_trace_capability.py +39 -0
  26. execweave/auto_specialized.py +547 -0
  27. execweave/backends.py +102 -0
  28. execweave/benchmark.py +80 -0
  29. execweave/claude_adapter.py +517 -0
  30. execweave/claude_child_transcript.py +314 -0
  31. execweave/claude_delegation.py +136 -0
  32. execweave/claude_full_fidelity.py +396 -0
  33. execweave/claude_hook_cli.py +209 -0
  34. execweave/claude_hook_contract.py +943 -0
  35. execweave/claude_model_observer.py +353 -0
  36. execweave/claude_record.py +106 -0
  37. execweave/cli.py +629 -0
  38. execweave/codex_adapter.py +455 -0
  39. execweave/codex_conversation.py +621 -0
  40. execweave/codex_full_fidelity.py +287 -0
  41. execweave/codex_hook_cli.py +301 -0
  42. execweave/codex_hook_entry.py +207 -0
  43. execweave/codex_hook_lifecycle.py +363 -0
  44. execweave/codex_message_diagnostics.py +322 -0
  45. execweave/codex_message_transport_diagnostics.py +399 -0
  46. execweave/codex_record.py +199 -0
  47. execweave/codex_rollout_structures.py +402 -0
  48. execweave/codex_rollout_trace.py +56 -0
  49. execweave/codex_rollout_trace_base.py +1509 -0
  50. execweave/collector.py +768 -0
  51. execweave/command.py +157 -0
  52. execweave/command_privacy.py +20 -0
  53. execweave/content_evidence.py +101 -0
  54. execweave/content_integrity.py +289 -0
  55. execweave/content_store.py +273 -0
  56. execweave/controlled_checks.py +561 -0
  57. execweave/conversation_archive.py +338 -0
  58. execweave/conversation_message_identity.py +264 -0
  59. execweave/conversation_preview.py +66 -0
  60. execweave/conversation_preview_antigravity.py +32 -0
  61. execweave/conversation_preview_claude.py +31 -0
  62. execweave/conversation_preview_codex.py +107 -0
  63. execweave/conversation_preview_common.py +180 -0
  64. execweave/conversation_preview_generic.py +188 -0
  65. execweave/conversation_preview_lines.py +133 -0
  66. execweave/conversation_preview_transcript.py +121 -0
  67. execweave/conversation_records.py +349 -0
  68. execweave/conversation_records_antigravity.py +370 -0
  69. execweave/conversation_records_codex.py +83 -0
  70. execweave/conversation_records_common.py +17 -0
  71. execweave/conversation_records_ollama.py +39 -0
  72. execweave/correlation.py +818 -0
  73. execweave/cursor_adapter.py +349 -0
  74. execweave/cursor_delegation.py +87 -0
  75. execweave/cursor_delegation_base.py +220 -0
  76. execweave/cursor_full_fidelity.py +489 -0
  77. execweave/cursor_hook_cli.py +195 -0
  78. execweave/cursor_hook_contract.py +439 -0
  79. execweave/cursor_lifecycle.py +159 -0
  80. execweave/cursor_record.py +96 -0
  81. execweave/dashboard_shell.py +283 -0
  82. execweave/delivery_status.py +94 -0
  83. execweave/entry.py +98 -0
  84. execweave/evidence_availability.py +113 -0
  85. execweave/evidence_grade.py +166 -0
  86. execweave/fidelity.py +304 -0
  87. execweave/filesystem.py +327 -0
  88. execweave/finalization.py +92 -0
  89. execweave/focus.py +118 -0
  90. execweave/framework_adapters/__init__.py +34 -0
  91. execweave/framework_adapters/autogen.py +398 -0
  92. execweave/framework_adapters/base.py +580 -0
  93. execweave/framework_adapters/camel.py +270 -0
  94. execweave/framework_adapters/camel_channel.py +71 -0
  95. execweave/framework_adapters/metagpt.py +315 -0
  96. execweave/framework_adapters/metagpt_ollama_compat.py +54 -0
  97. execweave/framework_adapters/metagpt_recording.py +342 -0
  98. execweave/framework_adapters/registry.py +90 -0
  99. execweave/graph.py +590 -0
  100. execweave/graph_ops.py +472 -0
  101. execweave/hook_command.py +32 -0
  102. execweave/hook_delivery.py +32 -0
  103. execweave/hook_input.py +16 -0
  104. execweave/http_proxy.py +187 -0
  105. execweave/http_proxy_cli.py +84 -0
  106. execweave/inference_gateway.py +476 -0
  107. execweave/inference_gateway_cli.py +211 -0
  108. execweave/inference_gateway_full_fidelity.py +613 -0
  109. execweave/inference_identity.py +76 -0
  110. execweave/inference_identity_cli.py +60 -0
  111. execweave/integrity.py +235 -0
  112. execweave/integrity_cli.py +55 -0
  113. execweave/investigation_index.py +445 -0
  114. execweave/litellm_callback.py +211 -0
  115. execweave/litellm_callback_cli.py +42 -0
  116. execweave/live.py +445 -0
  117. execweave/live_core.py +972 -0
  118. execweave/live_view.py +109 -0
  119. execweave/live_view_extra_style.py +11 -0
  120. execweave/live_view_markup.py +29 -0
  121. execweave/live_view_process_layout.py +650 -0
  122. execweave/live_view_readability.py +502 -0
  123. execweave/live_view_script_a.py +59 -0
  124. execweave/live_view_script_b.py +97 -0
  125. execweave/live_view_script_c.py +59 -0
  126. execweave/live_view_script_d.py +40 -0
  127. execweave/live_view_style.py +34 -0
  128. execweave/model_runtime.py +560 -0
  129. execweave/model_runtime_cli.py +265 -0
  130. execweave/model_runtime_full_fidelity.py +519 -0
  131. execweave/observation.py +53 -0
  132. execweave/observation_demo.py +69 -0
  133. execweave/openai_agents.py +267 -0
  134. execweave/openai_agents_sdk.py +453 -0
  135. execweave/openai_compatible.py +239 -0
  136. execweave/openai_compatible_cli.py +189 -0
  137. execweave/openai_compatible_full_fidelity.py +438 -0
  138. execweave/opencode_adapter.py +325 -0
  139. execweave/opencode_event_contract.py +734 -0
  140. execweave/opencode_full_fidelity.py +198 -0
  141. execweave/opencode_hook_cli.py +119 -0
  142. execweave/opencode_plugin_cli.py +150 -0
  143. execweave/opencode_record.py +96 -0
  144. execweave/opencode_task_linkage.py +225 -0
  145. execweave/overhead_benchmark.py +440 -0
  146. execweave/privacy.py +84 -0
  147. execweave/private_io.py +465 -0
  148. execweave/provider_capability.py +578 -0
  149. execweave/provider_lifecycle.py +282 -0
  150. execweave/provider_record.py +290 -0
  151. execweave/reader_identity.py +13 -0
  152. execweave/redacted_archive.py +906 -0
  153. execweave/risk.py +106 -0
  154. execweave/rule_pack.py +359 -0
  155. execweave/rule_pack_cli.py +57 -0
  156. execweave/run_assessment.py +200 -0
  157. execweave/runtime_endpoint_availability.py +44 -0
  158. execweave/scalability_benchmark.py +195 -0
  159. execweave/schema.py +62 -0
  160. execweave/scope.py +85 -0
  161. execweave/semantic.py +453 -0
  162. execweave/session_summary.py +159 -0
  163. execweave/sink.py +71 -0
  164. execweave/strace_backend.py +927 -0
  165. execweave/stream_assembly.py +363 -0
  166. execweave/task_artifacts.py +192 -0
  167. execweave/task_validation.py +317 -0
  168. execweave/theme.py +40 -0
  169. execweave/top.py +599 -0
  170. execweave/top_cli.py +150 -0
  171. execweave/validate.py +196 -0
  172. execweave/vendor/dagre.min.js +815 -0
  173. execweave/view_cli.py +49 -0
  174. execweave/viewer.py +474 -0
  175. execweave/viewer_agent_panel.py +630 -0
  176. execweave/viewer_agent_panel_antigravity.py +31 -0
  177. execweave/viewer_agent_panel_claude.py +9 -0
  178. execweave/viewer_agent_panel_codex.py +50 -0
  179. execweave/viewer_agent_panel_cursor.py +9 -0
  180. execweave/viewer_agent_panel_default.py +79 -0
  181. execweave/viewer_agent_panel_ollama.py +20 -0
  182. execweave/viewer_agent_panel_opencode.py +9 -0
  183. execweave/viewer_agent_panel_registry.py +20 -0
  184. execweave/viewer_archive_verifier.py +178 -0
  185. execweave/viewer_background_files.py +86 -0
  186. execweave/viewer_content_browser.py +307 -0
  187. execweave/viewer_content_health.py +208 -0
  188. execweave/viewer_content_inspector.py +309 -0
  189. execweave/viewer_controlled_checks.py +258 -0
  190. execweave/viewer_conversation_sync.py +115 -0
  191. execweave/viewer_dashboard_clean.py +405 -0
  192. execweave/viewer_dashboard_focus.py +127 -0
  193. execweave/viewer_dashboard_hardening.py +264 -0
  194. execweave/viewer_dashboard_hardening_v2.py +62 -0
  195. execweave/viewer_dashboard_projection.py +261 -0
  196. execweave/viewer_delivery_status.py +155 -0
  197. execweave/viewer_edge_decross.py +117 -0
  198. execweave/viewer_execution_flow.py +611 -0
  199. execweave/viewer_execution_flow_provider_normalization.py +107 -0
  200. execweave/viewer_execution_flow_safety.py +349 -0
  201. execweave/viewer_external_endpoints.py +307 -0
  202. execweave/viewer_flow_canvas.py +1140 -0
  203. execweave/viewer_flow_layout.py +922 -0
  204. execweave/viewer_fold_state.py +31 -0
  205. execweave/viewer_framework_flow.py +68 -0
  206. execweave/viewer_framework_model_output.py +133 -0
  207. execweave/viewer_gif.py +278 -0
  208. execweave/viewer_history_browser.py +225 -0
  209. execweave/viewer_investigation.py +268 -0
  210. execweave/viewer_layout_geometry.py +192 -0
  211. execweave/viewer_layout_v2.py +429 -0
  212. execweave/viewer_layout_v2_detached.py +25 -0
  213. execweave/viewer_limits.py +93 -0
  214. execweave/viewer_live_layout.py +61 -0
  215. execweave/viewer_message_handoffs.py +114 -0
  216. execweave/viewer_projection.py +488 -0
  217. execweave/viewer_projection_base.py +522 -0
  218. execweave/viewer_projection_bridges.py +214 -0
  219. execweave/viewer_recorded_sources.py +146 -0
  220. execweave/viewer_run_assessment.py +274 -0
  221. execweave/viewer_run_guide.py +175 -0
  222. execweave/viewer_runtime_evidence.py +258 -0
  223. execweave/viewer_semantic_projection.py +641 -0
  224. execweave/viewer_session_flow.py +491 -0
  225. execweave/viewer_structure_share.py +132 -0
  226. execweave/viewer_task_validation.py +241 -0
  227. execweave/viewer_tool_mirror_identity.py +75 -0
  228. execweave/viewer_workflow_mode.py +127 -0
  229. execweave/workflow.py +183 -0
  230. execweave-1.0.0.dist-info/METADATA +462 -0
  231. execweave-1.0.0.dist-info/RECORD +234 -0
  232. execweave-1.0.0.dist-info/WHEEL +4 -0
  233. execweave-1.0.0.dist-info/entry_points.txt +30 -0
  234. execweave-1.0.0.dist-info/licenses/LICENSE +16 -0
@@ -0,0 +1,398 @@
1
+ """AutoGen adapter over authoritative message/runtime/model callbacks."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import importlib.metadata
6
+ import json
7
+ from typing import Any
8
+
9
+ from .base import (
10
+ AdapterCapabilities,
11
+ AdapterContext,
12
+ AgentRecord,
13
+ EntityRef,
14
+ FrameworkAdapter,
15
+ FrameworkCompatibility,
16
+ MessageRecord,
17
+ ModelCallRecord,
18
+ TaskRecord,
19
+ ToolCallRecord,
20
+ )
21
+
22
+
23
+ class AutoGenAdapter(FrameworkAdapter):
24
+ framework_name = "autogen"
25
+ capabilities = AdapterCapabilities(
26
+ events=(
27
+ "AGENT_CREATED",
28
+ "AGENT_STARTED",
29
+ "AGENT_STOPPED",
30
+ "TASK_CREATED",
31
+ "TASK_ASSIGNED",
32
+ "TASK_STARTED",
33
+ "TASK_UPDATED",
34
+ "TASK_COMPLETED",
35
+ "TASK_FAILED",
36
+ "TASK_CONTENT_RECORDED",
37
+ "MESSAGE_SENT",
38
+ "MESSAGE_RECEIVED",
39
+ "MODEL_REQUEST",
40
+ "MODEL_RESPONSE",
41
+ "MODEL_FAILURE",
42
+ "TOOL_CALL",
43
+ "TOOL_RESULT",
44
+ "TOOL_FAILURE",
45
+ ),
46
+ content_modes=("metadata_only", "content_ref_only", "prompt_only", "prompt_and_response"),
47
+ authoritative_surfaces=(
48
+ "autogen_core.AgentId",
49
+ "autogen_core.RoutedAgent",
50
+ "autogen_agentchat.messages",
51
+ "autogen_core.logging.LLMCallEvent",
52
+ ),
53
+ known_limitations=(
54
+ "AutoGen APIs vary between autogen-core and autogen-agentchat; callers must pass the authoritative event payload.",
55
+ ),
56
+ )
57
+
58
+ def __init__(self, context: AdapterContext) -> None:
59
+ super().__init__(context)
60
+ self._agents: dict[str, EntityRef] = {}
61
+ self._event_counter = 0
62
+ self._model_call_counter = 0
63
+
64
+ @classmethod
65
+ def compatibility(cls) -> FrameworkCompatibility:
66
+ version = None
67
+ for distribution in ("autogen-agentchat", "autogen-core", "pyautogen"):
68
+ try:
69
+ version = importlib.metadata.version(distribution)
70
+ break
71
+ except importlib.metadata.PackageNotFoundError:
72
+ continue
73
+ status = "verified" if version == "0.7.5" else ("warn" if version else "unknown")
74
+ return FrameworkCompatibility(
75
+ framework=cls.framework_name,
76
+ detected_version=version,
77
+ tested_versions=("0.7.5", "0.4.x"),
78
+ compatibility_status=status,
79
+ capabilities=cls.capabilities,
80
+ known_limitations=cls.capabilities.known_limitations,
81
+ )
82
+
83
+ def observe_agent(
84
+ self,
85
+ native_id: str | int,
86
+ *,
87
+ name: str | None = None,
88
+ role: str | None = None,
89
+ process: Any | None = None,
90
+ **attributes: Any,
91
+ ) -> EntityRef:
92
+ agent = self.agent(native_id, name=name, provider="autogen", role=role, **attributes)
93
+ self._agents[str(native_id)] = agent
94
+ self.context.record_agent(AgentRecord(agent, role=role, process=process, attributes=attributes))
95
+ return agent
96
+
97
+ def observe_task(
98
+ self,
99
+ task_id: str | int,
100
+ *,
101
+ owner: EntityRef | None = None,
102
+ name: str | None = None,
103
+ content: str | None = None,
104
+ content_kind: str = "task_prompt",
105
+ status: str = "created",
106
+ **attributes: Any,
107
+ ) -> EntityRef:
108
+ """Record an authoritative AutoGen task and its visible task prompt."""
109
+ entity_attributes = dict(attributes)
110
+ if content is not None and self.context.capture_policy.mode in {
111
+ "prompt_only",
112
+ "prompt_and_response",
113
+ }:
114
+ entity_attributes.setdefault("task_prompt", content)
115
+ task = self.task(task_id, name=name, provider="autogen", **entity_attributes)
116
+ event = {
117
+ "created": "TASK_CREATED",
118
+ "started": "TASK_STARTED",
119
+ "updated": "TASK_UPDATED",
120
+ "completed": "TASK_COMPLETED",
121
+ "failed": "TASK_FAILED",
122
+ }.get(status)
123
+ if event is None:
124
+ raise ValueError(f"unsupported AutoGen task status: {status}")
125
+ self.context.record_task(
126
+ TaskRecord(
127
+ task,
128
+ owner=owner,
129
+ content=content,
130
+ content_kind=content_kind,
131
+ attributes=attributes,
132
+ ),
133
+ event_type=event,
134
+ )
135
+ return task
136
+
137
+ def observe_message(
138
+ self,
139
+ message_id: str | int,
140
+ *,
141
+ source: EntityRef | None,
142
+ target: EntityRef | None,
143
+ content: str | None = None,
144
+ role: str | None = None,
145
+ task: EntityRef | None = None,
146
+ received: bool = False,
147
+ **attributes: Any,
148
+ ) -> EntityRef:
149
+ message = self.entity("message", message_id, name="AutoGen message", attributes={"provider": "autogen"})
150
+ self.context.record_message(
151
+ MessageRecord(
152
+ message,
153
+ source,
154
+ target,
155
+ role=role,
156
+ task=task,
157
+ content=content,
158
+ direction="received" if received else "sent",
159
+ attributes=attributes,
160
+ )
161
+ )
162
+ return message
163
+
164
+ def observe_model_call(
165
+ self,
166
+ call_id: str | int,
167
+ *,
168
+ agent: EntityRef | None,
169
+ model_id: str | int,
170
+ request: Any | None = None,
171
+ response: Any | None = None,
172
+ status: str = "request",
173
+ **attributes: Any,
174
+ ) -> EntityRef:
175
+ model = self.model(model_id, provider="autogen", **attributes)
176
+ call = self.entity("model_call", call_id, name="AutoGen model call", attributes={"provider": "autogen"})
177
+ self.context.record_model_call(
178
+ ModelCallRecord(
179
+ call,
180
+ agent,
181
+ model,
182
+ request=request,
183
+ response=response,
184
+ status=status,
185
+ content_kind="model_request" if status == "request" else "model_response",
186
+ attributes=attributes,
187
+ )
188
+ )
189
+ return call
190
+
191
+ def observe_tool_call(
192
+ self,
193
+ call_id: str | int,
194
+ *,
195
+ agent: EntityRef | None,
196
+ tool_id: str | int,
197
+ arguments: Any | None = None,
198
+ result: Any | None = None,
199
+ status: str = "call",
200
+ **attributes: Any,
201
+ ) -> EntityRef:
202
+ tool = self.tool(tool_id, provider="autogen", **attributes)
203
+ call = self.entity("tool_call", call_id, name="AutoGen tool call", attributes={"provider": "autogen"})
204
+ self.context.record_tool_call(
205
+ ToolCallRecord(
206
+ call,
207
+ agent,
208
+ tool,
209
+ arguments=arguments,
210
+ result=result,
211
+ status=status,
212
+ attributes=attributes,
213
+ )
214
+ )
215
+ return call
216
+
217
+ def observe_agentchat_event(
218
+ self,
219
+ event: Any,
220
+ *,
221
+ source: EntityRef | None = None,
222
+ target: EntityRef | None = None,
223
+ task: EntityRef | None = None,
224
+ received: bool = False,
225
+ **attributes: Any,
226
+ ) -> EntityRef | list[EntityRef]:
227
+ """Observe one item yielded by ``Agent.run_stream`` or a team stream."""
228
+ self._event_counter += 1
229
+ event_name = type(event).__name__
230
+ event_id = getattr(event, "id", None) or f"event-{self._event_counter}"
231
+ source_name = getattr(event, "source", None)
232
+ if source is None and source_name is not None:
233
+ source = self._agents.get(str(source_name)) or self.observe_agent(
234
+ str(source_name), name=str(source_name)
235
+ )
236
+ target_name = getattr(event, "target", None) or getattr(event, "recipient", None)
237
+ if target is None and target_name is not None:
238
+ target = self._agents.get(str(target_name)) or self.observe_agent(
239
+ str(target_name), name=str(target_name)
240
+ )
241
+ content = getattr(event, "content", None)
242
+ if event_name == "ThoughtEvent":
243
+ return self.observe_message(
244
+ event_id,
245
+ source=source,
246
+ target=target,
247
+ content=None,
248
+ role="internal_reasoning",
249
+ task=task,
250
+ received=received,
251
+ event_type=event_name,
252
+ content_suppressed_by_policy=True,
253
+ **attributes,
254
+ )
255
+ if event_name == "ToolCallRequestEvent":
256
+ results = []
257
+ for call in content if isinstance(content, list) else []:
258
+ call_id = getattr(call, "id", None) or f"{event_id}-tool"
259
+ tool_name = getattr(call, "name", None) or "autogen-tool"
260
+ results.append(
261
+ self.observe_tool_call(
262
+ call_id,
263
+ agent=source,
264
+ tool_id=tool_name,
265
+ arguments=_jsonable(getattr(call, "arguments", None)),
266
+ status="call",
267
+ event_type=event_name,
268
+ **attributes,
269
+ )
270
+ )
271
+ return results
272
+ if event_name == "ToolCallExecutionEvent":
273
+ results = []
274
+ for result in content if isinstance(content, list) else []:
275
+ call_id = getattr(result, "call_id", None) or f"{event_id}-tool"
276
+ tool_name = getattr(result, "name", None) or "autogen-tool"
277
+ status = "failure" if bool(getattr(result, "is_error", False)) else "result"
278
+ results.append(
279
+ self.observe_tool_call(
280
+ call_id,
281
+ agent=source,
282
+ tool_id=tool_name,
283
+ result=_jsonable(getattr(result, "content", None)),
284
+ status=status,
285
+ event_type=event_name,
286
+ **attributes,
287
+ )
288
+ )
289
+ return results
290
+ return self.observe_message(
291
+ event_id,
292
+ source=source,
293
+ target=target,
294
+ content=_text(content),
295
+ role=event_name,
296
+ task=task,
297
+ received=received,
298
+ event_type=event_name,
299
+ metadata=_jsonable(getattr(event, "metadata", None)),
300
+ **attributes,
301
+ )
302
+
303
+ def observe_model_event(
304
+ self,
305
+ event: Any,
306
+ *,
307
+ agent: EntityRef | None = None,
308
+ model_id: str | int = "autogen-model",
309
+ **attributes: Any,
310
+ ) -> list[EntityRef]:
311
+ """Observe an ``autogen_core.logging`` LLMCall/stream event."""
312
+ payload = getattr(event, "kwargs", None)
313
+ if not isinstance(payload, dict):
314
+ payload = vars(event) if hasattr(event, "__dict__") else {}
315
+ agent_id = payload.get("agent_id")
316
+ if agent is None and agent_id:
317
+ agent = self._agents.get(str(agent_id)) or self.observe_agent(str(agent_id), name=str(agent_id))
318
+ self._model_call_counter += 1
319
+ call_id = payload.get("call_id") or f"llm-{self._model_call_counter}"
320
+ event_type = str(payload.get("type") or type(event).__name__)
321
+ merged = {"event_type": event_type, **attributes}
322
+ request = _jsonable(payload.get("messages"))
323
+ response = _jsonable(payload.get("response"))
324
+ observed: list[EntityRef] = []
325
+ if request is not None:
326
+ observed.append(
327
+ self.observe_model_call(
328
+ call_id,
329
+ agent=agent,
330
+ model_id=model_id,
331
+ request=request,
332
+ status="request",
333
+ **merged,
334
+ )
335
+ )
336
+ if response is not None:
337
+ observed.append(
338
+ self.observe_model_call(
339
+ call_id,
340
+ agent=agent,
341
+ model_id=model_id,
342
+ response=response,
343
+ status="response",
344
+ prompt_tokens=payload.get("prompt_tokens"),
345
+ completion_tokens=payload.get("completion_tokens"),
346
+ **merged,
347
+ )
348
+ )
349
+ return observed
350
+
351
+ def observe_tool_event(
352
+ self,
353
+ event: Any,
354
+ *,
355
+ agent: EntityRef | None = None,
356
+ **attributes: Any,
357
+ ) -> EntityRef:
358
+ """Observe an ``autogen_core.logging.ToolCallEvent``."""
359
+ payload = getattr(event, "kwargs", None)
360
+ if not isinstance(payload, dict):
361
+ payload = vars(event) if hasattr(event, "__dict__") else {}
362
+ agent_id = payload.get("agent_id")
363
+ if agent is None and agent_id:
364
+ agent = self._agents.get(str(agent_id)) or self.observe_agent(str(agent_id), name=str(agent_id))
365
+ return self.observe_tool_call(
366
+ payload.get("call_id") or f"tool-{self._event_counter + 1}",
367
+ agent=agent,
368
+ tool_id=payload.get("tool_name") or "autogen-tool",
369
+ arguments=_jsonable(payload.get("arguments")),
370
+ result=_jsonable(payload.get("result")),
371
+ status="result",
372
+ event_type=str(payload.get("type") or type(event).__name__),
373
+ **attributes,
374
+ )
375
+
376
+
377
+ def _jsonable(value: Any) -> Any:
378
+ if value is None or isinstance(value, (str, int, float, bool)):
379
+ return value
380
+ if isinstance(value, list):
381
+ return [_jsonable(item) for item in value]
382
+ if isinstance(value, dict):
383
+ return {str(key): _jsonable(child) for key, child in value.items()}
384
+ model_dump = getattr(value, "model_dump", None)
385
+ if callable(model_dump):
386
+ return _jsonable(model_dump())
387
+ to_dict = getattr(value, "dict", None)
388
+ if callable(to_dict):
389
+ return _jsonable(to_dict())
390
+ return str(value)
391
+
392
+
393
+ def _text(value: Any) -> str | None:
394
+ if value is None:
395
+ return None
396
+ if isinstance(value, str):
397
+ return value
398
+ return json.dumps(_jsonable(value), ensure_ascii=False, sort_keys=True)