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,270 @@
|
|
|
1
|
+
"""CAMEL Workforce adapter over authoritative callback/model boundaries."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import importlib.metadata
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from .base import AdapterCapabilities, AdapterContext, AgentRecord, EntityRef, FrameworkAdapter, FrameworkCompatibility, MessageRecord, ModelCallRecord, ProcessRef, TaskRecord
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class CAMELAdapter(FrameworkAdapter):
|
|
12
|
+
framework_name = "camel"
|
|
13
|
+
capabilities = AdapterCapabilities(
|
|
14
|
+
events=("AGENT_CREATED", "AGENT_STARTED", "AGENT_STOPPED", "TASK_CREATED", "TASK_ASSIGNED", "TASK_STARTED", "TASK_UPDATED", "TASK_COMPLETED", "TASK_FAILED", "TASK_CONTENT_RECORDED", "MESSAGE_SENT", "MESSAGE_RECEIVED", "MESSAGE_UNROUTED", "MODEL_REQUEST", "MODEL_RESPONSE", "MODEL_FAILURE"),
|
|
15
|
+
content_modes=("metadata_only", "content_ref_only", "prompt_only", "prompt_and_response"),
|
|
16
|
+
authoritative_surfaces=("camel.societies.workforce.WorkforceCallback", "camel.models.BaseModelBackend.run", "camel.models.BaseModelBackend.arun"),
|
|
17
|
+
known_limitations=("WorkforceCallback LogEvent does not expose the emitting worker or recipient; those log messages are explicitly marked MESSAGE_UNROUTED and correlated to the observed process instead of being assigned to a guessed agent.", "A created worker is not treated as assigned until CAMEL reports a task assignment."),
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
def __init__(self, context: AdapterContext) -> None:
|
|
21
|
+
super().__init__(context)
|
|
22
|
+
self._agents: dict[str, EntityRef] = {}
|
|
23
|
+
self._tasks: dict[str, EntityRef] = {}
|
|
24
|
+
self._active_tasks_by_agent: dict[str, EntityRef] = {}
|
|
25
|
+
self._message_counter = 0
|
|
26
|
+
|
|
27
|
+
@classmethod
|
|
28
|
+
def compatibility(cls) -> FrameworkCompatibility:
|
|
29
|
+
try:
|
|
30
|
+
version = importlib.metadata.version("camel-ai")
|
|
31
|
+
except importlib.metadata.PackageNotFoundError:
|
|
32
|
+
version = None
|
|
33
|
+
status = "verified" if version in {"0.2.84", "0.2.91a7"} else ("warn" if version else "unknown")
|
|
34
|
+
return FrameworkCompatibility(framework=cls.framework_name, detected_version=version, tested_versions=("0.2.84", "0.2.91a7"), compatibility_status=status, capabilities=cls.capabilities, known_limitations=cls.capabilities.known_limitations)
|
|
35
|
+
|
|
36
|
+
def agent_created(self, native_id: str | int, *, name: str | None = None, role: str | None = None, process: ProcessRef | None = None, parent: EntityRef | None = None, **attributes: Any) -> EntityRef:
|
|
37
|
+
agent = self.agent(native_id, name=name, role=role, provider="camel", **attributes)
|
|
38
|
+
self._agents[str(native_id)] = agent
|
|
39
|
+
self.context.record_agent(AgentRecord(agent, role=role, process=process, parent_agent=parent, attributes=attributes))
|
|
40
|
+
return agent
|
|
41
|
+
|
|
42
|
+
def agent_started(self, agent: EntityRef, **attributes: Any) -> None:
|
|
43
|
+
self.emit("AGENT_STARTED", "AGENT_STARTED", source=agent, attributes=attributes)
|
|
44
|
+
|
|
45
|
+
def agent_stopped(self, agent: EntityRef, **attributes: Any) -> None:
|
|
46
|
+
self.emit("AGENT_STOPPED", "AGENT_STOPPED", source=agent, attributes=attributes)
|
|
47
|
+
|
|
48
|
+
def task_event(self, event_type: str, native_id: str | int, *, name: str | None = None, owner: EntityRef | None = None, parent: EntityRef | None = None, content: str | None = None, content_kind: str = "task_prompt", **attributes: Any) -> EntityRef:
|
|
49
|
+
existing = self._tasks.get(str(native_id))
|
|
50
|
+
if existing is not None and name is None and content is None and not attributes:
|
|
51
|
+
task = existing
|
|
52
|
+
else:
|
|
53
|
+
entity_attributes = dict(attributes)
|
|
54
|
+
if content is not None and self.context.capture_policy.mode in {
|
|
55
|
+
"prompt_only",
|
|
56
|
+
"prompt_and_response",
|
|
57
|
+
}:
|
|
58
|
+
entity_attributes.setdefault("task_prompt", content)
|
|
59
|
+
task = self.task(native_id, name=name, provider="camel", **entity_attributes)
|
|
60
|
+
self._tasks[str(native_id)] = task
|
|
61
|
+
self.context.record_task(
|
|
62
|
+
TaskRecord(
|
|
63
|
+
task,
|
|
64
|
+
owner=owner,
|
|
65
|
+
parent_task=parent,
|
|
66
|
+
content=content,
|
|
67
|
+
content_kind=content_kind,
|
|
68
|
+
attributes=attributes,
|
|
69
|
+
),
|
|
70
|
+
event_type=event_type,
|
|
71
|
+
)
|
|
72
|
+
return task
|
|
73
|
+
|
|
74
|
+
def task_created(self, native_id: str | int, **kwargs: Any) -> EntityRef:
|
|
75
|
+
return self.task_event("TASK_CREATED", native_id, **kwargs)
|
|
76
|
+
|
|
77
|
+
def task_assigned(self, task: EntityRef, agent: EntityRef, **attributes: Any) -> None:
|
|
78
|
+
self._active_tasks_by_agent[agent.id] = task
|
|
79
|
+
self.emit("TASK_ASSIGNED", "ASSIGNED_TO", source=task, target=agent, attributes=attributes)
|
|
80
|
+
|
|
81
|
+
def active_task_for(self, agent: EntityRef | None) -> EntityRef | None:
|
|
82
|
+
"""Return the latest provider-observed task assigned to an agent."""
|
|
83
|
+
return self._active_tasks_by_agent.get(agent.id) if agent is not None else None
|
|
84
|
+
|
|
85
|
+
def task_started(self, task: EntityRef, agent: EntityRef | None = None, **attributes: Any) -> None:
|
|
86
|
+
self.emit("TASK_STARTED", "TASK_STARTED", source=agent or task, target=task, attributes=attributes)
|
|
87
|
+
|
|
88
|
+
def task_updated(self, task: EntityRef, **attributes: Any) -> None:
|
|
89
|
+
self.emit("TASK_UPDATED", "TASK_UPDATED", source=task, attributes=attributes)
|
|
90
|
+
|
|
91
|
+
def task_completed(self, task: EntityRef, agent: EntityRef | None = None, **attributes: Any) -> None:
|
|
92
|
+
self.emit("TASK_COMPLETED", "TASK_COMPLETED", source=agent or task, target=task, attributes=attributes)
|
|
93
|
+
|
|
94
|
+
def task_failed(self, task: EntityRef, agent: EntityRef | None = None, **attributes: Any) -> None:
|
|
95
|
+
self.emit("TASK_FAILED", "TASK_FAILED", source=agent or task, target=task, attributes=attributes)
|
|
96
|
+
|
|
97
|
+
def message(self, message_id: str | int, source: EntityRef | None, target: EntityRef | None, *, content: str | None = None, role: str | None = None, task: EntityRef | None = None, received: bool = False, **attributes: Any) -> EntityRef:
|
|
98
|
+
message = self.entity("message", message_id, name="CAMEL message", attributes={"provider": "camel"})
|
|
99
|
+
self.context.record_message(MessageRecord(message, source, target, role=role, task=task, content=content, direction="received" if received else "sent", attributes=attributes))
|
|
100
|
+
return message
|
|
101
|
+
|
|
102
|
+
def message_unrouted(self, message: EntityRef, *, callback_name: str, missing_sender: bool, missing_recipient: bool, reason: str = "callback_payload_missing_agent_boundary") -> None:
|
|
103
|
+
"""Keep callback messages visible without inventing an agent route.
|
|
104
|
+
|
|
105
|
+
CAMEL's WorkforceCallback log surface can emit a message without a
|
|
106
|
+
worker or recipient. The process is the only authoritative boundary
|
|
107
|
+
available in that case, so record that boundary explicitly rather
|
|
108
|
+
than leaving the message looking like a dropped graph node.
|
|
109
|
+
"""
|
|
110
|
+
process = self.context.process
|
|
111
|
+
if process is None:
|
|
112
|
+
return
|
|
113
|
+
self.emit(
|
|
114
|
+
"MESSAGE_UNROUTED",
|
|
115
|
+
"OBSERVED_AT_PROCESS",
|
|
116
|
+
source=message,
|
|
117
|
+
target=process.to_entity(),
|
|
118
|
+
attributes={
|
|
119
|
+
"callback_name": callback_name,
|
|
120
|
+
"routing_status": "unrouted",
|
|
121
|
+
"routing_reason": reason,
|
|
122
|
+
"missing_sender": missing_sender,
|
|
123
|
+
"missing_recipient": missing_recipient,
|
|
124
|
+
"routing_basis": "authoritative_process_boundary",
|
|
125
|
+
},
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
def model_call(self, call_id: str | int, agent: EntityRef | None, model_id: str | int, *, model_name: str | None = None, request: Any | None = None, response: Any | None = None, status: str = "request", task: EntityRef | None = None, **attributes: Any) -> EntityRef:
|
|
129
|
+
model = self.model(model_id, name=model_name, provider="camel", **attributes)
|
|
130
|
+
call = self.entity("model_call", call_id, name="CAMEL model call", attributes={"provider": "camel"})
|
|
131
|
+
self.context.record_model_call(ModelCallRecord(call, agent, model, request=request, response=response, content_kind="model_request" if status == "request" else "model_response", status=status, task=task, attributes=attributes))
|
|
132
|
+
return call
|
|
133
|
+
|
|
134
|
+
def workforce_callback(self) -> Any:
|
|
135
|
+
"""Build a callback compatible with the installed CAMEL Workforce."""
|
|
136
|
+
module = __import__("camel.societies.workforce.workforce_callback", fromlist=["WorkforceCallback"])
|
|
137
|
+
base = module.WorkforceCallback
|
|
138
|
+
methods = {name: _callback_method(name, self) for name in getattr(base, "__abstractmethods__", frozenset())}
|
|
139
|
+
for name in ("log_worker_created", "log_task_created", "log_task_assigned", "log_task_started", "log_task_updated", "log_task_completed", "log_task_failed"):
|
|
140
|
+
methods[name] = _callback_method(name, self)
|
|
141
|
+
return type("ExecWeaveCAMELWorkforceCallback", (base,), methods)()
|
|
142
|
+
|
|
143
|
+
def observe_task_channel(self, channel: Any, *, publishers: dict[str, EntityRef]) -> Any:
|
|
144
|
+
"""Record actual task dispatch/receipt and result dispatch/receipt."""
|
|
145
|
+
from .camel_channel import observe_task_channel
|
|
146
|
+
|
|
147
|
+
return observe_task_channel(self, channel, publishers)
|
|
148
|
+
|
|
149
|
+
def _callback_event(self, name: str, args: tuple[Any, ...], kwargs: dict[str, Any]) -> Any:
|
|
150
|
+
payload = _payload(args, kwargs)
|
|
151
|
+
if name in {"log_message", "log_stream_chunk"}:
|
|
152
|
+
content = _string(_value(payload, "message", "text"))
|
|
153
|
+
native_message_id = _value(payload, "message_id", "id", "task_id", "worker_id")
|
|
154
|
+
self._message_counter += 1
|
|
155
|
+
message_id = (
|
|
156
|
+
native_message_id
|
|
157
|
+
if isinstance(native_message_id, (str, int)) and str(native_message_id)
|
|
158
|
+
else f"{self.framework_name}-message-{self._message_counter}"
|
|
159
|
+
)
|
|
160
|
+
worker_id = _value(payload, "worker_id", "agent_id")
|
|
161
|
+
source = self._agents.get(str(worker_id)) if worker_id is not None else None
|
|
162
|
+
target_id = _value(payload, "target_worker_id", "recipient_worker_id", "target_agent_id", "recipient_agent_id", "receiver_id")
|
|
163
|
+
target = self._agents.get(str(target_id)) if target_id is not None else None
|
|
164
|
+
message = self.message(
|
|
165
|
+
message_id,
|
|
166
|
+
source,
|
|
167
|
+
target,
|
|
168
|
+
content=content,
|
|
169
|
+
role="stream" if name == "log_stream_chunk" else "log",
|
|
170
|
+
attributes={
|
|
171
|
+
"callback_name": name,
|
|
172
|
+
"event_type": _value(payload, "event_type"),
|
|
173
|
+
"metadata": _value(payload, "metadata"),
|
|
174
|
+
"message_id_source": "provider" if native_message_id is not None else "execweave_derived",
|
|
175
|
+
},
|
|
176
|
+
)
|
|
177
|
+
if source is None or target is None:
|
|
178
|
+
self.message_unrouted(
|
|
179
|
+
message,
|
|
180
|
+
callback_name=name,
|
|
181
|
+
missing_sender=source is None,
|
|
182
|
+
missing_recipient=target is None,
|
|
183
|
+
)
|
|
184
|
+
return message
|
|
185
|
+
if name == "log_task_decomposed":
|
|
186
|
+
parent_key = _native(payload, "parent_task_id", "task_id", "id")
|
|
187
|
+
parent = self._tasks.get(str(parent_key)) or self.task_created(parent_key)
|
|
188
|
+
subtasks = _value(payload, "subtask_ids")
|
|
189
|
+
for subtask_key in subtasks if isinstance(subtasks, list) else []:
|
|
190
|
+
self.task_event("TASK_CREATED", subtask_key, parent=parent)
|
|
191
|
+
return self.task_updated(parent, callback_name=name, subtask_ids=subtasks)
|
|
192
|
+
if name == "log_worker_deleted":
|
|
193
|
+
worker_key = _native(payload, "worker_id", "id", "name")
|
|
194
|
+
agent = self._agents.get(str(worker_key)) or self.agent_created(worker_key)
|
|
195
|
+
return self.agent_stopped(agent, reason=_value(payload, "reason"))
|
|
196
|
+
if name == "log_all_tasks_completed":
|
|
197
|
+
task_key = _value(payload, "task_id")
|
|
198
|
+
if task_key is not None:
|
|
199
|
+
task = self._tasks.get(str(task_key)) or self.task_created(task_key)
|
|
200
|
+
return self.task_completed(task, callback_name=name)
|
|
201
|
+
return self.emit("TASK_COMPLETED", "ALL_TASKS_COMPLETED", attributes={"callback_name": name})
|
|
202
|
+
if name == "log_worker_created":
|
|
203
|
+
return self.agent_created(_native(payload, "worker_id", "id", "name"), name=_string(_value(payload, "name", "role")), role=_string(_value(payload, "role", "worker_type")))
|
|
204
|
+
if name == "log_task_created":
|
|
205
|
+
task_key = _native(payload, "task_id", "id", "name")
|
|
206
|
+
existing = self._tasks.get(str(task_key))
|
|
207
|
+
if existing is not None:
|
|
208
|
+
return existing
|
|
209
|
+
return self.task_created(task_key, name=_string(_value(payload, "name", "description")))
|
|
210
|
+
if name == "log_task_assigned":
|
|
211
|
+
task_key = _native(payload, "task_id", "id", "name")
|
|
212
|
+
task = self._tasks.get(str(task_key)) or self.task_created(task_key)
|
|
213
|
+
worker_value = kwargs.get("worker") or kwargs.get("agent") or payload
|
|
214
|
+
agent_key = _native(worker_value, "worker_id", "agent_id", "id", "name")
|
|
215
|
+
agent = self._agents.get(str(agent_key)) or self.agent_created(agent_key, name=_string(_value(worker_value, "name", "role")))
|
|
216
|
+
return self.task_assigned(task, agent)
|
|
217
|
+
task_value = kwargs.get("task") or payload
|
|
218
|
+
task_key = _native(task_value, "task_id", "id", "name")
|
|
219
|
+
task = self._tasks.get(str(task_key)) or self.task_created(task_key)
|
|
220
|
+
if name == "log_task_started":
|
|
221
|
+
return self.task_started(task)
|
|
222
|
+
if name == "log_task_updated":
|
|
223
|
+
return self.task_updated(task, callback_name=name)
|
|
224
|
+
if name == "log_task_completed":
|
|
225
|
+
return self.task_completed(task)
|
|
226
|
+
if name == "log_task_failed":
|
|
227
|
+
return self.task_failed(task)
|
|
228
|
+
return self.emit("TASK_UPDATED", "CALLBACK_OBSERVED", attributes={"callback_name": name, "argument_count": len(args)})
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def _callback_method(name: str, adapter: CAMELAdapter):
|
|
232
|
+
def callback(*args: Any, **kwargs: Any) -> Any:
|
|
233
|
+
return adapter._callback_event(name, args, kwargs)
|
|
234
|
+
return callback
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def _payload(args: tuple[Any, ...], kwargs: dict[str, Any]) -> Any:
|
|
238
|
+
if args:
|
|
239
|
+
return args[-1]
|
|
240
|
+
for value in reversed(args):
|
|
241
|
+
if isinstance(value, (dict, str, int)):
|
|
242
|
+
return value
|
|
243
|
+
for key in ("task", "worker", "agent", "model", "message", "task_id", "worker_id"):
|
|
244
|
+
if key in kwargs:
|
|
245
|
+
return kwargs[key]
|
|
246
|
+
return kwargs
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def _value(value: Any, *keys: str) -> Any:
|
|
250
|
+
if isinstance(value, dict):
|
|
251
|
+
for key in keys:
|
|
252
|
+
if key in value:
|
|
253
|
+
return value[key]
|
|
254
|
+
for key in keys:
|
|
255
|
+
candidate = getattr(value, key, None)
|
|
256
|
+
if candidate is not None:
|
|
257
|
+
return candidate
|
|
258
|
+
return value if isinstance(value, (str, int, float, bool)) else None
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def _native(value: Any, *keys: str) -> str | int:
|
|
262
|
+
candidate = _value(value, *keys)
|
|
263
|
+
return candidate if isinstance(candidate, (str, int)) and str(candidate) else str(candidate)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def _string(value: Any) -> str | None:
|
|
267
|
+
if value is None:
|
|
268
|
+
return None
|
|
269
|
+
text = str(value).strip()
|
|
270
|
+
return text or None
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Observe an explicitly supplied CAMEL TaskChannel instance, not global classes."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from typing import Any, Mapping
|
|
5
|
+
|
|
6
|
+
from .base import EntityRef
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def observe_task_channel(adapter: Any, channel: Any, publishers: Mapping[str, EntityRef]) -> Any:
|
|
10
|
+
if getattr(channel, "_execweave_channel_adapter", None) is adapter:
|
|
11
|
+
return channel
|
|
12
|
+
names = ("post_task", "get_assigned_task_by_assignee", "return_task", "get_returned_task_by_publisher")
|
|
13
|
+
originals = {name: getattr(channel, name, None) for name in names}
|
|
14
|
+
if not all(callable(method) for method in originals.values()):
|
|
15
|
+
raise TypeError("CAMEL channel does not expose the supported task delivery boundaries")
|
|
16
|
+
routes: dict[str, dict[str, Any]] = {}
|
|
17
|
+
counter = 0
|
|
18
|
+
|
|
19
|
+
def record(route, *, reply=False, received=False):
|
|
20
|
+
source, target = route["publisher"], route["assignee"]
|
|
21
|
+
task = route["task"]
|
|
22
|
+
content = str(getattr(task, "result", "") or "") if reply else str(getattr(task, "content", "") or "")
|
|
23
|
+
if reply:
|
|
24
|
+
source, target = target, source
|
|
25
|
+
message = adapter.message(
|
|
26
|
+
route["id"] + (":reply" if reply else ":dispatch"), source, target,
|
|
27
|
+
content=content, role="agent", received=received,
|
|
28
|
+
routing_source="camel_task_channel_delivery" if received else "camel_task_channel_post",
|
|
29
|
+
native_task_id=str(task.id),
|
|
30
|
+
)
|
|
31
|
+
if source is None or target is None:
|
|
32
|
+
adapter.message_unrouted(message, callback_name="TaskChannel", missing_sender=source is None, missing_recipient=target is None)
|
|
33
|
+
|
|
34
|
+
async def post_task(task, publisher_id, assignee_id):
|
|
35
|
+
nonlocal counter
|
|
36
|
+
result = await originals["post_task"](task, publisher_id, assignee_id)
|
|
37
|
+
counter += 1
|
|
38
|
+
route = {"id": f"channel:{task.id}:{counter}", "task": task,
|
|
39
|
+
"publisher": publishers.get(str(publisher_id)) or adapter._agents.get(str(publisher_id)),
|
|
40
|
+
"assignee": adapter._agents.get(str(assignee_id))}
|
|
41
|
+
routes[str(task.id)] = route
|
|
42
|
+
record(route)
|
|
43
|
+
return result
|
|
44
|
+
|
|
45
|
+
async def assigned(assignee_id):
|
|
46
|
+
task = await originals["get_assigned_task_by_assignee"](assignee_id)
|
|
47
|
+
route = routes.get(str(task.id))
|
|
48
|
+
if route:
|
|
49
|
+
record(route, received=True)
|
|
50
|
+
return task
|
|
51
|
+
|
|
52
|
+
async def return_task(task_id):
|
|
53
|
+
result = await originals["return_task"](task_id)
|
|
54
|
+
route = routes.get(str(task_id))
|
|
55
|
+
if route:
|
|
56
|
+
record(route, reply=True)
|
|
57
|
+
return result
|
|
58
|
+
|
|
59
|
+
async def returned(publisher_id):
|
|
60
|
+
task = await originals["get_returned_task_by_publisher"](publisher_id)
|
|
61
|
+
route = routes.pop(str(task.id), None)
|
|
62
|
+
if route:
|
|
63
|
+
record(route, reply=True, received=True)
|
|
64
|
+
return task
|
|
65
|
+
|
|
66
|
+
channel.post_task = post_task
|
|
67
|
+
channel.get_assigned_task_by_assignee = assigned
|
|
68
|
+
channel.return_task = return_task
|
|
69
|
+
channel.get_returned_task_by_publisher = returned
|
|
70
|
+
channel._execweave_channel_adapter = adapter
|
|
71
|
+
return channel
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
"""MetaGPT adapter for role/message/action/model/parser observability."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import importlib.metadata
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from .base import (
|
|
9
|
+
AdapterCapabilities,
|
|
10
|
+
AdapterContext,
|
|
11
|
+
AgentRecord,
|
|
12
|
+
EntityRef,
|
|
13
|
+
FrameworkAdapter,
|
|
14
|
+
FrameworkCompatibility,
|
|
15
|
+
MessageRecord,
|
|
16
|
+
ModelCallRecord,
|
|
17
|
+
TaskRecord,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class MetaGPTAdapter(FrameworkAdapter):
|
|
22
|
+
framework_name = "metagpt"
|
|
23
|
+
capabilities = AdapterCapabilities(
|
|
24
|
+
events=(
|
|
25
|
+
"AGENT_CREATED",
|
|
26
|
+
"AGENT_STARTED",
|
|
27
|
+
"AGENT_STOPPED",
|
|
28
|
+
"TASK_CREATED",
|
|
29
|
+
"TASK_STARTED",
|
|
30
|
+
"TASK_COMPLETED",
|
|
31
|
+
"TASK_FAILED",
|
|
32
|
+
"TASK_UPDATED",
|
|
33
|
+
"TASK_CONTENT_RECORDED",
|
|
34
|
+
"MESSAGE_SENT",
|
|
35
|
+
"MESSAGE_RECEIVED",
|
|
36
|
+
"MODEL_REQUEST",
|
|
37
|
+
"MODEL_RESPONSE",
|
|
38
|
+
"MODEL_FAILURE",
|
|
39
|
+
),
|
|
40
|
+
content_modes=("metadata_only", "content_ref_only", "prompt_only", "prompt_and_response"),
|
|
41
|
+
authoritative_surfaces=(
|
|
42
|
+
"metagpt.roles.Role",
|
|
43
|
+
"metagpt.actions.Action",
|
|
44
|
+
"metagpt.schema.Message",
|
|
45
|
+
"metagpt.provider.base_llm.BaseLLM",
|
|
46
|
+
),
|
|
47
|
+
known_limitations=(
|
|
48
|
+
"MetaGPT releases expose different role and provider hooks; parser failure and retry events must be supplied by the integration wrapper.",
|
|
49
|
+
),
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
def __init__(self, context: AdapterContext) -> None:
|
|
53
|
+
super().__init__(context)
|
|
54
|
+
self._roles: dict[str, EntityRef] = {}
|
|
55
|
+
self._message_counter = 0
|
|
56
|
+
|
|
57
|
+
@classmethod
|
|
58
|
+
def compatibility(cls) -> FrameworkCompatibility:
|
|
59
|
+
try:
|
|
60
|
+
version = importlib.metadata.version("metagpt")
|
|
61
|
+
except importlib.metadata.PackageNotFoundError:
|
|
62
|
+
version = None
|
|
63
|
+
status = "verified" if version == "1.0.0" else ("warn" if version else "unknown")
|
|
64
|
+
return FrameworkCompatibility(
|
|
65
|
+
framework=cls.framework_name,
|
|
66
|
+
detected_version=version,
|
|
67
|
+
tested_versions=("1.0.0", "0.8.x"),
|
|
68
|
+
compatibility_status=status,
|
|
69
|
+
capabilities=cls.capabilities,
|
|
70
|
+
known_limitations=cls.capabilities.known_limitations,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
def observe_role(
|
|
74
|
+
self,
|
|
75
|
+
native_id: str | int,
|
|
76
|
+
*,
|
|
77
|
+
name: str | None = None,
|
|
78
|
+
role: str | None = None,
|
|
79
|
+
process: Any | None = None,
|
|
80
|
+
**attributes: Any,
|
|
81
|
+
) -> EntityRef:
|
|
82
|
+
agent = self.agent(native_id, name=name, provider="metagpt", role=role, **attributes)
|
|
83
|
+
self._roles[str(native_id)] = agent
|
|
84
|
+
self.context.record_agent(AgentRecord(agent, role=role, process=process, attributes=attributes))
|
|
85
|
+
return agent
|
|
86
|
+
|
|
87
|
+
def observe_role_object(self, role_object: Any, *, process: Any | None = None, **attributes: Any) -> EntityRef:
|
|
88
|
+
"""Observe a current ``metagpt.roles.Role`` instance by its public fields."""
|
|
89
|
+
native_id = getattr(role_object, "role_id", None) or getattr(role_object, "name", None) or type(role_object).__name__
|
|
90
|
+
name = _text(getattr(role_object, "name", None)) or type(role_object).__name__
|
|
91
|
+
profile = _text(getattr(role_object, "profile", None))
|
|
92
|
+
return self.observe_role(native_id, name=name, role=profile, process=process, role_type=type(role_object).__name__, **attributes)
|
|
93
|
+
|
|
94
|
+
def observe_task(
|
|
95
|
+
self,
|
|
96
|
+
task_id: str | int,
|
|
97
|
+
*,
|
|
98
|
+
owner: EntityRef | None = None,
|
|
99
|
+
name: str | None = None,
|
|
100
|
+
content: str | None = None,
|
|
101
|
+
content_kind: str = "task_prompt",
|
|
102
|
+
status: str = "created",
|
|
103
|
+
**attributes: Any,
|
|
104
|
+
) -> EntityRef:
|
|
105
|
+
entity_attributes = dict(attributes)
|
|
106
|
+
if content is not None and self.context.capture_policy.mode in {
|
|
107
|
+
"prompt_only",
|
|
108
|
+
"prompt_and_response",
|
|
109
|
+
}:
|
|
110
|
+
entity_attributes.setdefault("task_prompt", content)
|
|
111
|
+
task = self.task(task_id, name=name, provider="metagpt", **entity_attributes)
|
|
112
|
+
event = {
|
|
113
|
+
"created": "TASK_CREATED",
|
|
114
|
+
"started": "TASK_STARTED",
|
|
115
|
+
"completed": "TASK_COMPLETED",
|
|
116
|
+
"failed": "TASK_FAILED",
|
|
117
|
+
}.get(status)
|
|
118
|
+
if event is None:
|
|
119
|
+
raise ValueError(f"unsupported MetaGPT task status: {status}")
|
|
120
|
+
self.context.record_task(
|
|
121
|
+
TaskRecord(
|
|
122
|
+
task,
|
|
123
|
+
owner=owner,
|
|
124
|
+
content=content,
|
|
125
|
+
content_kind=content_kind,
|
|
126
|
+
attributes=attributes,
|
|
127
|
+
),
|
|
128
|
+
event_type=event,
|
|
129
|
+
)
|
|
130
|
+
return task
|
|
131
|
+
|
|
132
|
+
def observe_message(
|
|
133
|
+
self,
|
|
134
|
+
message_id: str | int,
|
|
135
|
+
*,
|
|
136
|
+
source: EntityRef | None,
|
|
137
|
+
target: EntityRef | None,
|
|
138
|
+
content: str | None = None,
|
|
139
|
+
role: str | None = None,
|
|
140
|
+
task: EntityRef | None = None,
|
|
141
|
+
received: bool = False,
|
|
142
|
+
content_payload: Any | None = None,
|
|
143
|
+
**attributes: Any,
|
|
144
|
+
) -> EntityRef:
|
|
145
|
+
message = self.entity("message", message_id, name="MetaGPT message", attributes={"provider": "metagpt"})
|
|
146
|
+
self.context.record_message(
|
|
147
|
+
MessageRecord(
|
|
148
|
+
message,
|
|
149
|
+
source,
|
|
150
|
+
target,
|
|
151
|
+
role=role,
|
|
152
|
+
task=task,
|
|
153
|
+
content=content,
|
|
154
|
+
content_payload=content_payload,
|
|
155
|
+
direction="received" if received else "sent",
|
|
156
|
+
attributes=attributes,
|
|
157
|
+
)
|
|
158
|
+
)
|
|
159
|
+
return message
|
|
160
|
+
|
|
161
|
+
def observe_message_object(self, message_object: Any, *, task: EntityRef | None = None, **attributes: Any) -> EntityRef:
|
|
162
|
+
"""Observe a current ``metagpt.schema.Message`` instance."""
|
|
163
|
+
self._message_counter += 1
|
|
164
|
+
message_id = getattr(message_object, "id", None) or f"message-{self._message_counter}"
|
|
165
|
+
source_name = getattr(message_object, "sent_from", None)
|
|
166
|
+
target_name = getattr(message_object, "send_to", None)
|
|
167
|
+
source = self._roles.get(str(source_name)) if source_name else None
|
|
168
|
+
if source is None and source_name == "user":
|
|
169
|
+
source = self.entity("user", "user", name="user")
|
|
170
|
+
content = _text(getattr(message_object, "content", None))
|
|
171
|
+
role = _text(getattr(message_object, "role", None))
|
|
172
|
+
common_attributes = {
|
|
173
|
+
"cause_by": _text(getattr(message_object, "cause_by", None)),
|
|
174
|
+
"metadata": getattr(message_object, "metadata", None),
|
|
175
|
+
"message_type": type(message_object).__name__,
|
|
176
|
+
**attributes,
|
|
177
|
+
}
|
|
178
|
+
target_names = None
|
|
179
|
+
if isinstance(target_name, (list, tuple, set, frozenset)):
|
|
180
|
+
target_names = list(target_name)
|
|
181
|
+
if isinstance(target_name, (set, frozenset)):
|
|
182
|
+
target_names.sort(key=str)
|
|
183
|
+
targets = [self._roles.get(str(name)) for name in target_names if name]
|
|
184
|
+
targets = [target for target in targets if target is not None]
|
|
185
|
+
else:
|
|
186
|
+
target = self._roles.get(str(target_name)) if isinstance(target_name, str) else None
|
|
187
|
+
targets = [target] if target is not None else []
|
|
188
|
+
shared_content_payload = None
|
|
189
|
+
if target_names is not None and targets:
|
|
190
|
+
recipient_labels = [target.name or target.id for target in targets]
|
|
191
|
+
shared_content_payload = {
|
|
192
|
+
"message_id": message_id,
|
|
193
|
+
"text": content,
|
|
194
|
+
"sender": source.name or source.id if source is not None else None,
|
|
195
|
+
"recipient": recipient_labels[0] if len(recipient_labels) == 1 else None,
|
|
196
|
+
"recipients": recipient_labels,
|
|
197
|
+
"role": role,
|
|
198
|
+
"kind": "agent_message",
|
|
199
|
+
"phase": "sent",
|
|
200
|
+
"content_state": "plaintext",
|
|
201
|
+
}
|
|
202
|
+
if not targets:
|
|
203
|
+
return self.observe_message(
|
|
204
|
+
message_id,
|
|
205
|
+
source=source,
|
|
206
|
+
target=None,
|
|
207
|
+
content=content,
|
|
208
|
+
role=role,
|
|
209
|
+
task=task,
|
|
210
|
+
content_payload=shared_content_payload,
|
|
211
|
+
**common_attributes,
|
|
212
|
+
)
|
|
213
|
+
message = None
|
|
214
|
+
for target in targets:
|
|
215
|
+
message = self.observe_message(
|
|
216
|
+
message_id,
|
|
217
|
+
source=source,
|
|
218
|
+
target=target,
|
|
219
|
+
content=content,
|
|
220
|
+
role=role,
|
|
221
|
+
task=task,
|
|
222
|
+
content_payload=shared_content_payload,
|
|
223
|
+
**common_attributes,
|
|
224
|
+
)
|
|
225
|
+
return message
|
|
226
|
+
|
|
227
|
+
def observe_message_delivery(self, message_object: Any, *, recipient: EntityRef, task: EntityRef | None = None) -> EntityRef:
|
|
228
|
+
"""Call after the native Role.put_message accepted a message into its queue."""
|
|
229
|
+
self._message_counter += 1
|
|
230
|
+
return self.observe_message(
|
|
231
|
+
getattr(message_object, "id", None) or f"delivery-{self._message_counter}",
|
|
232
|
+
source=(self.entity("user", "user", name="user") if getattr(message_object, "sent_from", None) == "user"
|
|
233
|
+
else self._roles.get(str(getattr(message_object, "sent_from", "")))),
|
|
234
|
+
target=recipient,
|
|
235
|
+
content=_text(getattr(message_object, "content", None)),
|
|
236
|
+
role=_text(getattr(message_object, "role", None)), task=task, received=True,
|
|
237
|
+
routing_source="metagpt.Role.put_message",
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
def observe_action(
|
|
241
|
+
self,
|
|
242
|
+
action_id: str | int,
|
|
243
|
+
*,
|
|
244
|
+
owner: EntityRef | None,
|
|
245
|
+
task: EntityRef | None = None,
|
|
246
|
+
status: str = "started",
|
|
247
|
+
**attributes: Any,
|
|
248
|
+
) -> EntityRef:
|
|
249
|
+
action = self.entity("task", action_id, name="MetaGPT action", attributes={"provider": "metagpt", "action": True, **attributes})
|
|
250
|
+
event = "TASK_STARTED" if status == "started" else "TASK_COMPLETED" if status == "completed" else "TASK_FAILED" if status == "failed" else "TASK_UPDATED"
|
|
251
|
+
self.emit(event, event, source=owner, target=action, attributes={"action_id": action.id, "task_id": task.id if task else None, **attributes})
|
|
252
|
+
return action
|
|
253
|
+
|
|
254
|
+
def observe_action_object(self, action_object: Any, *, owner: EntityRef | None, task: EntityRef | None = None, status: str = "started", **attributes: Any) -> EntityRef:
|
|
255
|
+
action_id = getattr(action_object, "name", None) or type(action_object).__name__
|
|
256
|
+
return self.observe_action(action_id, owner=owner, task=task, status=status, action_type=type(action_object).__name__, **attributes)
|
|
257
|
+
|
|
258
|
+
def observe_model_call(
|
|
259
|
+
self,
|
|
260
|
+
call_id: str | int,
|
|
261
|
+
*,
|
|
262
|
+
role: EntityRef | None,
|
|
263
|
+
model_id: str | int,
|
|
264
|
+
request: Any | None = None,
|
|
265
|
+
response: Any | None = None,
|
|
266
|
+
status: str = "request",
|
|
267
|
+
**attributes: Any,
|
|
268
|
+
) -> EntityRef:
|
|
269
|
+
model = self.model(model_id, provider="metagpt", **attributes)
|
|
270
|
+
call = self.entity("model_call", call_id, name="MetaGPT model call", attributes={"provider": "metagpt"})
|
|
271
|
+
self.context.record_model_call(
|
|
272
|
+
ModelCallRecord(
|
|
273
|
+
call,
|
|
274
|
+
role,
|
|
275
|
+
model,
|
|
276
|
+
request=request,
|
|
277
|
+
response=response,
|
|
278
|
+
status=status,
|
|
279
|
+
content_kind="model_request" if status == "request" else "model_response",
|
|
280
|
+
attributes=attributes,
|
|
281
|
+
)
|
|
282
|
+
)
|
|
283
|
+
return call
|
|
284
|
+
|
|
285
|
+
def observe_parser_failure(
|
|
286
|
+
self,
|
|
287
|
+
failure_id: str | int,
|
|
288
|
+
*,
|
|
289
|
+
role: EntityRef | None,
|
|
290
|
+
error: str,
|
|
291
|
+
task: EntityRef | None = None,
|
|
292
|
+
**attributes: Any,
|
|
293
|
+
) -> EntityRef:
|
|
294
|
+
failure = self.entity("parser_failure", failure_id, name="MetaGPT structured-output parser failure", attributes={"provider": "metagpt"})
|
|
295
|
+
self.emit("TASK_FAILED", "PARSER_FAILURE", source=role, target=failure, attributes={"task_id": task.id if task else None, "error": error, **attributes})
|
|
296
|
+
return failure
|
|
297
|
+
|
|
298
|
+
def observe_retry(
|
|
299
|
+
self,
|
|
300
|
+
retry_id: str | int,
|
|
301
|
+
*,
|
|
302
|
+
role: EntityRef | None,
|
|
303
|
+
task: EntityRef | None = None,
|
|
304
|
+
**attributes: Any,
|
|
305
|
+
) -> EntityRef:
|
|
306
|
+
retry = self.entity("task", retry_id, name="MetaGPT retry", attributes={"provider": "metagpt", "retry": True})
|
|
307
|
+
self.emit("TASK_UPDATED", "RETRY_REQUESTED", source=role, target=retry, attributes={"task_id": task.id if task else None, **attributes})
|
|
308
|
+
return retry
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def _text(value: Any) -> str | None:
|
|
312
|
+
if value is None:
|
|
313
|
+
return None
|
|
314
|
+
text = str(value).strip()
|
|
315
|
+
return text or None
|