node_entities.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. LOOP_ID = "loop_id"
  19. LOOP_INDEX = "loop_index"
  20. PARALLEL_ID = "parallel_id"
  21. PARALLEL_START_NODE_ID = "parallel_start_node_id"
  22. PARENT_PARALLEL_ID = "parent_parallel_id"
  23. PARENT_PARALLEL_START_NODE_ID = "parent_parallel_start_node_id"
  24. PARALLEL_MODE_RUN_ID = "parallel_mode_run_id"
  25. ITERATION_DURATION_MAP = "iteration_duration_map" # single iteration duration if iteration node runs
  26. LOOP_DURATION_MAP = "loop_duration_map" # single loop duration if loop node runs
  27. ERROR_STRATEGY = "error_strategy" # node in continue on error mode return the field
  28. class NodeRunResult(BaseModel):
  29. """
  30. Node Run Result.
  31. """
  32. status: WorkflowNodeExecutionStatus = WorkflowNodeExecutionStatus.RUNNING
  33. inputs: Optional[Mapping[str, Any]] = None # node inputs
  34. process_data: Optional[Mapping[str, Any]] = None # process data
  35. outputs: Optional[Mapping[str, Any]] = None # node outputs
  36. metadata: Optional[Mapping[NodeRunMetadataKey, Any]] = None # node metadata
  37. llm_usage: Optional[LLMUsage] = None # llm usage
  38. edge_source_handle: Optional[str] = None # source handle id of node with multiple branches
  39. error: Optional[str] = None # error message if status is failed
  40. error_type: Optional[str] = None # error type if status is failed
  41. # single step node run retry
  42. retry_index: int = 0
  43. class AgentNodeStrategyInit(BaseModel):
  44. name: str
  45. icon: str | None = None