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.
- execweave/__init__.py +3 -0
- execweave/__main__.py +5 -0
- execweave/_conversation_records_core.py +902 -0
- execweave/_dashboard_shell_base.py +148 -0
- execweave/_http_proxy_base.py +565 -0
- execweave/_http_proxy_bounded.py +560 -0
- execweave/_http_proxy_stage.py +509 -0
- execweave/acceptance_output.py +19 -0
- execweave/agent_bootstrap.py +395 -0
- execweave/agent_topology.py +313 -0
- execweave/agent_trace.py +1162 -0
- execweave/agy_preview_sanitize.py +102 -0
- execweave/analysis.py +427 -0
- execweave/anthropic.py +228 -0
- execweave/anthropic_cli.py +171 -0
- execweave/anthropic_full_fidelity.py +385 -0
- execweave/antigravity_adapter.py +112 -0
- execweave/antigravity_adapter_base.py +479 -0
- execweave/antigravity_full_fidelity.py +656 -0
- execweave/antigravity_full_fidelity_base.py +172 -0
- execweave/antigravity_full_fidelity_collaboration_base.py +451 -0
- execweave/antigravity_hook_cli.py +209 -0
- execweave/antigravity_record.py +96 -0
- execweave/antigravity_subagent_linkage.py +449 -0
- execweave/antigravity_trace_capability.py +39 -0
- execweave/auto_specialized.py +547 -0
- execweave/backends.py +102 -0
- execweave/benchmark.py +80 -0
- execweave/claude_adapter.py +517 -0
- execweave/claude_child_transcript.py +314 -0
- execweave/claude_delegation.py +136 -0
- execweave/claude_full_fidelity.py +396 -0
- execweave/claude_hook_cli.py +209 -0
- execweave/claude_hook_contract.py +943 -0
- execweave/claude_model_observer.py +353 -0
- execweave/claude_record.py +106 -0
- execweave/cli.py +629 -0
- execweave/codex_adapter.py +455 -0
- execweave/codex_conversation.py +621 -0
- execweave/codex_full_fidelity.py +287 -0
- execweave/codex_hook_cli.py +301 -0
- execweave/codex_hook_entry.py +207 -0
- execweave/codex_hook_lifecycle.py +363 -0
- execweave/codex_message_diagnostics.py +322 -0
- execweave/codex_message_transport_diagnostics.py +399 -0
- execweave/codex_record.py +199 -0
- execweave/codex_rollout_structures.py +402 -0
- execweave/codex_rollout_trace.py +56 -0
- execweave/codex_rollout_trace_base.py +1509 -0
- execweave/collector.py +768 -0
- execweave/command.py +157 -0
- execweave/command_privacy.py +20 -0
- execweave/content_evidence.py +101 -0
- execweave/content_integrity.py +289 -0
- execweave/content_store.py +273 -0
- execweave/controlled_checks.py +561 -0
- execweave/conversation_archive.py +338 -0
- execweave/conversation_message_identity.py +264 -0
- execweave/conversation_preview.py +66 -0
- execweave/conversation_preview_antigravity.py +32 -0
- execweave/conversation_preview_claude.py +31 -0
- execweave/conversation_preview_codex.py +107 -0
- execweave/conversation_preview_common.py +180 -0
- execweave/conversation_preview_generic.py +188 -0
- execweave/conversation_preview_lines.py +133 -0
- execweave/conversation_preview_transcript.py +121 -0
- execweave/conversation_records.py +349 -0
- execweave/conversation_records_antigravity.py +370 -0
- execweave/conversation_records_codex.py +83 -0
- execweave/conversation_records_common.py +17 -0
- execweave/conversation_records_ollama.py +39 -0
- execweave/correlation.py +818 -0
- execweave/cursor_adapter.py +349 -0
- execweave/cursor_delegation.py +87 -0
- execweave/cursor_delegation_base.py +220 -0
- execweave/cursor_full_fidelity.py +489 -0
- execweave/cursor_hook_cli.py +195 -0
- execweave/cursor_hook_contract.py +439 -0
- execweave/cursor_lifecycle.py +159 -0
- execweave/cursor_record.py +96 -0
- execweave/dashboard_shell.py +283 -0
- execweave/delivery_status.py +94 -0
- execweave/entry.py +98 -0
- execweave/evidence_availability.py +113 -0
- execweave/evidence_grade.py +166 -0
- execweave/fidelity.py +304 -0
- execweave/filesystem.py +327 -0
- execweave/finalization.py +92 -0
- execweave/focus.py +118 -0
- execweave/framework_adapters/__init__.py +34 -0
- execweave/framework_adapters/autogen.py +398 -0
- execweave/framework_adapters/base.py +580 -0
- execweave/framework_adapters/camel.py +270 -0
- execweave/framework_adapters/camel_channel.py +71 -0
- execweave/framework_adapters/metagpt.py +315 -0
- execweave/framework_adapters/metagpt_ollama_compat.py +54 -0
- execweave/framework_adapters/metagpt_recording.py +342 -0
- execweave/framework_adapters/registry.py +90 -0
- execweave/graph.py +590 -0
- execweave/graph_ops.py +472 -0
- execweave/hook_command.py +32 -0
- execweave/hook_delivery.py +32 -0
- execweave/hook_input.py +16 -0
- execweave/http_proxy.py +187 -0
- execweave/http_proxy_cli.py +84 -0
- execweave/inference_gateway.py +476 -0
- execweave/inference_gateway_cli.py +211 -0
- execweave/inference_gateway_full_fidelity.py +613 -0
- execweave/inference_identity.py +76 -0
- execweave/inference_identity_cli.py +60 -0
- execweave/integrity.py +235 -0
- execweave/integrity_cli.py +55 -0
- execweave/investigation_index.py +445 -0
- execweave/litellm_callback.py +211 -0
- execweave/litellm_callback_cli.py +42 -0
- execweave/live.py +445 -0
- execweave/live_core.py +972 -0
- execweave/live_view.py +109 -0
- execweave/live_view_extra_style.py +11 -0
- execweave/live_view_markup.py +29 -0
- execweave/live_view_process_layout.py +650 -0
- execweave/live_view_readability.py +502 -0
- execweave/live_view_script_a.py +59 -0
- execweave/live_view_script_b.py +97 -0
- execweave/live_view_script_c.py +59 -0
- execweave/live_view_script_d.py +40 -0
- execweave/live_view_style.py +34 -0
- execweave/model_runtime.py +560 -0
- execweave/model_runtime_cli.py +265 -0
- execweave/model_runtime_full_fidelity.py +519 -0
- execweave/observation.py +53 -0
- execweave/observation_demo.py +69 -0
- execweave/openai_agents.py +267 -0
- execweave/openai_agents_sdk.py +453 -0
- execweave/openai_compatible.py +239 -0
- execweave/openai_compatible_cli.py +189 -0
- execweave/openai_compatible_full_fidelity.py +438 -0
- execweave/opencode_adapter.py +325 -0
- execweave/opencode_event_contract.py +734 -0
- execweave/opencode_full_fidelity.py +198 -0
- execweave/opencode_hook_cli.py +119 -0
- execweave/opencode_plugin_cli.py +150 -0
- execweave/opencode_record.py +96 -0
- execweave/opencode_task_linkage.py +225 -0
- execweave/overhead_benchmark.py +440 -0
- execweave/privacy.py +84 -0
- execweave/private_io.py +465 -0
- execweave/provider_capability.py +578 -0
- execweave/provider_lifecycle.py +282 -0
- execweave/provider_record.py +290 -0
- execweave/reader_identity.py +13 -0
- execweave/redacted_archive.py +906 -0
- execweave/risk.py +106 -0
- execweave/rule_pack.py +359 -0
- execweave/rule_pack_cli.py +57 -0
- execweave/run_assessment.py +200 -0
- execweave/runtime_endpoint_availability.py +44 -0
- execweave/scalability_benchmark.py +195 -0
- execweave/schema.py +62 -0
- execweave/scope.py +85 -0
- execweave/semantic.py +453 -0
- execweave/session_summary.py +159 -0
- execweave/sink.py +71 -0
- execweave/strace_backend.py +927 -0
- execweave/stream_assembly.py +363 -0
- execweave/task_artifacts.py +192 -0
- execweave/task_validation.py +317 -0
- execweave/theme.py +40 -0
- execweave/top.py +599 -0
- execweave/top_cli.py +150 -0
- execweave/validate.py +196 -0
- execweave/vendor/dagre.min.js +815 -0
- execweave/view_cli.py +49 -0
- execweave/viewer.py +474 -0
- execweave/viewer_agent_panel.py +630 -0
- execweave/viewer_agent_panel_antigravity.py +31 -0
- execweave/viewer_agent_panel_claude.py +9 -0
- execweave/viewer_agent_panel_codex.py +50 -0
- execweave/viewer_agent_panel_cursor.py +9 -0
- execweave/viewer_agent_panel_default.py +79 -0
- execweave/viewer_agent_panel_ollama.py +20 -0
- execweave/viewer_agent_panel_opencode.py +9 -0
- execweave/viewer_agent_panel_registry.py +20 -0
- execweave/viewer_archive_verifier.py +178 -0
- execweave/viewer_background_files.py +86 -0
- execweave/viewer_content_browser.py +307 -0
- execweave/viewer_content_health.py +208 -0
- execweave/viewer_content_inspector.py +309 -0
- execweave/viewer_controlled_checks.py +258 -0
- execweave/viewer_conversation_sync.py +115 -0
- execweave/viewer_dashboard_clean.py +405 -0
- execweave/viewer_dashboard_focus.py +127 -0
- execweave/viewer_dashboard_hardening.py +264 -0
- execweave/viewer_dashboard_hardening_v2.py +62 -0
- execweave/viewer_dashboard_projection.py +261 -0
- execweave/viewer_delivery_status.py +155 -0
- execweave/viewer_edge_decross.py +117 -0
- execweave/viewer_execution_flow.py +611 -0
- execweave/viewer_execution_flow_provider_normalization.py +107 -0
- execweave/viewer_execution_flow_safety.py +349 -0
- execweave/viewer_external_endpoints.py +307 -0
- execweave/viewer_flow_canvas.py +1140 -0
- execweave/viewer_flow_layout.py +922 -0
- execweave/viewer_fold_state.py +31 -0
- execweave/viewer_framework_flow.py +68 -0
- execweave/viewer_framework_model_output.py +133 -0
- execweave/viewer_gif.py +278 -0
- execweave/viewer_history_browser.py +225 -0
- execweave/viewer_investigation.py +268 -0
- execweave/viewer_layout_geometry.py +192 -0
- execweave/viewer_layout_v2.py +429 -0
- execweave/viewer_layout_v2_detached.py +25 -0
- execweave/viewer_limits.py +93 -0
- execweave/viewer_live_layout.py +61 -0
- execweave/viewer_message_handoffs.py +114 -0
- execweave/viewer_projection.py +488 -0
- execweave/viewer_projection_base.py +522 -0
- execweave/viewer_projection_bridges.py +214 -0
- execweave/viewer_recorded_sources.py +146 -0
- execweave/viewer_run_assessment.py +274 -0
- execweave/viewer_run_guide.py +175 -0
- execweave/viewer_runtime_evidence.py +258 -0
- execweave/viewer_semantic_projection.py +641 -0
- execweave/viewer_session_flow.py +491 -0
- execweave/viewer_structure_share.py +132 -0
- execweave/viewer_task_validation.py +241 -0
- execweave/viewer_tool_mirror_identity.py +75 -0
- execweave/viewer_workflow_mode.py +127 -0
- execweave/workflow.py +183 -0
- execweave-1.0.0.dist-info/METADATA +462 -0
- execweave-1.0.0.dist-info/RECORD +234 -0
- execweave-1.0.0.dist-info/WHEEL +4 -0
- execweave-1.0.0.dist-info/entry_points.txt +30 -0
- 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)
|