puffinflow 2.dev0__py3-none-any.whl
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.
- puffinflow/__init__.py +132 -0
- puffinflow/core/__init__.py +110 -0
- puffinflow/core/agent/__init__.py +320 -0
- puffinflow/core/agent/base.py +1635 -0
- puffinflow/core/agent/checkpoint.py +50 -0
- puffinflow/core/agent/context.py +521 -0
- puffinflow/core/agent/decorators/__init__.py +90 -0
- puffinflow/core/agent/decorators/builder.py +454 -0
- puffinflow/core/agent/decorators/flexible.py +714 -0
- puffinflow/core/agent/decorators/inspection.py +144 -0
- puffinflow/core/agent/dependencies.py +57 -0
- puffinflow/core/agent/scheduling/__init__.py +21 -0
- puffinflow/core/agent/scheduling/builder.py +160 -0
- puffinflow/core/agent/scheduling/exceptions.py +35 -0
- puffinflow/core/agent/scheduling/inputs.py +137 -0
- puffinflow/core/agent/scheduling/parser.py +209 -0
- puffinflow/core/agent/scheduling/scheduler.py +413 -0
- puffinflow/core/agent/state.py +141 -0
- puffinflow/core/config.py +62 -0
- puffinflow/core/coordination/__init__.py +137 -0
- puffinflow/core/coordination/agent_group.py +359 -0
- puffinflow/core/coordination/agent_pool.py +629 -0
- puffinflow/core/coordination/agent_team.py +577 -0
- puffinflow/core/coordination/coordinator.py +720 -0
- puffinflow/core/coordination/deadlock.py +1759 -0
- puffinflow/core/coordination/fluent_api.py +421 -0
- puffinflow/core/coordination/primitives.py +478 -0
- puffinflow/core/coordination/rate_limiter.py +520 -0
- puffinflow/core/observability/__init__.py +47 -0
- puffinflow/core/observability/agent.py +139 -0
- puffinflow/core/observability/alerting.py +73 -0
- puffinflow/core/observability/config.py +127 -0
- puffinflow/core/observability/context.py +88 -0
- puffinflow/core/observability/core.py +147 -0
- puffinflow/core/observability/decorators.py +105 -0
- puffinflow/core/observability/events.py +71 -0
- puffinflow/core/observability/interfaces.py +196 -0
- puffinflow/core/observability/metrics.py +137 -0
- puffinflow/core/observability/tracing.py +209 -0
- puffinflow/core/reliability/__init__.py +27 -0
- puffinflow/core/reliability/bulkhead.py +96 -0
- puffinflow/core/reliability/circuit_breaker.py +149 -0
- puffinflow/core/reliability/leak_detector.py +122 -0
- puffinflow/core/resources/__init__.py +77 -0
- puffinflow/core/resources/allocation.py +790 -0
- puffinflow/core/resources/pool.py +645 -0
- puffinflow/core/resources/quotas.py +567 -0
- puffinflow/core/resources/requirements.py +217 -0
- puffinflow/version.py +21 -0
- puffinflow-2.dev0.dist-info/METADATA +334 -0
- puffinflow-2.dev0.dist-info/RECORD +55 -0
- puffinflow-2.dev0.dist-info/WHEEL +5 -0
- puffinflow-2.dev0.dist-info/entry_points.txt +3 -0
- puffinflow-2.dev0.dist-info/licenses/LICENSE +21 -0
- puffinflow-2.dev0.dist-info/top_level.txt +1 -0
puffinflow/__init__.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"""
|
|
2
|
+
PuffinFlow - Workflow Orchestration Framework.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
__version__ = "0.1.dev12+g0f61537.d20250701"
|
|
6
|
+
__author__ = "Mohamed Ahmed"
|
|
7
|
+
__email__ = "mohamed.ahmed.4894@gmail.com"
|
|
8
|
+
|
|
9
|
+
# Core agent functionality
|
|
10
|
+
from .core.agent import (
|
|
11
|
+
Agent,
|
|
12
|
+
AgentCheckpoint,
|
|
13
|
+
AgentResult,
|
|
14
|
+
AgentStatus,
|
|
15
|
+
Context,
|
|
16
|
+
Priority,
|
|
17
|
+
StateBuilder,
|
|
18
|
+
StateResult,
|
|
19
|
+
StateStatus,
|
|
20
|
+
build_state,
|
|
21
|
+
cpu_intensive,
|
|
22
|
+
critical_state,
|
|
23
|
+
gpu_accelerated,
|
|
24
|
+
io_intensive,
|
|
25
|
+
memory_intensive,
|
|
26
|
+
network_intensive,
|
|
27
|
+
state,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
# Configuration
|
|
31
|
+
from .core.config import Features, Settings, get_features, get_settings
|
|
32
|
+
|
|
33
|
+
# Enhanced coordination
|
|
34
|
+
from .core.coordination import (
|
|
35
|
+
AgentGroup,
|
|
36
|
+
AgentOrchestrator,
|
|
37
|
+
AgentPool,
|
|
38
|
+
Agents,
|
|
39
|
+
AgentTeam,
|
|
40
|
+
DynamicProcessingPool,
|
|
41
|
+
EventBus,
|
|
42
|
+
ParallelAgentGroup,
|
|
43
|
+
TeamResult,
|
|
44
|
+
WorkItem,
|
|
45
|
+
WorkQueue,
|
|
46
|
+
create_pipeline,
|
|
47
|
+
create_team,
|
|
48
|
+
run_agents_parallel,
|
|
49
|
+
run_agents_sequential,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
# Reliability patterns
|
|
53
|
+
from .core.reliability import (
|
|
54
|
+
Bulkhead,
|
|
55
|
+
BulkheadConfig,
|
|
56
|
+
CircuitBreaker,
|
|
57
|
+
CircuitBreakerConfig,
|
|
58
|
+
ResourceLeakDetector,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
# Resource management
|
|
62
|
+
from .core.resources import (
|
|
63
|
+
AllocationStrategy,
|
|
64
|
+
QuotaManager,
|
|
65
|
+
ResourcePool,
|
|
66
|
+
ResourceRequirements,
|
|
67
|
+
ResourceType,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
__all__ = [
|
|
71
|
+
"Agent",
|
|
72
|
+
"AgentCheckpoint",
|
|
73
|
+
"AgentGroup",
|
|
74
|
+
"AgentOrchestrator",
|
|
75
|
+
"AgentPool",
|
|
76
|
+
"AgentResult",
|
|
77
|
+
"AgentStatus",
|
|
78
|
+
"AgentTeam",
|
|
79
|
+
"Agents",
|
|
80
|
+
"AllocationStrategy",
|
|
81
|
+
"Bulkhead",
|
|
82
|
+
"BulkheadConfig",
|
|
83
|
+
"CircuitBreaker",
|
|
84
|
+
"CircuitBreakerConfig",
|
|
85
|
+
"Context",
|
|
86
|
+
"DynamicProcessingPool",
|
|
87
|
+
"EventBus",
|
|
88
|
+
"Features",
|
|
89
|
+
"ParallelAgentGroup",
|
|
90
|
+
"Priority",
|
|
91
|
+
"QuotaManager",
|
|
92
|
+
"ResourceLeakDetector",
|
|
93
|
+
"ResourcePool",
|
|
94
|
+
"ResourceRequirements",
|
|
95
|
+
"ResourceType",
|
|
96
|
+
"Settings",
|
|
97
|
+
"StateBuilder",
|
|
98
|
+
"StateResult",
|
|
99
|
+
"StateStatus",
|
|
100
|
+
"TeamResult",
|
|
101
|
+
"WorkItem",
|
|
102
|
+
"WorkQueue",
|
|
103
|
+
"build_state",
|
|
104
|
+
"cpu_intensive",
|
|
105
|
+
"create_pipeline",
|
|
106
|
+
"create_team",
|
|
107
|
+
"critical_state",
|
|
108
|
+
"get_features",
|
|
109
|
+
"get_settings",
|
|
110
|
+
"gpu_accelerated",
|
|
111
|
+
"io_intensive",
|
|
112
|
+
"memory_intensive",
|
|
113
|
+
"network_intensive",
|
|
114
|
+
"run_agents_parallel",
|
|
115
|
+
"run_agents_sequential",
|
|
116
|
+
"state",
|
|
117
|
+
]
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def get_version() -> str:
|
|
121
|
+
"""Get PuffinFlow version."""
|
|
122
|
+
return __version__
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def get_info() -> dict[str, str]:
|
|
126
|
+
"""Get PuffinFlow package information."""
|
|
127
|
+
return {
|
|
128
|
+
"version": __version__,
|
|
129
|
+
"author": __author__,
|
|
130
|
+
"email": __email__,
|
|
131
|
+
"description": "Workflow orchestration framework with advanced resource management and observability",
|
|
132
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""Workflow Orchestrator Core Engine."""
|
|
2
|
+
|
|
3
|
+
__version__ = "0.1.0"
|
|
4
|
+
|
|
5
|
+
from .agent.base import Agent
|
|
6
|
+
from .agent.context import Context
|
|
7
|
+
from .agent.state import Priority, StateStatus
|
|
8
|
+
from .resources.pool import ResourcePool
|
|
9
|
+
from .resources.requirements import (
|
|
10
|
+
ResourceRequirements,
|
|
11
|
+
ResourceType,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
# Import reliability components
|
|
15
|
+
try:
|
|
16
|
+
from .reliability.bulkhead import Bulkhead, BulkheadConfig
|
|
17
|
+
from .reliability.circuit_breaker import (
|
|
18
|
+
CircuitBreaker,
|
|
19
|
+
CircuitBreakerConfig,
|
|
20
|
+
)
|
|
21
|
+
from .reliability.leak_detector import ResourceLeakDetector
|
|
22
|
+
except ImportError:
|
|
23
|
+
# Create mock classes if reliability module is not available
|
|
24
|
+
from typing import Any
|
|
25
|
+
|
|
26
|
+
class MockCircuitBreaker:
|
|
27
|
+
def __init__(self, config: Any) -> None:
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
class MockCircuitBreakerConfig:
|
|
31
|
+
def __init__(self, **kwargs: Any) -> None:
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
class MockBulkhead:
|
|
35
|
+
def __init__(self, config: Any) -> None:
|
|
36
|
+
pass
|
|
37
|
+
|
|
38
|
+
class MockBulkheadConfig:
|
|
39
|
+
def __init__(self, **kwargs: Any) -> None:
|
|
40
|
+
pass
|
|
41
|
+
|
|
42
|
+
class MockResourceLeakDetector:
|
|
43
|
+
def __init__(self, **kwargs: Any) -> None:
|
|
44
|
+
pass
|
|
45
|
+
|
|
46
|
+
# Assign to actual names to avoid redefinition
|
|
47
|
+
CircuitBreaker = MockCircuitBreaker # type: ignore[assignment,misc]
|
|
48
|
+
CircuitBreakerConfig = MockCircuitBreakerConfig # type: ignore[assignment,misc]
|
|
49
|
+
Bulkhead = MockBulkhead # type: ignore[assignment,misc]
|
|
50
|
+
BulkheadConfig = MockBulkheadConfig # type: ignore[assignment,misc]
|
|
51
|
+
ResourceLeakDetector = MockResourceLeakDetector # type: ignore[assignment,misc]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
# Import state decorator if available
|
|
55
|
+
try:
|
|
56
|
+
from .agent.decorators.flexible import state
|
|
57
|
+
except ImportError:
|
|
58
|
+
# Create a simple mock state decorator
|
|
59
|
+
from typing import Any, Callable
|
|
60
|
+
|
|
61
|
+
def state(**kwargs: Any) -> Callable[[Callable[..., Any]], Callable[..., Any]]: # type: ignore[misc]
|
|
62
|
+
def decorator(func: Callable[..., Any]) -> Callable[..., Any]:
|
|
63
|
+
# Create ResourceRequirements from kwargs
|
|
64
|
+
requirements = ResourceRequirements()
|
|
65
|
+
if "cpu" in kwargs:
|
|
66
|
+
requirements.cpu_units = kwargs["cpu"]
|
|
67
|
+
if "memory" in kwargs:
|
|
68
|
+
requirements.memory_mb = kwargs["memory"]
|
|
69
|
+
if "io" in kwargs:
|
|
70
|
+
requirements.io_weight = kwargs["io"]
|
|
71
|
+
if "network" in kwargs:
|
|
72
|
+
requirements.network_weight = kwargs["network"]
|
|
73
|
+
if "gpu" in kwargs:
|
|
74
|
+
requirements.gpu_units = kwargs["gpu"]
|
|
75
|
+
|
|
76
|
+
# Determine resource_types from non-zero values
|
|
77
|
+
resource_types = ResourceType.NONE
|
|
78
|
+
if requirements.cpu_units > 0:
|
|
79
|
+
resource_types |= ResourceType.CPU
|
|
80
|
+
if requirements.memory_mb > 0:
|
|
81
|
+
resource_types |= ResourceType.MEMORY
|
|
82
|
+
if requirements.io_weight > 0:
|
|
83
|
+
resource_types |= ResourceType.IO
|
|
84
|
+
if requirements.network_weight > 0:
|
|
85
|
+
resource_types |= ResourceType.NETWORK
|
|
86
|
+
if requirements.gpu_units > 0:
|
|
87
|
+
resource_types |= ResourceType.GPU
|
|
88
|
+
|
|
89
|
+
requirements.resource_types = resource_types
|
|
90
|
+
func._resource_requirements = requirements # type: ignore
|
|
91
|
+
return func
|
|
92
|
+
|
|
93
|
+
return decorator
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
__all__ = [
|
|
97
|
+
"Agent",
|
|
98
|
+
"Bulkhead",
|
|
99
|
+
"BulkheadConfig",
|
|
100
|
+
"CircuitBreaker",
|
|
101
|
+
"CircuitBreakerConfig",
|
|
102
|
+
"Context",
|
|
103
|
+
"Priority",
|
|
104
|
+
"ResourceLeakDetector",
|
|
105
|
+
"ResourcePool",
|
|
106
|
+
"ResourceRequirements",
|
|
107
|
+
"ResourceType",
|
|
108
|
+
"StateStatus",
|
|
109
|
+
"state",
|
|
110
|
+
]
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
"""Agent module with enhanced coordination features."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Callable
|
|
4
|
+
|
|
5
|
+
from .base import Agent, AgentResult, ResourceTimeoutError
|
|
6
|
+
from .checkpoint import AgentCheckpoint
|
|
7
|
+
from .context import Context, StateType
|
|
8
|
+
from .dependencies import DependencyConfig, DependencyLifecycle, DependencyType
|
|
9
|
+
from .state import (
|
|
10
|
+
AgentStatus,
|
|
11
|
+
DeadLetter,
|
|
12
|
+
PrioritizedState,
|
|
13
|
+
Priority,
|
|
14
|
+
RetryPolicy,
|
|
15
|
+
StateMetadata,
|
|
16
|
+
StateResult,
|
|
17
|
+
StateStatus,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
# Decorators
|
|
21
|
+
try:
|
|
22
|
+
from .decorators.builder import (
|
|
23
|
+
StateBuilder,
|
|
24
|
+
build_state,
|
|
25
|
+
cpu_state,
|
|
26
|
+
exclusive_state,
|
|
27
|
+
external_service_state,
|
|
28
|
+
fault_tolerant_state,
|
|
29
|
+
gpu_state,
|
|
30
|
+
high_priority_state,
|
|
31
|
+
isolated_state,
|
|
32
|
+
memory_state,
|
|
33
|
+
production_state,
|
|
34
|
+
protected_state,
|
|
35
|
+
)
|
|
36
|
+
from .decorators.flexible import (
|
|
37
|
+
FlexibleStateDecorator,
|
|
38
|
+
StateProfile,
|
|
39
|
+
batch_state,
|
|
40
|
+
concurrent_state,
|
|
41
|
+
cpu_intensive,
|
|
42
|
+
create_custom_decorator,
|
|
43
|
+
critical_state,
|
|
44
|
+
external_service,
|
|
45
|
+
fault_tolerant,
|
|
46
|
+
get_profile,
|
|
47
|
+
gpu_accelerated,
|
|
48
|
+
high_availability,
|
|
49
|
+
io_intensive,
|
|
50
|
+
list_profiles,
|
|
51
|
+
memory_intensive,
|
|
52
|
+
minimal_state,
|
|
53
|
+
network_intensive,
|
|
54
|
+
quick_state,
|
|
55
|
+
state,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
# synchronized_state, # Temporarily disabled
|
|
59
|
+
from .decorators.inspection import (
|
|
60
|
+
compare_states,
|
|
61
|
+
get_state_config,
|
|
62
|
+
get_state_coordination,
|
|
63
|
+
get_state_rate_limit,
|
|
64
|
+
get_state_requirements,
|
|
65
|
+
get_state_summary,
|
|
66
|
+
is_puffinflow_state,
|
|
67
|
+
list_state_metadata,
|
|
68
|
+
)
|
|
69
|
+
except ImportError:
|
|
70
|
+
# Decorators not available
|
|
71
|
+
pass
|
|
72
|
+
|
|
73
|
+
# Scheduling components
|
|
74
|
+
try:
|
|
75
|
+
from .scheduling import (
|
|
76
|
+
GlobalScheduler,
|
|
77
|
+
InputType,
|
|
78
|
+
InvalidInputTypeError,
|
|
79
|
+
InvalidScheduleError,
|
|
80
|
+
ScheduleBuilder,
|
|
81
|
+
ScheduledAgent,
|
|
82
|
+
ScheduledInput,
|
|
83
|
+
ScheduleParser,
|
|
84
|
+
SchedulingError,
|
|
85
|
+
parse_magic_prefix,
|
|
86
|
+
parse_schedule_string,
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
_SCHEDULING_AVAILABLE = True
|
|
90
|
+
except ImportError:
|
|
91
|
+
# Scheduling not available
|
|
92
|
+
_SCHEDULING_AVAILABLE = False
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
# Team decorators for convenience
|
|
96
|
+
def create_team_decorator(
|
|
97
|
+
team_name: str, **defaults: Any
|
|
98
|
+
) -> Callable[[Callable], Callable]:
|
|
99
|
+
"""Create a decorator for team-specific agents."""
|
|
100
|
+
try:
|
|
101
|
+
from .decorators.flexible import create_custom_decorator
|
|
102
|
+
|
|
103
|
+
team_defaults = {
|
|
104
|
+
"tags": {"team": team_name},
|
|
105
|
+
"description": f"Agent for {team_name} team",
|
|
106
|
+
**defaults,
|
|
107
|
+
}
|
|
108
|
+
return create_custom_decorator(**team_defaults)
|
|
109
|
+
except ImportError:
|
|
110
|
+
return lambda func: func
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def create_environment_decorator(
|
|
114
|
+
env: str, **defaults: Any
|
|
115
|
+
) -> Callable[[Callable], Callable]:
|
|
116
|
+
"""Create a decorator for environment-specific agents."""
|
|
117
|
+
try:
|
|
118
|
+
from .decorators.flexible import create_custom_decorator
|
|
119
|
+
|
|
120
|
+
env_defaults = {
|
|
121
|
+
"tags": {"environment": env},
|
|
122
|
+
"description": f"Agent for {env} environment",
|
|
123
|
+
**defaults,
|
|
124
|
+
}
|
|
125
|
+
return create_custom_decorator(**env_defaults)
|
|
126
|
+
except ImportError:
|
|
127
|
+
return lambda func: func
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def create_service_decorator(
|
|
131
|
+
service_name: str, **defaults: Any
|
|
132
|
+
) -> Callable[[Callable], Callable]:
|
|
133
|
+
"""Create a decorator for service-specific agents."""
|
|
134
|
+
try:
|
|
135
|
+
from .decorators.flexible import create_custom_decorator
|
|
136
|
+
|
|
137
|
+
service_defaults = {
|
|
138
|
+
"tags": {"service": service_name},
|
|
139
|
+
"description": f"Agent for {service_name} service",
|
|
140
|
+
**defaults,
|
|
141
|
+
}
|
|
142
|
+
return create_custom_decorator(**service_defaults)
|
|
143
|
+
except ImportError:
|
|
144
|
+
return lambda func: func
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def create_reliable_team_decorator(
|
|
148
|
+
team_name: str, **defaults: Any
|
|
149
|
+
) -> Callable[[Callable], Callable]:
|
|
150
|
+
"""Create a decorator for reliable team agents."""
|
|
151
|
+
try:
|
|
152
|
+
from .decorators.flexible import create_custom_decorator
|
|
153
|
+
|
|
154
|
+
reliable_defaults = {
|
|
155
|
+
"tags": {"team": team_name, "reliability": "high"},
|
|
156
|
+
"circuit_breaker": True,
|
|
157
|
+
"bulkhead": True,
|
|
158
|
+
"retries": 5,
|
|
159
|
+
**defaults,
|
|
160
|
+
}
|
|
161
|
+
return create_custom_decorator(**reliable_defaults)
|
|
162
|
+
except ImportError:
|
|
163
|
+
return lambda func: func
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def create_external_team_decorator(
|
|
167
|
+
team_name: str, **defaults: Any
|
|
168
|
+
) -> Callable[[Callable], Callable]:
|
|
169
|
+
"""Create a decorator for external service team agents."""
|
|
170
|
+
try:
|
|
171
|
+
from .decorators.flexible import create_custom_decorator
|
|
172
|
+
|
|
173
|
+
external_defaults = {
|
|
174
|
+
"tags": {"team": team_name, "type": "external"},
|
|
175
|
+
"circuit_breaker": True,
|
|
176
|
+
"timeout": 30.0,
|
|
177
|
+
"retries": 3,
|
|
178
|
+
**defaults,
|
|
179
|
+
}
|
|
180
|
+
return create_custom_decorator(**external_defaults)
|
|
181
|
+
except ImportError:
|
|
182
|
+
return lambda func: func
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
__all__ = [
|
|
186
|
+
# Core classes
|
|
187
|
+
"Agent",
|
|
188
|
+
"AgentCheckpoint",
|
|
189
|
+
"AgentResult",
|
|
190
|
+
"AgentStatus",
|
|
191
|
+
"Context",
|
|
192
|
+
"DeadLetter",
|
|
193
|
+
"DependencyConfig",
|
|
194
|
+
"DependencyLifecycle",
|
|
195
|
+
# Dependencies
|
|
196
|
+
"DependencyType",
|
|
197
|
+
"FlexibleStateDecorator",
|
|
198
|
+
# Scheduling (if available)
|
|
199
|
+
"GlobalScheduler",
|
|
200
|
+
"InputType",
|
|
201
|
+
"InvalidInputTypeError",
|
|
202
|
+
"InvalidScheduleError",
|
|
203
|
+
"PrioritizedState",
|
|
204
|
+
# State management
|
|
205
|
+
"Priority",
|
|
206
|
+
"ResourceTimeoutError",
|
|
207
|
+
"RetryPolicy",
|
|
208
|
+
"ScheduleBuilder",
|
|
209
|
+
"ScheduleParser",
|
|
210
|
+
"ScheduledAgent",
|
|
211
|
+
"ScheduledInput",
|
|
212
|
+
"SchedulingError",
|
|
213
|
+
# Decorators (if available)
|
|
214
|
+
"StateBuilder",
|
|
215
|
+
"StateMetadata",
|
|
216
|
+
"StateProfile",
|
|
217
|
+
"StateResult",
|
|
218
|
+
"StateStatus",
|
|
219
|
+
"StateType",
|
|
220
|
+
"batch_state",
|
|
221
|
+
"build_state",
|
|
222
|
+
"compare_states",
|
|
223
|
+
"concurrent_state",
|
|
224
|
+
"cpu_intensive",
|
|
225
|
+
"cpu_state",
|
|
226
|
+
"create_custom_decorator",
|
|
227
|
+
"create_environment_decorator",
|
|
228
|
+
"create_external_team_decorator",
|
|
229
|
+
"create_reliable_team_decorator",
|
|
230
|
+
"create_service_decorator",
|
|
231
|
+
# Team decorators
|
|
232
|
+
"create_team_decorator",
|
|
233
|
+
"critical_state",
|
|
234
|
+
"exclusive_state",
|
|
235
|
+
"external_service",
|
|
236
|
+
"external_service_state",
|
|
237
|
+
"fault_tolerant",
|
|
238
|
+
"fault_tolerant_state",
|
|
239
|
+
"get_profile",
|
|
240
|
+
"get_state_config",
|
|
241
|
+
"get_state_coordination",
|
|
242
|
+
"get_state_rate_limit",
|
|
243
|
+
"get_state_requirements",
|
|
244
|
+
"get_state_summary",
|
|
245
|
+
"gpu_accelerated",
|
|
246
|
+
"gpu_state",
|
|
247
|
+
"high_availability",
|
|
248
|
+
"high_priority_state",
|
|
249
|
+
"io_intensive",
|
|
250
|
+
# Inspection utilities
|
|
251
|
+
"is_puffinflow_state",
|
|
252
|
+
"isolated_state",
|
|
253
|
+
"list_profiles",
|
|
254
|
+
"list_state_metadata",
|
|
255
|
+
"memory_intensive",
|
|
256
|
+
"memory_state",
|
|
257
|
+
"minimal_state",
|
|
258
|
+
"network_intensive",
|
|
259
|
+
"parse_magic_prefix",
|
|
260
|
+
"parse_schedule_string",
|
|
261
|
+
"production_state",
|
|
262
|
+
"protected_state",
|
|
263
|
+
"quick_state",
|
|
264
|
+
# Flexible decorators
|
|
265
|
+
"state",
|
|
266
|
+
]
|
|
267
|
+
|
|
268
|
+
__doc__ = """
|
|
269
|
+
Enhanced Agent Module for PuffinFlow
|
|
270
|
+
|
|
271
|
+
This module provides the core Agent class with enhanced features for:
|
|
272
|
+
- Direct variable access and manipulation
|
|
273
|
+
- Rich context management with multiple content types
|
|
274
|
+
- Team coordination and messaging
|
|
275
|
+
- Event-driven communication
|
|
276
|
+
- State management and checkpointing
|
|
277
|
+
- Resource management and reliability patterns
|
|
278
|
+
|
|
279
|
+
Key Classes:
|
|
280
|
+
- Agent: Enhanced agent with direct variable access
|
|
281
|
+
- Context: Rich context with outputs, metadata, metrics, caching
|
|
282
|
+
- AgentResult: Comprehensive result container
|
|
283
|
+
- AgentCheckpoint: State persistence and recovery
|
|
284
|
+
|
|
285
|
+
Decorators (if available):
|
|
286
|
+
- @state: Flexible state decorator with profiles
|
|
287
|
+
- @cpu_intensive, @memory_intensive, etc.: Predefined profiles
|
|
288
|
+
- @build_state(): Fluent builder pattern
|
|
289
|
+
|
|
290
|
+
Team Features:
|
|
291
|
+
- AgentTeam: Multi-agent coordination
|
|
292
|
+
- Messaging between agents
|
|
293
|
+
- Event bus for loose coupling
|
|
294
|
+
- Shared variables and context
|
|
295
|
+
|
|
296
|
+
Example:
|
|
297
|
+
from puffinflow import Agent, state
|
|
298
|
+
|
|
299
|
+
class DataProcessor(Agent):
|
|
300
|
+
@state(cpu=2.0, memory=512.0)
|
|
301
|
+
async def process_data(self, context):
|
|
302
|
+
# Direct variable access
|
|
303
|
+
batch_size = self.get_variable("batch_size", 1000)
|
|
304
|
+
|
|
305
|
+
# Process data
|
|
306
|
+
result = await self.process(batch_size)
|
|
307
|
+
|
|
308
|
+
# Set outputs and metrics
|
|
309
|
+
context.set_output("processed_count", len(result))
|
|
310
|
+
context.set_metric("processing_time", time.time())
|
|
311
|
+
|
|
312
|
+
return "completed"
|
|
313
|
+
|
|
314
|
+
# Create and run agent
|
|
315
|
+
processor = DataProcessor("processor")
|
|
316
|
+
processor.set_variable("batch_size", 2000)
|
|
317
|
+
|
|
318
|
+
result = await processor.run()
|
|
319
|
+
print(f"Processed: {result.get_output('processed_count')}")
|
|
320
|
+
"""
|