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,267 @@
|
|
|
1
|
+
"""Opt-in, run-scoped OpenAI Python SDK observations for custom scripts.
|
|
2
|
+
|
|
3
|
+
Usage:
|
|
4
|
+
rec = OpenAIAgentRecorder(capture_mode="metadata_only")
|
|
5
|
+
client = rec.wrap(OpenAI())
|
|
6
|
+
with rec.agent("Planner"):
|
|
7
|
+
client.responses.create(model="gpt-...", input="hello")
|
|
8
|
+
|
|
9
|
+
This is not transparent network interception. It records client calls made through
|
|
10
|
+
the wrapped resources. Explicit send/receive calls are required for multi-agent
|
|
11
|
+
routing; model output never establishes delivery by itself.
|
|
12
|
+
"""
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import inspect
|
|
16
|
+
import os
|
|
17
|
+
from contextlib import contextmanager
|
|
18
|
+
from contextvars import ContextVar
|
|
19
|
+
from typing import Any
|
|
20
|
+
from uuid import uuid4
|
|
21
|
+
|
|
22
|
+
from .framework_adapters.base import (
|
|
23
|
+
AdapterContext, AgentRecord, ContentCapturePolicy, MessageRecord,
|
|
24
|
+
ModelCallRecord, ToolCallRecord,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
_REDACTED = object()
|
|
28
|
+
_CREDENTIAL_KEYS = frozenset({
|
|
29
|
+
"authorization", "proxy-authorization", "cookie", "set-cookie",
|
|
30
|
+
"api_key", "apikey", "api-key", "x-api-key", "password",
|
|
31
|
+
"token", "access_token", "refresh_token", "client_secret",
|
|
32
|
+
})
|
|
33
|
+
_ALLOWED_RESOURCES = frozenset({"responses", "chat.completions"})
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _safe(value: Any, depth: int = 0) -> Any:
|
|
37
|
+
"""Bounded explicit-content serializer; credential field names are excluded."""
|
|
38
|
+
if depth > 6:
|
|
39
|
+
return "[depth limit]"
|
|
40
|
+
if value is None or type(value) in {bool, int, float}:
|
|
41
|
+
return value
|
|
42
|
+
if isinstance(value, str):
|
|
43
|
+
return value[:32768]
|
|
44
|
+
if isinstance(value, (list, tuple)):
|
|
45
|
+
return [_safe(item, depth + 1) for item in value[:100]]
|
|
46
|
+
if isinstance(value, dict):
|
|
47
|
+
return {
|
|
48
|
+
str(key)[:128]: _safe(item, depth + 1)
|
|
49
|
+
for key, item in list(value.items())[:100]
|
|
50
|
+
if str(key).lower().replace("-", "_") not in
|
|
51
|
+
{name.replace("-", "_") for name in _CREDENTIAL_KEYS}
|
|
52
|
+
}
|
|
53
|
+
if hasattr(value, "model_dump"):
|
|
54
|
+
try:
|
|
55
|
+
return _safe(value.model_dump(mode="json"), depth + 1)
|
|
56
|
+
except (TypeError, ValueError, AttributeError):
|
|
57
|
+
return "[unserializable response]"
|
|
58
|
+
return "[unserializable value]"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class _ResourceProxy:
|
|
62
|
+
def __init__(self, raw: Any, recorder: "OpenAIAgentRecorder", path: str):
|
|
63
|
+
self._raw = raw
|
|
64
|
+
self._recorder = recorder
|
|
65
|
+
self._path = path
|
|
66
|
+
|
|
67
|
+
def __getattr__(self, key: str) -> Any:
|
|
68
|
+
value = getattr(self._raw, key)
|
|
69
|
+
next_path = self._path + "." + key
|
|
70
|
+
if next_path in _ALLOWED_RESOURCES:
|
|
71
|
+
return _ResourceProxy(value, self._recorder, next_path)
|
|
72
|
+
if key != "create" or self._path not in _ALLOWED_RESOURCES:
|
|
73
|
+
return value
|
|
74
|
+
def invoke(*args: Any, **kwargs: Any) -> Any:
|
|
75
|
+
call_id = self._recorder._begin(self._path, kwargs)
|
|
76
|
+
try:
|
|
77
|
+
result = value(*args, **kwargs)
|
|
78
|
+
except BaseException as exc:
|
|
79
|
+
self._recorder._failed(call_id, type(exc).__name__)
|
|
80
|
+
raise
|
|
81
|
+
|
|
82
|
+
# OpenAI's AsyncAPIResource may return an awaitable from an
|
|
83
|
+
# ordinary callable (not an inspect.iscoroutinefunction).
|
|
84
|
+
# A coroutine is NOT a successful response: await it before
|
|
85
|
+
# emitting MODEL_RESPONSE, and classify HTTP errors accurately.
|
|
86
|
+
if inspect.isawaitable(result):
|
|
87
|
+
async def finish() -> Any:
|
|
88
|
+
try:
|
|
89
|
+
resolved = await result
|
|
90
|
+
except BaseException as exc:
|
|
91
|
+
self._recorder._failed(call_id, type(exc).__name__)
|
|
92
|
+
raise
|
|
93
|
+
self._recorder._done(
|
|
94
|
+
call_id, resolved, streamed=kwargs.get("stream") is True,
|
|
95
|
+
)
|
|
96
|
+
return resolved
|
|
97
|
+
return finish()
|
|
98
|
+
|
|
99
|
+
self._recorder._done(call_id, result, streamed=kwargs.get("stream") is True)
|
|
100
|
+
return result
|
|
101
|
+
return invoke
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class _ClientProxy:
|
|
105
|
+
def __init__(self, raw: Any, recorder: "OpenAIAgentRecorder"):
|
|
106
|
+
self._raw = raw
|
|
107
|
+
self._recorder = recorder
|
|
108
|
+
|
|
109
|
+
def __getattr__(self, key: str) -> Any:
|
|
110
|
+
value = getattr(self._raw, key)
|
|
111
|
+
if key in {"responses", "chat"}:
|
|
112
|
+
return _ResourceProxy(value, self._recorder, key)
|
|
113
|
+
return value
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class OpenAIAgentRecorder:
|
|
117
|
+
"""Instrument explicitly wrapped OpenAI/AsyncOpenAI clients.
|
|
118
|
+
|
|
119
|
+
When not launched under ExecWeave, this adapter is a no-op. No API key is
|
|
120
|
+
needed or read by this module; the official SDK handles authentication.
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
def __init__(self, *, capture_mode: str = "metadata_only", default_agent: str = "main"):
|
|
124
|
+
ContentCapturePolicy(capture_mode)
|
|
125
|
+
self._enabled = bool(
|
|
126
|
+
os.environ.get("EXECWEAVE_SEMANTIC_SIDECAR")
|
|
127
|
+
and os.environ.get("EXECWEAVE_SESSION_ID")
|
|
128
|
+
)
|
|
129
|
+
self._context = (AdapterContext.from_environment(
|
|
130
|
+
"openai-python", capture_mode=capture_mode,
|
|
131
|
+
) if self._enabled else None)
|
|
132
|
+
self._capture_mode = capture_mode
|
|
133
|
+
self._default_agent = default_agent
|
|
134
|
+
self._current_agent: ContextVar[str] = ContextVar(
|
|
135
|
+
"execweave_openai_agent", default=default_agent,
|
|
136
|
+
)
|
|
137
|
+
self._agents: dict[str, Any] = {}
|
|
138
|
+
self._calls: dict[str, tuple[Any, Any]] = {}
|
|
139
|
+
self._tools: dict[str, tuple[Any, Any]] = {}
|
|
140
|
+
|
|
141
|
+
def wrap(self, client: Any) -> Any:
|
|
142
|
+
"""Return a proxy for Responses and Chat Completions only."""
|
|
143
|
+
return _ClientProxy(client, self) if self._enabled else client
|
|
144
|
+
|
|
145
|
+
@contextmanager
|
|
146
|
+
def agent(self, name: str):
|
|
147
|
+
"""Explicit agent ownership; contextvars isolates async tasks."""
|
|
148
|
+
if not isinstance(name, str) or not name.strip():
|
|
149
|
+
raise ValueError("agent name must be nonempty")
|
|
150
|
+
marker = self._current_agent.set(name.strip())
|
|
151
|
+
try:
|
|
152
|
+
self._agent(name.strip())
|
|
153
|
+
yield
|
|
154
|
+
finally:
|
|
155
|
+
self._current_agent.reset(marker)
|
|
156
|
+
|
|
157
|
+
def _agent(self, name: str) -> Any:
|
|
158
|
+
if not self._enabled:
|
|
159
|
+
return None
|
|
160
|
+
if name not in self._agents:
|
|
161
|
+
assert self._context is not None
|
|
162
|
+
agent = self._context.entity("agent", name, name=name, attributes={
|
|
163
|
+
"conversation_scope": "framework_agent",
|
|
164
|
+
"conversation_agent_id": name,
|
|
165
|
+
"conversation_agent_path": "/openai-python/" + name,
|
|
166
|
+
"provider": "openai",
|
|
167
|
+
})
|
|
168
|
+
self._context.record_agent(AgentRecord(agent, role=name))
|
|
169
|
+
self._agents[name] = agent
|
|
170
|
+
return self._agents[name]
|
|
171
|
+
|
|
172
|
+
def _begin(self, resource: str, kwargs: dict[str, Any]) -> str:
|
|
173
|
+
call_id = uuid4().hex
|
|
174
|
+
if not self._enabled:
|
|
175
|
+
return call_id
|
|
176
|
+
assert self._context is not None
|
|
177
|
+
agent = self._agent(self._current_agent.get())
|
|
178
|
+
model_name = kwargs.get("model")
|
|
179
|
+
model_name = model_name if isinstance(model_name, str) else "unknown"
|
|
180
|
+
model = self._context.entity("model", model_name, name=model_name, attributes={
|
|
181
|
+
"provider": "openai",
|
|
182
|
+
})
|
|
183
|
+
call = self._context.entity("model_call", call_id, name=resource)
|
|
184
|
+
self._calls[call_id] = (agent, model)
|
|
185
|
+
metadata = {"sdk_surface": resource, "provider": "openai"}
|
|
186
|
+
value = _safe(kwargs) if self._capture_mode != "metadata_only" else None
|
|
187
|
+
self._context.record_model_call(ModelCallRecord(
|
|
188
|
+
call, agent, model, request=value, status="request", attributes=metadata,
|
|
189
|
+
))
|
|
190
|
+
return call_id
|
|
191
|
+
|
|
192
|
+
def _done(self, call_id: str, result: Any, *, streamed: bool) -> None:
|
|
193
|
+
if not self._enabled or call_id not in self._calls:
|
|
194
|
+
return
|
|
195
|
+
assert self._context is not None
|
|
196
|
+
agent, model = self._calls.pop(call_id)
|
|
197
|
+
# A returned iterator is not a completed response. Never label it as such.
|
|
198
|
+
if streamed:
|
|
199
|
+
return
|
|
200
|
+
response = _safe(result) if self._capture_mode == "prompt_and_response" else None
|
|
201
|
+
call = self._context.entity("model_call", call_id, name="OpenAI model call")
|
|
202
|
+
self._context.record_model_call(ModelCallRecord(
|
|
203
|
+
call, agent, model, response=response, status="response",
|
|
204
|
+
attributes={"provider": "openai", "response_observed": True},
|
|
205
|
+
))
|
|
206
|
+
|
|
207
|
+
def _failed(self, call_id: str, exception_type: str) -> None:
|
|
208
|
+
if not self._enabled or call_id not in self._calls:
|
|
209
|
+
return
|
|
210
|
+
assert self._context is not None
|
|
211
|
+
agent, model = self._calls.pop(call_id)
|
|
212
|
+
call = self._context.entity("model_call", call_id, name="OpenAI model call")
|
|
213
|
+
self._context.record_model_call(ModelCallRecord(
|
|
214
|
+
call, agent, model, status="failure",
|
|
215
|
+
attributes={"provider": "openai", "error_type": exception_type[:100]},
|
|
216
|
+
))
|
|
217
|
+
|
|
218
|
+
def sent(self, message_id: str, sender: str, recipient: str, *,
|
|
219
|
+
content: str | None = None) -> None:
|
|
220
|
+
self._message(message_id, sender, recipient, "sent", content)
|
|
221
|
+
|
|
222
|
+
def received(self, message_id: str, sender: str, recipient: str, *,
|
|
223
|
+
content: str | None = None) -> None:
|
|
224
|
+
self._message(message_id, sender, recipient, "received", content)
|
|
225
|
+
|
|
226
|
+
def _message(self, message_id: str, sender: str, recipient: str,
|
|
227
|
+
phase: str, content: str | None) -> None:
|
|
228
|
+
if not all(isinstance(x, str) and x.strip() for x in (message_id, sender, recipient)):
|
|
229
|
+
raise ValueError("message ID, sender and recipient must be nonempty")
|
|
230
|
+
if not self._enabled:
|
|
231
|
+
return
|
|
232
|
+
assert self._context is not None
|
|
233
|
+
source, target = self._agent(sender), self._agent(recipient)
|
|
234
|
+
message = self._context.entity("message", message_id, name="Agent handoff")
|
|
235
|
+
self._context.record_message(MessageRecord(
|
|
236
|
+
message, source, target, direction=phase,
|
|
237
|
+
content=(content if self._capture_mode != "metadata_only" else None),
|
|
238
|
+
))
|
|
239
|
+
|
|
240
|
+
def tool_started(self, name: str, *, arguments: Any = None) -> str:
|
|
241
|
+
call_id = uuid4().hex
|
|
242
|
+
if self._enabled:
|
|
243
|
+
assert self._context is not None
|
|
244
|
+
agent = self._agent(self._current_agent.get())
|
|
245
|
+
tool = self._context.entity("tool", name, name=name)
|
|
246
|
+
self._tools[call_id] = (agent, tool)
|
|
247
|
+
call = self._context.entity("tool_call", call_id, name=name)
|
|
248
|
+
self._context.record_tool_call(ToolCallRecord(
|
|
249
|
+
call, agent, tool,
|
|
250
|
+
arguments=_safe(arguments) if self._capture_mode != "metadata_only" else None,
|
|
251
|
+
status="call",
|
|
252
|
+
))
|
|
253
|
+
return call_id
|
|
254
|
+
|
|
255
|
+
def tool_finished(self, call_id: str, *, result: Any = None,
|
|
256
|
+
failed: bool = False) -> None:
|
|
257
|
+
pair = self._tools.pop(call_id, None)
|
|
258
|
+
if pair is None:
|
|
259
|
+
return
|
|
260
|
+
assert self._context is not None
|
|
261
|
+
agent, tool = pair
|
|
262
|
+
call = self._context.entity("tool_call", call_id, name=tool.name)
|
|
263
|
+
self._context.record_tool_call(ToolCallRecord(
|
|
264
|
+
call, agent, tool,
|
|
265
|
+
result=_safe(result) if self._capture_mode == "prompt_and_response" else None,
|
|
266
|
+
status="failure" if failed else "result",
|
|
267
|
+
))
|