node_entities.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from collections.abc import Mapping
  2. from enum import StrEnum
  3. from typing import Any, Optional
  4. from pydantic import BaseModel
  5. from core.model_runtime.entities.llm_entities import LLMUsage
  6. from models.workflow import WorkflowNodeExecutionStatus
  7. class NodeRunMetadataKey(StrEnum):
  8. """
  9. Node Run Metadata Key.
  10. """
  11. TOTAL_TOKENS = "total_tokens"
  12. TOTAL_PRICE = "total_price"
  13. CURRENCY = "currency"
  14. TOOL_INFO = "tool_info"
  15. AGENT_LOG = "agent_log"
  16. ITERATION_ID = "iteration_id"
  17. ITERATION_INDEX = "iteration_index"
  18. PARALLEL_ID = "parallel_id"
  19. PARALLEL_START_NODE_ID = "parallel_start_node_id"
  20. PARENT_PARALLEL_ID = "parent_parallel_id"
  21. PARENT_PARALLEL_START_NODE_ID = "parent_parallel_start_node_id"
  22. PARALLEL_MODE_RUN_ID = "parallel_mode_run_id"
  23. ITERATION_DURATION_MAP = "iteration_duration_map" # single iteration duration if iteration node runs
  24. ERROR_STRATEGY = "error_strategy" # node in continue on error mode return the field
  25. class NodeRunResult(BaseModel):
  26. """
  27. Node Run Result.
  28. """
  29. status: WorkflowNodeExecutionStatus = WorkflowNodeExecutionStatus.RUNNING
  30. inputs: Optional[Mapping[str, Any]] = None # node inputs
  31. process_data: Optional[Mapping[str, Any]] = None # process data
  32. outputs: Optional[Mapping[str, Any]] = None # node outputs
  33. metadata: Optional[Mapping[NodeRunMetadataKey, Any]] = None # node metadata
  34. llm_usage: Optional[LLMUsage] = None # llm usage
  35. edge_source_handle: Optional[str] = None # source handle id of node with multiple branches
  36. error: Optional[str] = None # error message if status is failed
  37. error_type: Optional[str] = None # error type if status is failed
  38. # single step node run retry
  39. retry_index: int = 0
  40. class AgentNodeStrategyInit(BaseModel):
  41. name: str
  42. icon: str | None = None