flock-core 0.5.4__py3-none-any.whl → 0.5.5__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.

flock/agent.py CHANGED
@@ -249,7 +249,26 @@ class Agent(metaclass=AutoTracedMeta):
249
249
  accumulated_metrics: dict[str, float] = {}
250
250
  for engine in engines:
251
251
  current_inputs = await engine.on_pre_evaluate(self, ctx, current_inputs)
252
- result = await engine.evaluate(self, ctx, current_inputs)
252
+ use_batch_mode = bool(getattr(ctx, "is_batch", False))
253
+ try:
254
+ if use_batch_mode:
255
+ logger.debug(
256
+ "Agent %s: routing %d artifacts to %s.evaluate_batch",
257
+ self.name,
258
+ len(current_inputs.artifacts),
259
+ engine.__class__.__name__,
260
+ )
261
+ result = await engine.evaluate_batch(self, ctx, current_inputs)
262
+ else:
263
+ result = await engine.evaluate(self, ctx, current_inputs)
264
+ except NotImplementedError:
265
+ if use_batch_mode:
266
+ logger.error(
267
+ "Agent %s: engine %s does not implement evaluate_batch()",
268
+ self.name,
269
+ engine.__class__.__name__,
270
+ )
271
+ raise
253
272
 
254
273
  # AUTO-WRAP: If engine returns BaseModel instead of EvalResult, wrap it
255
274
  from flock.runtime import EvalResult as ER
flock/components.py CHANGED
@@ -109,6 +109,38 @@ class EngineComponent(AgentComponent):
109
109
  """Override this method in your engine implementation."""
110
110
  raise NotImplementedError
111
111
 
112
+ async def evaluate_batch(self, agent: Agent, ctx: Context, inputs: EvalInputs) -> EvalResult:
113
+ """Process batch of accumulated artifacts (BatchSpec).
114
+
115
+ Override this method if your engine supports batch processing.
116
+
117
+ Args:
118
+ agent: Agent instance executing this engine
119
+ ctx: Execution context (ctx.is_batch will be True)
120
+ inputs: EvalInputs with inputs.artifacts containing batch items
121
+
122
+ Returns:
123
+ EvalResult with processed artifacts
124
+
125
+ Raises:
126
+ NotImplementedError: If engine doesn't support batching
127
+
128
+ Example:
129
+ >>> async def evaluate_batch(self, agent, ctx, inputs):
130
+ ... events = inputs.all_as(Event) # Get ALL items
131
+ ... results = await bulk_process(events)
132
+ ... return EvalResult.from_objects(*results, agent=agent)
133
+ """
134
+ raise NotImplementedError(
135
+ f"{self.__class__.__name__} does not support batch processing.\n\n"
136
+ f"To fix this:\n"
137
+ f"1. Remove BatchSpec from agent subscription, OR\n"
138
+ f"2. Implement evaluate_batch() in {self.__class__.__name__}, OR\n"
139
+ f"3. Use a batch-aware engine (e.g., CustomBatchEngine)\n\n"
140
+ f"Agent: {agent.name}\n"
141
+ f"Engine: {self.__class__.__name__}"
142
+ )
143
+
112
144
  async def fetch_conversation_context(
113
145
  self,
114
146
  ctx: Context,