Components¶
components ¶
Agent component abstractions.
Classes¶
TracedModelMeta ¶
Bases: ModelMetaclass
, AutoTracedMeta
Combined metaclass for Pydantic models with auto-tracing.
This metaclass combines Pydantic's ModelMetaclass with AutoTracedMeta to enable both Pydantic functionality and automatic method tracing.
AgentComponentConfig ¶
Bases: BaseModel
Functions¶
with_fields classmethod
¶
with_fields(**field_definitions) -> type[Self]
Create a new config class with additional fields.
This allows dynamic config creation for components with custom configuration needs.
Example
CustomConfig = AgentComponentConfig.with_fields( temperature=Field(default=0.7, description="LLM temperature"), max_tokens=Field(default=1000, description="Max tokens to generate") )
Source code in src/flock/components.py
AgentComponent ¶
Bases: BaseModel
Base class for agent components with lifecycle hooks.
All public methods are automatically traced via OpenTelemetry.
EngineComponent ¶
Bases: AgentComponent
Base class for engine components with built-in conversation context support.
Functions¶
evaluate async
¶
evaluate(agent: Agent, ctx: Context, inputs: EvalInputs) -> EvalResult
evaluate_batch async
¶
evaluate_batch(agent: Agent, ctx: Context, inputs: EvalInputs) -> EvalResult
Process batch of accumulated artifacts (BatchSpec).
Override this method if your engine supports batch processing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent | Agent | Agent instance executing this engine | required |
ctx | Context | Execution context (ctx.is_batch will be True) | required |
inputs | EvalInputs | EvalInputs with inputs.artifacts containing batch items | required |
Returns:
Type | Description |
---|---|
EvalResult | EvalResult with processed artifacts |
Raises:
Type | Description |
---|---|
NotImplementedError | If engine doesn't support batching |
Example
async def evaluate_batch(self, agent, ctx, inputs): ... events = inputs.all_as(Event) # Get ALL items ... results = await bulk_process(events) ... return EvalResult.from_objects(*results, agent=agent)
Source code in src/flock/components.py
fetch_conversation_context async
¶
fetch_conversation_context(ctx: Context, correlation_id: UUID | None = None, max_artifacts: int | None = None) -> list[dict[str, Any]]
Fetch all artifacts with the same correlation_id for conversation context.
Source code in src/flock/components.py
get_latest_artifact_of_type async
¶
get_latest_artifact_of_type(ctx: Context, artifact_type: str, correlation_id: UUID | None = None) -> dict[str, Any] | None
Get the most recent artifact of a specific type in the conversation.
Source code in src/flock/components.py
should_use_context ¶
should_use_context(inputs: EvalInputs) -> bool
Determine if context should be included based on the current inputs.