flock-core 0.4.520__py3-none-any.whl → 0.5.0b2__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.

Potentially problematic release.


This version of flock-core might be problematic. Click here for more details.

Files changed (103) hide show
  1. flock/cli/manage_agents.py +3 -3
  2. flock/components/__init__.py +28 -0
  3. flock/components/evaluation/__init__.py +9 -0
  4. flock/components/evaluation/declarative_evaluation_component.py +198 -0
  5. flock/components/routing/__init__.py +15 -0
  6. flock/{routers/conditional/conditional_router.py → components/routing/conditional_routing_component.py} +60 -49
  7. flock/components/routing/default_routing_component.py +103 -0
  8. flock/components/routing/llm_routing_component.py +208 -0
  9. flock/components/utility/__init__.py +15 -0
  10. flock/{modules/enterprise_memory/enterprise_memory_module.py → components/utility/memory_utility_component.py} +195 -173
  11. flock/{modules/performance/metrics_module.py → components/utility/metrics_utility_component.py} +101 -86
  12. flock/{modules/output/output_module.py → components/utility/output_utility_component.py} +49 -49
  13. flock/core/__init__.py +2 -8
  14. flock/core/agent/__init__.py +16 -0
  15. flock/core/agent/flock_agent_components.py +104 -0
  16. flock/core/agent/flock_agent_execution.py +101 -0
  17. flock/core/agent/flock_agent_integration.py +147 -0
  18. flock/core/agent/flock_agent_lifecycle.py +177 -0
  19. flock/core/agent/flock_agent_serialization.py +378 -0
  20. flock/core/component/__init__.py +15 -0
  21. flock/core/{flock_module.py → component/agent_component_base.py} +136 -35
  22. flock/core/component/evaluation_component_base.py +56 -0
  23. flock/core/component/routing_component_base.py +75 -0
  24. flock/core/component/utility_component_base.py +69 -0
  25. flock/core/config/flock_agent_config.py +49 -2
  26. flock/core/evaluation/utils.py +1 -1
  27. flock/core/execution/evaluation_executor.py +1 -1
  28. flock/core/flock.py +137 -483
  29. flock/core/flock_agent.py +151 -1018
  30. flock/core/flock_factory.py +94 -73
  31. flock/core/{flock_registry.py → flock_registry.py.backup} +3 -17
  32. flock/core/logging/logging.py +1 -0
  33. flock/core/mcp/flock_mcp_server.py +42 -37
  34. flock/core/mixin/dspy_integration.py +5 -5
  35. flock/core/orchestration/__init__.py +18 -0
  36. flock/core/orchestration/flock_batch_processor.py +94 -0
  37. flock/core/orchestration/flock_evaluator.py +113 -0
  38. flock/core/orchestration/flock_execution.py +288 -0
  39. flock/core/orchestration/flock_initialization.py +125 -0
  40. flock/core/orchestration/flock_server_manager.py +65 -0
  41. flock/core/orchestration/flock_web_server.py +117 -0
  42. flock/core/registry/__init__.py +39 -0
  43. flock/core/registry/agent_registry.py +69 -0
  44. flock/core/registry/callable_registry.py +139 -0
  45. flock/core/registry/component_discovery.py +142 -0
  46. flock/core/registry/component_registry.py +64 -0
  47. flock/core/registry/config_mapping.py +64 -0
  48. flock/core/registry/decorators.py +137 -0
  49. flock/core/registry/registry_hub.py +202 -0
  50. flock/core/registry/server_registry.py +57 -0
  51. flock/core/registry/type_registry.py +86 -0
  52. flock/core/serialization/flock_serializer.py +33 -30
  53. flock/core/serialization/serialization_utils.py +28 -25
  54. flock/core/util/input_resolver.py +29 -2
  55. flock/platform/docker_tools.py +3 -3
  56. flock/tools/markdown_tools.py +1 -2
  57. flock/tools/text_tools.py +1 -2
  58. flock/webapp/app/main.py +9 -5
  59. flock/workflow/activities.py +59 -84
  60. flock/workflow/activities_unified.py +230 -0
  61. flock/workflow/agent_execution_activity.py +6 -6
  62. flock/workflow/flock_workflow.py +1 -1
  63. {flock_core-0.4.520.dist-info → flock_core-0.5.0b2.dist-info}/METADATA +2 -2
  64. {flock_core-0.4.520.dist-info → flock_core-0.5.0b2.dist-info}/RECORD +67 -68
  65. flock/core/flock_evaluator.py +0 -60
  66. flock/core/flock_router.py +0 -83
  67. flock/evaluators/__init__.py +0 -1
  68. flock/evaluators/declarative/__init__.py +0 -1
  69. flock/evaluators/declarative/declarative_evaluator.py +0 -194
  70. flock/evaluators/memory/memory_evaluator.py +0 -90
  71. flock/evaluators/test/test_case_evaluator.py +0 -38
  72. flock/evaluators/zep/zep_evaluator.py +0 -59
  73. flock/modules/__init__.py +0 -1
  74. flock/modules/assertion/__init__.py +0 -1
  75. flock/modules/assertion/assertion_module.py +0 -286
  76. flock/modules/callback/__init__.py +0 -1
  77. flock/modules/callback/callback_module.py +0 -91
  78. flock/modules/enterprise_memory/README.md +0 -99
  79. flock/modules/mem0/__init__.py +0 -1
  80. flock/modules/mem0/mem0_module.py +0 -126
  81. flock/modules/mem0_async/__init__.py +0 -1
  82. flock/modules/mem0_async/async_mem0_module.py +0 -126
  83. flock/modules/memory/__init__.py +0 -1
  84. flock/modules/memory/memory_module.py +0 -429
  85. flock/modules/memory/memory_parser.py +0 -125
  86. flock/modules/memory/memory_storage.py +0 -736
  87. flock/modules/output/__init__.py +0 -1
  88. flock/modules/performance/__init__.py +0 -1
  89. flock/modules/zep/__init__.py +0 -1
  90. flock/modules/zep/zep_module.py +0 -192
  91. flock/routers/__init__.py +0 -1
  92. flock/routers/agent/__init__.py +0 -1
  93. flock/routers/agent/agent_router.py +0 -236
  94. flock/routers/agent/handoff_agent.py +0 -58
  95. flock/routers/default/__init__.py +0 -1
  96. flock/routers/default/default_router.py +0 -80
  97. flock/routers/feedback/feedback_router.py +0 -114
  98. flock/routers/list_generator/list_generator_router.py +0 -166
  99. flock/routers/llm/__init__.py +0 -1
  100. flock/routers/llm/llm_router.py +0 -365
  101. {flock_core-0.4.520.dist-info → flock_core-0.5.0b2.dist-info}/WHEEL +0 -0
  102. {flock_core-0.4.520.dist-info → flock_core-0.5.0b2.dist-info}/entry_points.txt +0 -0
  103. {flock_core-0.4.520.dist-info → flock_core-0.5.0b2.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,208 @@
1
+ # src/flock/components/routing/llm_routing_component.py
2
+ """LLM-based routing component implementation for the unified component architecture."""
3
+
4
+ import json
5
+ from typing import TYPE_CHECKING, Any
6
+
7
+ import litellm
8
+ from pydantic import Field
9
+
10
+ from flock.core.component.agent_component_base import AgentComponentConfig
11
+ from flock.core.component.routing_component_base import RoutingComponentBase
12
+ from flock.core.context.context import FlockContext
13
+ from flock.core.registry import flock_component
14
+ # HandOffRequest removed - using agent.next_agent directly
15
+ from flock.core.logging.logging import get_logger
16
+
17
+ if TYPE_CHECKING:
18
+ from flock.core.flock_agent import FlockAgent
19
+
20
+ logger = get_logger("components.routing.llm")
21
+
22
+
23
+ class LLMRoutingConfig(AgentComponentConfig):
24
+ """Configuration for the LLM routing component."""
25
+
26
+ temperature: float = Field(
27
+ default=0.2, description="Temperature for LLM routing decisions"
28
+ )
29
+ max_tokens: int = Field(
30
+ default=500, description="Maximum tokens for LLM response"
31
+ )
32
+ confidence_threshold: float = Field(
33
+ default=0.5, description="Minimum confidence threshold for routing"
34
+ )
35
+ model: str = Field(
36
+ default="azure/gpt-4.1", description="Model to use for routing decisions"
37
+ )
38
+ prompt_template: str = Field(
39
+ default="""You are a workflow routing assistant. Given the current agent's output and available next agents, determine which agent should execute next.
40
+
41
+ Current Agent: {current_agent_name}
42
+ Current Output: {current_output}
43
+
44
+ Available Agents:
45
+ {available_agents}
46
+
47
+ Select the most appropriate next agent based on the current output. Respond with JSON in this exact format:
48
+ {{"next_agent": "agent_name", "confidence": 0.8, "reasoning": "explanation"}}
49
+
50
+ If no agent is suitable, use "next_agent": "" to end the workflow.""",
51
+ description="Template for LLM routing prompt"
52
+ )
53
+
54
+
55
+ @flock_component(config_class=LLMRoutingConfig)
56
+ class LLMRoutingComponent(RoutingComponentBase):
57
+ """Router that uses an LLM to determine the next agent in a workflow.
58
+
59
+ This component analyzes the current agent's output and uses an LLM to
60
+ intelligently select the most appropriate next agent from available options.
61
+ """
62
+
63
+ config: LLMRoutingConfig = Field(
64
+ default_factory=LLMRoutingConfig
65
+ )
66
+
67
+ def __init__(
68
+ self,
69
+ name: str = "llm_router",
70
+ config: LLMRoutingConfig | None = None,
71
+ **data,
72
+ ):
73
+ if config is None:
74
+ config = LLMRoutingConfig()
75
+ super().__init__(name=name, config=config, **data)
76
+
77
+ def _get_available_agents(
78
+ self, agent_definitions: dict[str, Any], current_agent_name: str
79
+ ) -> list[str]:
80
+ """Get list of available agent names except the current one."""
81
+ available = []
82
+ for agent_name in agent_definitions.keys():
83
+ if agent_name != current_agent_name:
84
+ available.append(agent_name)
85
+ return available
86
+
87
+ def _create_selection_prompt(
88
+ self,
89
+ current_agent: "FlockAgent",
90
+ result: dict[str, Any],
91
+ available_agents: list[str],
92
+ ) -> str:
93
+ """Create the prompt for LLM agent selection."""
94
+
95
+ # Format available agents
96
+ agents_list = []
97
+ for agent_name in available_agents:
98
+ agents_list.append(f"- {agent_name}")
99
+
100
+ available_agents_str = "\n".join(agents_list) if agents_list else "None available"
101
+
102
+ # Format current output
103
+ current_output = json.dumps(result, indent=2) if result else "No output"
104
+
105
+ return self.config.prompt_template.format(
106
+ current_agent_name=current_agent.name,
107
+ current_output=current_output,
108
+ available_agents=available_agents_str
109
+ )
110
+
111
+ async def _select_next_agent(
112
+ self,
113
+ current_agent: "FlockAgent",
114
+ result: dict[str, Any],
115
+ available_agents: list[str],
116
+ ) -> tuple[str, float]:
117
+ """Use an LLM to select the best next agent."""
118
+
119
+ if not available_agents:
120
+ logger.warning("No available agents for LLM routing")
121
+ return "", 0.0
122
+
123
+ # Create the selection prompt
124
+ prompt = self._create_selection_prompt(current_agent, result, available_agents)
125
+
126
+ try:
127
+ # Call the LLM
128
+ response = await litellm.acompletion(
129
+ model=self.config.model,
130
+ messages=[
131
+ {"role": "user", "content": prompt}
132
+ ],
133
+ temperature=self.config.temperature,
134
+ max_tokens=self.config.max_tokens,
135
+ )
136
+
137
+ response_content = response.choices[0].message.content.strip()
138
+ logger.debug(f"LLM routing response: {response_content}")
139
+
140
+ # Parse the JSON response
141
+ try:
142
+ routing_decision = json.loads(response_content)
143
+ next_agent = routing_decision.get("next_agent", "")
144
+ confidence = routing_decision.get("confidence", 0.0)
145
+ reasoning = routing_decision.get("reasoning", "No reasoning provided")
146
+
147
+ logger.info(f"LLM routing decision: {next_agent} (confidence: {confidence}) - {reasoning}")
148
+
149
+ # Validate the selected agent is available
150
+ if next_agent and next_agent not in available_agents and next_agent != "":
151
+ logger.warning(f"LLM selected unavailable agent '{next_agent}', ending workflow")
152
+ return "", 0.0
153
+
154
+ return next_agent, confidence
155
+
156
+ except json.JSONDecodeError as e:
157
+ logger.error(f"Failed to parse LLM response as JSON: {e}")
158
+ return "", 0.0
159
+
160
+ except Exception as e:
161
+ logger.error(f"Error calling LLM for routing: {e}")
162
+ return "", 0.0
163
+
164
+ async def determine_next_step(
165
+ self,
166
+ agent: "FlockAgent",
167
+ result: dict[str, Any],
168
+ context: FlockContext | None = None,
169
+ ) -> None:
170
+ """Use LLM to determine the next agent based on current output."""
171
+
172
+ if not context:
173
+ logger.warning("No context provided for LLM routing")
174
+ return
175
+
176
+ logger.info(f"LLM routing from agent '{agent.name}'")
177
+
178
+ # Get available agents from context
179
+ agent_definitions = getattr(context, 'agent_definitions', {})
180
+ available_agents = self._get_available_agents(agent_definitions, agent.name)
181
+
182
+ logger.debug(f"Available agents for LLM routing: {available_agents}")
183
+
184
+ if not available_agents:
185
+ logger.warning("No available agents for LLM routing")
186
+ return
187
+
188
+ # Use LLM to select the next agent
189
+ next_agent_name, confidence = await self._select_next_agent(
190
+ agent, result, available_agents
191
+ )
192
+
193
+ logger.info(f"LLM routing result: {next_agent_name} (confidence: {confidence})")
194
+
195
+ # Check confidence threshold
196
+ if not next_agent_name or confidence < self.config.confidence_threshold:
197
+ logger.warning(
198
+ f"LLM routing confidence {confidence} below threshold {self.config.confidence_threshold}"
199
+ )
200
+ return
201
+
202
+ # Validate the selected agent exists
203
+ if next_agent_name not in agent_definitions:
204
+ logger.error(f"LLM selected non-existent agent '{next_agent_name}'")
205
+ return
206
+
207
+ logger.info(f"Successfully routed to agent '{next_agent_name}' with confidence {confidence}")
208
+ agent.next_agent = next_agent_name
@@ -0,0 +1,15 @@
1
+ # src/flock/components/utility/__init__.py
2
+ """Utility components for the Flock framework."""
3
+
4
+ from .memory_utility_component import MemoryUtilityComponent, MemoryUtilityConfig
5
+ from .metrics_utility_component import MetricsUtilityComponent, MetricsUtilityConfig
6
+ from .output_utility_component import OutputUtilityComponent, OutputUtilityConfig
7
+
8
+ __all__ = [
9
+ "MemoryUtilityComponent",
10
+ "MemoryUtilityConfig",
11
+ "MetricsUtilityComponent",
12
+ "MetricsUtilityConfig",
13
+ "OutputUtilityComponent",
14
+ "OutputUtilityConfig",
15
+ ]