Agents Overview
Overview of the ForkFit multi-agent cognitive architecture and shared helper utilities.
Agents Overview
ForkFit uses a collection of specialized, autonomous agents that collaborate within a cyclic state graph to build personalized, safe, and cost-effective meal schedules.
The agents are implemented in Python under the server/intelligence/src/agents/ directory.
1. Agent Architecture
Each agent is designed as a modular function that reads from and writes to the global GraphState TypedDict. Every specialist agent follows a uniform structure:
- Prerequisite Check: Inspects
state["required_agents"]to verify if it is needed. If not, it returns immediately (performing a fast no-op) to save execution latency. - Context Reading: Extracts specific metrics (e.g. biometrics, goals, or pantry stock) from the hydrated context.
- Execution: Performs LLM queries, database operations, or mathematical aggregations inside a telemetry timer.
- Telemetry Logging: Emits step updates (such as input/output payloads and latency) back to the server and client.
- State Update: Updates the state dict with its results and returns.
Execution Orchestration
The 11 agents in the graph are orchestrated in a hybrid parallel/serial topology to optimize execution latency and preserve logical dependencies:
- Parallel Specialists: The four analysis agents—
Safety,Nutrition,Budget, andCulture—are triggered in parallel, fanning out from thePlannernode. This allows concurrent analysis of biometrics, nutritional equations, ingredient cost bounds, and cultural checks. - Serial Remaining Pipeline: Once all parallel agents finish execution (or return early), the graph fans in to the
Recipenode. The remaining nodes (Recipe,Calendar,Shopping,Consensus,Judge,Visualization) are executed sequentially (in serial) because each relies on the outputs of the preceding nodes.
2. Shared Helpers
Common utilities are shared across agent modules to maintain DRY (Don't Repeat Yourself) design principles.
Implementation: helpers.py
Timer Class
A context manager used to measure the execution latency of agent tasks in wall-clock milliseconds:
t = Timer()
with t:
await run_agent_workflow()
print(f"Elapsed: {t.ms}ms")emit_step Function
Serializes and streams real-time execution steps (inputs, outputs, latency, status) back to gRPC stream clients:
await emit_step(
callback=state.get("_step_callback"),
agent_name="Nutrition",
status="completed",
step_type="aggregation",
input_data=input_data,
output_data=output_data,
latency_ms=timer.ms,
)