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