-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathagent_configs.py
More file actions
87 lines (71 loc) · 3.04 KB
/
Copy pathagent_configs.py
File metadata and controls
87 lines (71 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from __future__ import annotations
from pydantic import Field, BaseModel, field_validator, model_validator
class TemporalWorkflowConfig(BaseModel):
"""
Configuration for the temporal workflow that defines the agent.
Attributes:
name: The name of the temporal workflow that defines the agent.
queue_name: The name of the temporal queue to send tasks to.
"""
name: str = Field(
..., description="The name of the temporal workflow that defines the agent."
)
queue_name: str = Field(
..., description="The name of the temporal queue to send tasks to."
)
# TODO: Remove this class when we remove the agentex agents create
class TemporalWorkerConfig(BaseModel):
"""
Configuration for temporal worker deployment
Attributes:
image: The image to use for the temporal worker
workflow: The temporal workflow configuration
"""
image: str | None = Field(
default=None, description="Image to use for the temporal worker"
)
workflow: TemporalWorkflowConfig | None = Field(
default=None,
description="Configuration for the temporal workflow that defines the agent. Only required for agents that leverage Temporal.",
)
class TemporalConfig(BaseModel):
"""
Simplified temporal configuration for agents
Attributes:
enabled: Whether this agent uses Temporal workflows
workflow: The temporal workflow configuration
workflows: The list of temporal workflow configurations
health_check_port: Port for temporal worker health check endpoint
"""
enabled: bool = Field(
default=False, description="Whether this agent uses Temporal workflows"
)
workflow: TemporalWorkflowConfig | None = Field(
default=None,
description="Temporal workflow configuration. Required when enabled=True. (deprecated: use workflows instead)",
)
workflows: list[TemporalWorkflowConfig] | None = Field(
default=None,
description="List of temporal workflow configurations. Used when enabled=true.",
)
health_check_port: int | None = Field(
default=None,
description="Port for temporal worker health check endpoint. Defaults to 80 if not specified.",
)
@field_validator("workflows")
@classmethod
def validate_workflows_not_empty(cls, v):
"""Ensure workflows list is not empty when provided"""
if v is not None and len(v) == 0:
raise ValueError("workflows list cannot be empty when provided")
return v
@model_validator(mode="after")
def validate_temporal_config_when_enabled(self):
"""Validate that workflow configuration exists when enabled=true"""
if self.enabled:
# Must have either workflow (legacy) or workflows (new)
if not self.workflow and (not self.workflows or len(self.workflows) == 0):
raise ValueError(
"When temporal.enabled=true, either 'workflow' or 'workflows' must be provided and non-empty"
)
return self