feat: add workflow action outcomes and tracing

This commit is contained in:
Xin Wang
2026-08-01 11:21:31 +08:00
parent ad5ff061bb
commit b747144ff1
13 changed files with 558 additions and 32 deletions

View File

@@ -2,8 +2,11 @@
from __future__ import annotations
import json
import re
from copy import deepcopy
from dataclasses import dataclass
from hashlib import sha256
from typing import Any
from services.node_specs import normalize_graph
@@ -32,6 +35,7 @@ class AgentStageConfig:
class WorkflowEngine:
def __init__(self, graph: dict[str, Any]):
self.graph = normalize_graph(graph)
self.revision = self._revision_for(self.graph)
self.settings = self.graph.get("settings") or {}
self.nodes: dict[str, dict] = {
str(node["id"]): node
@@ -48,6 +52,29 @@ class WorkflowEngine:
None,
)
@staticmethod
def _revision_for(normalized_graph: dict[str, Any]) -> str:
"""Hash the exact normalized graph used by this runtime."""
canonical = json.dumps(
normalized_graph,
ensure_ascii=False,
sort_keys=True,
separators=(",", ":"),
).encode("utf-8")
return f"sha256:{sha256(canonical).hexdigest()}"
def session_metadata(self) -> dict[str, Any]:
"""Pin a conversation to an immutable, inspectable graph snapshot."""
return {
"workflow": {
"revision": self.revision,
"specVersion": self.graph.get("specVersion"),
"snapshot": deepcopy(self.graph),
}
}
def has_graph(self) -> bool:
return bool(self.start_id)