workflow-exec-engine 0.1.1__tar.gz → 0.1.2__tar.gz

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 (53) hide show
  1. workflow_exec_engine-0.1.2/MANIFEST.in +8 -0
  2. {workflow_exec_engine-0.1.1/workflow_exec_engine.egg-info → workflow_exec_engine-0.1.2}/PKG-INFO +6 -3
  3. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/README.md +2 -2
  4. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/pyproject.toml +5 -0
  5. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/__init__.py +4 -1
  6. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/client/a2a_transport.py +3 -0
  7. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/client/engine_client.py +14 -7
  8. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/client/sensitive_data.py +32 -0
  9. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/core/executor.py +29 -8
  10. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/core/models.py +39 -1
  11. workflow_exec_engine-0.1.2/workflow_engine/observation.py +949 -0
  12. workflow_exec_engine-0.1.2/workflow_engine/observation_content.py +269 -0
  13. workflow_exec_engine-0.1.2/workflow_engine/observation_spool.py +38 -0
  14. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/registry/http_auth.py +69 -19
  15. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/registry/registry_client.py +8 -1
  16. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/runner.py +66 -35
  17. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2/workflow_exec_engine.egg-info}/PKG-INFO +6 -3
  18. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_exec_engine.egg-info/SOURCES.txt +3 -2
  19. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_exec_engine.egg-info/requires.txt +4 -0
  20. workflow_exec_engine-0.1.1/MANIFEST.in +0 -4
  21. workflow_exec_engine-0.1.1/examples/execute_psop_demo.py +0 -90
  22. workflow_exec_engine-0.1.1/examples/quickstart.py +0 -109
  23. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/LICENSE +0 -0
  24. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/README_en.md +0 -0
  25. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/requirements.txt +0 -0
  26. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/setup.cfg +0 -0
  27. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/client/__init__.py +0 -0
  28. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/client/a2at_messages.py +0 -0
  29. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/client/agentcard_normalizer.py +0 -0
  30. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/client/auth_manager.py +0 -0
  31. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/client/auth_provider.py +0 -0
  32. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/client/credential_crypto.py +0 -0
  33. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/client/credential_service.py +0 -0
  34. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/client/env_file_loader.py +0 -0
  35. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/client/extension_interceptor.py +0 -0
  36. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/client/extension_sender.py +0 -0
  37. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/client/extensions.py +0 -0
  38. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/client/protocol_interceptor.py +0 -0
  39. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/client/protocol_logger.py +0 -0
  40. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/client/remote_error.py +0 -0
  41. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/client/sse_normalization.py +0 -0
  42. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/client/ssl_context.py +0 -0
  43. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/client/stub_engine_client.py +0 -0
  44. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/client/transport_activity.py +0 -0
  45. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/control/__init__.py +0 -0
  46. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/control/control_points.py +0 -0
  47. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/core/__init__.py +0 -0
  48. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/core/context_builder.py +0 -0
  49. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/core/failure_mapping.py +0 -0
  50. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/core/workflow_validator.py +0 -0
  51. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_engine/registry/__init__.py +0 -0
  52. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_exec_engine.egg-info/dependency_links.txt +0 -0
  53. {workflow_exec_engine-0.1.1 → workflow_exec_engine-0.1.2}/workflow_exec_engine.egg-info/top_level.txt +0 -0
@@ -0,0 +1,8 @@
1
+ include README.md
2
+ include README_en.md
3
+ include requirements.txt
4
+
5
+ # examples/ and samples/ are auxiliary test material, not part of the SDK
6
+ # distribution. Keep them out of the sdist as well as the wheel.
7
+ prune examples
8
+ prune samples
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: workflow-exec-engine
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Standalone workflow execution SDK for A2A-T multi-agent orchestration
5
5
  Author-email: A2A SDK Team <ivo.zhou@huawei.com>
6
6
  License-Expression: Apache-2.0
@@ -30,6 +30,9 @@ Provides-Extra: dev
30
30
  Requires-Dist: build>=1.2.0; extra == "dev"
31
31
  Requires-Dist: pytest>=8.0.0; extra == "dev"
32
32
  Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
33
+ Provides-Extra: samples
34
+ Requires-Dist: fastapi>=0.115.0; extra == "samples"
35
+ Requires-Dist: uvicorn>=0.30.0; extra == "samples"
33
36
  Dynamic: license-file
34
37
 
35
38
  # A2A-T Workflow Engine SDK(Python)
@@ -189,8 +192,8 @@ Bearer Token;OAuth2 的申请、刷新由业务已有认证库完成,也可
189
192
  后重试一次。注册中心操作不自动重放。认证头不允许重复名称、换行或覆盖 Host 等传输头。
190
193
  中心地址支持部署路径前缀,账号令牌仍限定在该前缀下的公开编排 API。
191
194
 
192
- 源码版本现为 `0.1.1`,包含已发布 `0.1.0` 之后的主干修复。发布前可运行
193
- `python -m build` 后安装 `dist/workflow_exec_engine-0.1.1-py3-none-any.whl`;
195
+ 源码版本现为 `0.1.2`,包含已发布 `0.1.1` 之后的主干变更。发布前可运行
196
+ `python -m build` 后安装 `dist/workflow_exec_engine-0.1.2-py3-none-any.whl`;
194
197
  此说明不代表该版本已发布到 PyPI。
195
198
 
196
199
  ## 文档与验证
@@ -155,8 +155,8 @@ Bearer Token;OAuth2 的申请、刷新由业务已有认证库完成,也可
155
155
  后重试一次。注册中心操作不自动重放。认证头不允许重复名称、换行或覆盖 Host 等传输头。
156
156
  中心地址支持部署路径前缀,账号令牌仍限定在该前缀下的公开编排 API。
157
157
 
158
- 源码版本现为 `0.1.1`,包含已发布 `0.1.0` 之后的主干修复。发布前可运行
159
- `python -m build` 后安装 `dist/workflow_exec_engine-0.1.1-py3-none-any.whl`;
158
+ 源码版本现为 `0.1.2`,包含已发布 `0.1.1` 之后的主干变更。发布前可运行
159
+ `python -m build` 后安装 `dist/workflow_exec_engine-0.1.2-py3-none-any.whl`;
160
160
  此说明不代表该版本已发布到 PyPI。
161
161
 
162
162
  ## 文档与验证
@@ -38,6 +38,11 @@ dev = [
38
38
  "pytest>=8.0.0",
39
39
  "pytest-asyncio>=0.23.0",
40
40
  ]
41
+ # The embedded-agent demo and the scenario run test start A2A HTTP servers.
42
+ samples = [
43
+ "fastapi>=0.115.0",
44
+ "uvicorn>=0.30.0",
45
+ ]
41
46
 
42
47
  [project.urls]
43
48
  Homepage = "https://github.com/project-openan/workflow-engine-sdk-python"
@@ -73,8 +73,11 @@ from workflow_engine.control import (
73
73
  )
74
74
  from workflow_engine.registry import RegistryClient, load_psop, search_psop, BearerAuth, HttpAuthProvider, OrchestrationAccountAuth
75
75
  from workflow_engine.runner import execute_psop
76
+ from workflow_engine.observation import CenterExecutionReporting, ExecutionReporter
76
77
 
77
78
  __all__ = [
79
+ "CenterExecutionReporting",
80
+ "ExecutionReporter",
78
81
  # Core
79
82
  "Workflow", "WorkflowStep", "Task", "JumpCondition",
80
83
  "StepType", "TaskStatus", "ExecutionResult",
@@ -99,4 +102,4 @@ __all__ = [
99
102
  "execute_psop",
100
103
  ]
101
104
 
102
- __version__ = "0.1.1"
105
+ __version__ = "0.1.2"
@@ -507,12 +507,14 @@ class A2ATransport:
507
507
  "TASK_STATE_COMPLETED", "TASK_STATE_FAILED",
508
508
  "TASK_STATE_CANCELED", "TASK_STATE_REJECTED",
509
509
  ),
510
+ "text": self._extract_message_text(update.status.message, None) or "",
510
511
  "metadata": self._struct_dict(update.metadata),
511
512
  })
512
513
 
513
514
  elif has_artifact:
514
515
  update = response.artifact_update
515
516
  artifact = self._received_artifact(update.artifact)
517
+ chunk_text = self._text_from_artifacts({artifact.artifact_id: artifact})
516
518
  previous = task_artifacts.get(artifact.artifact_id)
517
519
  if getattr(update, "append", False) and previous is not None:
518
520
  artifact = ReceivedArtifact(
@@ -531,6 +533,7 @@ class A2ATransport:
531
533
  "artifact_name": artifact.name,
532
534
  "append": getattr(update, "append", False),
533
535
  "last_chunk": getattr(update, "last_chunk", False),
536
+ "text": chunk_text or "",
534
537
  "metadata": dict(artifact.metadata),
535
538
  })
536
539
 
@@ -195,6 +195,7 @@ class WorkflowEngineClient:
195
195
  if interaction["negotiation_started"]:
196
196
  self._emit(EventType.NEGOTIATION_FAILED, {
197
197
  "agent": request.agent_name,
198
+ "task_id": request.task_id,
198
199
  "error": str(exc),
199
200
  "error_type": type(exc).__name__,
200
201
  })
@@ -243,6 +244,7 @@ class WorkflowEngineClient:
243
244
  result.failure_message = "Business sent Abort; task was not completed successfully"
244
245
  self._emit(EventType.AGENT_RESPONSE, {
245
246
  "agent": request.agent_name,
247
+ "task_id": request.task_id,
246
248
  "response": result.text,
247
249
  "received_messages": result.received_messages,
248
250
  })
@@ -272,7 +274,7 @@ class WorkflowEngineClient:
272
274
  )
273
275
  if candidate is None:
274
276
  return await self._finish_remote_result(
275
- request.agent_name, result, interaction,
277
+ request, result, interaction,
276
278
  )
277
279
  interaction["negotiation_started"] = True
278
280
  if exchange_number >= self._max_negotiation_exchanges:
@@ -309,7 +311,7 @@ class WorkflowEngineClient:
309
311
  continue
310
312
  if result.task_state != "TASK_STATE_INPUT_REQUIRED":
311
313
  return await self._finish_remote_result(
312
- request.agent_name, result, interaction,
314
+ request, result, interaction,
313
315
  )
314
316
  received = self._negotiation_response(result)
315
317
  context = self._negotiation_context(received)
@@ -328,6 +330,7 @@ class WorkflowEngineClient:
328
330
  )
329
331
  self._emit(EventType.NEGOTIATION_REQUEST, {
330
332
  "agent": request.agent_name, "request": request_model,
333
+ "task_id": request.task_id,
331
334
  "exchange": exchange_number + 1,
332
335
  })
333
336
  remaining = deadline - time.monotonic()
@@ -344,6 +347,7 @@ class WorkflowEngineClient:
344
347
  exchanges.append(NegotiationExchange(received, reply))
345
348
  self._emit(EventType.NEGOTIATION_RESOLVED, {
346
349
  "agent": request.agent_name, "exchange": exchange_number + 1,
350
+ "task_id": request.task_id,
347
351
  "reply": reply,
348
352
  })
349
353
  current_content = reply.content
@@ -356,13 +360,13 @@ class WorkflowEngineClient:
356
360
 
357
361
  async def _finish_remote_result(
358
362
  self,
359
- agent_name: str,
363
+ request: TaskRequest,
360
364
  result: SendMessageResult,
361
365
  interaction: dict[str, Any],
362
366
  ) -> SendMessageResult:
363
367
  interaction["terminal"] = result.is_terminal
364
368
  if result.task is not None and not result.is_terminal:
365
- await self._cancel_abandoned_interaction(agent_name, interaction)
369
+ await self._cancel_abandoned_interaction(request.agent_name, interaction)
366
370
  if result.failure_code is None:
367
371
  result.failure_code = "a2a.unsupported_task_state"
368
372
  result.failure_message = (
@@ -370,7 +374,8 @@ class WorkflowEngineClient:
370
374
  f"{result.task_state or 'unknown'}"
371
375
  )
372
376
  self._emit(EventType.AGENT_RESPONSE, {
373
- "agent": agent_name,
377
+ "agent": request.agent_name,
378
+ "task_id": request.task_id,
374
379
  "response": result.text,
375
380
  "received_messages": result.received_messages,
376
381
  })
@@ -431,7 +436,9 @@ class WorkflowEngineClient:
431
436
  consumed is a recovery candidate, because a transport may surface a
432
437
  dropped connection as any exception class at all.
433
438
  """
434
- self._emit(EventType.AGENT_REQUEST, {"agent": request.agent_name, "content": content})
439
+ self._emit(EventType.AGENT_REQUEST, {
440
+ "agent": request.agent_name, "task_id": request.task_id, "content": content,
441
+ })
435
442
  self._transport.validate_content_extensions(card, content)
436
443
  client = self._transport.client_for(request.agent_name)
437
444
  send_request = self._transport.build_send_request(content, context_id, remote_task_id)
@@ -443,7 +450,7 @@ class WorkflowEngineClient:
443
450
  revealed = data.get("task_id")
444
451
  if revealed:
445
452
  interaction["remote_task_id"] = revealed
446
- self._forward_intermediate_event(event_type, data)
453
+ self._forward_intermediate_event(event_type, {**data, "logical_task_id": request.task_id})
447
454
 
448
455
  try:
449
456
  return await asyncio.wait_for(
@@ -32,6 +32,25 @@ _JSON_SECRET = re.compile(
32
32
  r'("(?:[^"\\]|\\.)*"|\{[^{}]*\}|\[[^\[\]]*\]|[^,}\]\s]+)'
33
33
  )
34
34
 
35
+ #: Every word a rule above can match. Scanning for these first keeps a long payload that holds no
36
+ #: credential cheap: without it, the rules try to match at every position and a 30 KB value costs
37
+ #: seconds, which matters because logging and reporting redact every payload they see.
38
+ _NEEDLES = (
39
+ "password", "passwd", "pwd", "token", "secret", "apikey", "api_key", "api-key",
40
+ "accesssession", "access_session", "access-session", "authorization", "bearer", "basic",
41
+ "cookie",
42
+ )
43
+
44
+
45
+ def _may_hold_credential(text: str) -> bool:
46
+ """Whether any redaction rule could match this text.
47
+
48
+ A plain scan costs microseconds; the rules cost quadratic time on a payload that contains no
49
+ keyword at all, which is the common case for a large business value.
50
+ """
51
+ lowered = text.lower()
52
+ return any(needle in lowered for needle in _NEEDLES)
53
+
35
54
 
36
55
  def _sensitive_key(name: str) -> bool:
37
56
  normalized = name.lower().replace("-", "").replace("_", "")
@@ -56,6 +75,8 @@ def redact(text: str | None) -> str:
56
75
  """Hide standard credential forms while leaving other business text readable."""
57
76
  if text is None:
58
77
  return ""
78
+ if not _may_hold_credential(text):
79
+ return text
59
80
  try:
60
81
  parsed = json.loads(text)
61
82
  except (TypeError, ValueError):
@@ -63,3 +84,14 @@ def redact(text: str | None) -> str:
63
84
  else:
64
85
  cleaned = json.dumps(_redact_tree(parsed), ensure_ascii=False)
65
86
  return _AUTH_VALUE.sub(r"\1***", _FORM_SECRET.sub(r"\1***", cleaned))
87
+
88
+
89
+ def sensitive_key(name: str) -> bool:
90
+ """Whether a field name is a standard credential name, and so never worth reporting.
91
+
92
+ This recognises naming conventions only. It cannot tell whether an arbitrary business field
93
+ such as a customer phone number or a private key payload is approved for disclosure, which is
94
+ why reporting keeps structured outputs out unless the application names them.
95
+ """
96
+ return _sensitive_key(name)
97
+
@@ -256,6 +256,10 @@ class WorkflowExecutor:
256
256
  if not isinstance(result, TaskResult):
257
257
  raise TypeError("on_self_task must return TaskResult")
258
258
  except asyncio.CancelledError:
259
+ # A started task that is cancelled still owes its terminal events, so that no task
260
+ # is ever left without an end. It produced no result, so it takes no place in the
261
+ # run's.
262
+ self._report_cancelled(step, task, index, request)
259
263
  raise
260
264
  except Exception as exc:
261
265
  result = failure_to_task_result(exc)
@@ -273,19 +277,36 @@ class WorkflowExecutor:
273
277
  error_code=result.error_code,
274
278
  error_details=result.error_details,
275
279
  )
276
- history = {
280
+ history = self._task_history(step, index, task, request, result)
281
+ self.execution_history.append(history)
282
+ self._emit_event(EventType.TASK_STATUS_CHANGED, self._task_status(step, index, task, request))
283
+ self._emit_event(EventType.TASK_RESPONSE, history)
284
+ return task.description, index, execution_result
285
+
286
+ def _report_cancelled(self, step: WorkflowStep, task: Task, index: int, request) -> None:
287
+ """End a started task that was cancelled, with the engine's cancellation failure."""
288
+ task.status = TaskStatus.CANCELLED
289
+ self._emit_event(EventType.TASK_STATUS_CHANGED, self._task_status(step, index, task, request))
290
+ self._emit_event(
291
+ EventType.TASK_RESPONSE,
292
+ self._task_history(step, index, task, request, failure_to_task_result(asyncio.CancelledError())),
293
+ )
294
+
295
+ @staticmethod
296
+ def _task_status(step: WorkflowStep, index: int, task: Task, request) -> dict:
297
+ return {
298
+ "step": step.name, "subtask_index": index,
299
+ "agent": task.agent, "status": task.status.value, "task_id": request.task_id,
300
+ }
301
+
302
+ @staticmethod
303
+ def _task_history(step: WorkflowStep, index: int, task: Task, request, result: TaskResult) -> dict:
304
+ return {
277
305
  "step": step.name, "subtask_index": index, "task": task.description,
278
306
  "agent": task.agent, "status": task.status.value, "task_id": request.task_id,
279
307
  "outputs": result.outputs, "error": result.error or "",
280
308
  "error_code": result.error_code or "", "error_details": result.error_details,
281
309
  }
282
- self.execution_history.append(history)
283
- self._emit_event(EventType.TASK_STATUS_CHANGED, {
284
- "step": step.name, "subtask_index": index,
285
- "agent": task.agent, "status": task.status.value,
286
- })
287
- self._emit_event(EventType.TASK_RESPONSE, history)
288
- return task.description, index, execution_result
289
310
 
290
311
  @staticmethod
291
312
  def _protocol_result(result: SendMessageResult) -> TaskResult:
@@ -60,6 +60,8 @@ class TaskStatus(Enum):
60
60
  RUNNING = "running"
61
61
  SUCCESS = "success"
62
62
  FAILED = "failed"
63
+ #: The task was started and then cancelled before it produced a result.
64
+ CANCELLED = "cancelled"
63
65
 
64
66
 
65
67
  @dataclass(frozen=True)
@@ -264,6 +266,12 @@ class Workflow:
264
266
  name: str = ""
265
267
  description: str = ""
266
268
  steps: list[WorkflowStep] = field(default_factory=list)
269
+ revision: str | None = None
270
+ # Both fields below are handed out by the center with the PSOP: the immutable revision the
271
+ # workflow was published under, and the identity this account may report executions as.
272
+ reporting_source: str | None = None
273
+ # The registered host this PSOP declares as its executor, when it names one.
274
+ workflow_host: str | None = None
267
275
 
268
276
  @classmethod
269
277
  def from_dict(cls, data: Mapping[str, Any]) -> "Workflow":
@@ -305,11 +313,41 @@ class Workflow:
305
313
  context_from=context_from,
306
314
  step_type=StepType.from_value(raw_step.get("step_type", raw_step.get("type"))),
307
315
  ))
316
+ host = data.get("workflow_host")
317
+ if host is not None and not isinstance(host, str):
318
+ raise ValueError("workflow_host must be a string")
308
319
  return cls(
309
320
  id=data.get("id", ""), name=data.get("name", ""),
310
- description=data.get("description", ""), steps=steps,
321
+ description=data.get("description", ""), steps=steps, revision=data.get("revision"),
322
+ reporting_source=data.get("execution_reporting_source"),
323
+ workflow_host=host,
311
324
  )
312
325
 
326
+ def declared_host(self) -> str | None:
327
+ """The host this PSOP declares as its executor, or ``None`` when it declares none.
328
+
329
+ A definition names its host directly with ``workflow_host``. Older ones only name the
330
+ agent that runs their local (``SelfLoop``) tasks, which the center reads as the host.
331
+ Both are honoured, so a host that selects a PSOP for itself sees the same host the
332
+ center would dispatch to. A definition that names more than one host is refused, as it
333
+ is by the center.
334
+
335
+ Raises:
336
+ ValueError: if the definition names more than one host.
337
+ """
338
+ names = [
339
+ task.agent.strip()
340
+ for step in self.steps if step.step_type == StepType.SELF_LOOP
341
+ for task in step.subtasks if task.agent and task.agent.strip()
342
+ ]
343
+ if self.workflow_host and self.workflow_host.strip():
344
+ names.append(self.workflow_host.strip())
345
+ hosts = list(dict.fromkeys(names))
346
+ if len(hosts) > 1:
347
+ raise ValueError("workflow_host and SelfLoop tasks must identify one host, not "
348
+ f"{hosts}")
349
+ return hosts[0] if hosts else None
350
+
313
351
  @classmethod
314
352
  def from_json(cls, json_str: str) -> "Workflow":
315
353
  return cls.from_dict(json.loads(json_str))