How evolutionary-algorithms-on-click/evocv2_llm_microservice works
Purpose and runtime
EVOC DEAP Agent is a Python 3.11+ FastAPI service that generates, modifies, and repairs DEAP evolutionary-algorithm notebooks. Its central output constraint is a purely functional, fixed 12-cell Jupyter notebook. The ASGI entry point is app/main.py; container deployment is defined by Dockerfile and docker-compose.yml.
API boundary
HTTP endpoints separate the three user operations:
• Generate a complete notebook from structured JSON: app/routes/generate.py
• Modify an existing notebook from natural-language instructions: app/routes/modify.py
• Fix notebook/code failures from traceback context: app/routes/fix.py
app/main.py mounts these routes and exposes service/health behavior. Request and response schemas are centralized in app/models.py, providing the typed boundary between arbitrary client JSON and internal workflows.
Request normalization and specifications
app/core/request_parser.py converts flexible incoming JSON into the application’s canonical generation specification, preserving unrecognized fields as LLM-facing supplemental requirements. Runtime configuration, including API credentials and model settings, is sourced through app/config.py and environment values such as the Groq key.
LangGraph orchestration
app/graph.py defines the stateful LangGraph workflow used by generate, modify, and fix flows. It coordinates agent stages, validation/revision loops, and workflow state rather than allowing routes to invoke LLM logic directly. Shared state and session context are maintained through app/memory.py, which integrates Mem0 for history and user preferences.
Agent layer and structured LLM boundary
Mode-specific agents implement the substantive transformations:
• Initial notebook construction: app/agents/generator.py
• Targeted notebook edits: app/agents/modifier.py
• Error-driven code repair: app/agents/fixer.py
Their prompts are isolated by operation in app/prompts/generator.py, app/prompts/modifier.py, and app/prompts/fixer.py. LLM calls use Groq-compatible inference and Instructor/Pydantic-style structured outputs, so model responses are expected as validated data rather than markdown or free-form notebook text.
Notebook assembly and dependency correctness
app/core/llm_cell_generator.py turns model-generated content into the mandated cell-oriented representation. It enforces generation around the architecture’s 12 semantic stages: imports, problem setup, DEAP creator definitions, evaluation/operators, initialization, toolbox registration, evolution loop, and results. Dependency and ordering support spans app/core/llm_cell_generator.py and app/utils/cell_names.py, enabling hybrid static and LLM-informed detection when code is changed or repaired.
Export boundary and artifacts
The internal notebook/cell model is rendered into Jupyter-compatible artifacts by app/utils/notebook_exporter.py. Generated outputs may also be exported as Python, as illustrated by test_outputs/test_tsp_problem.ipynb and test_outputs/test_tsp_problem.py. The service’s external contract is therefore structured API input/output, with notebook serialization confined to the export layer rather than API route handlers.
Main entry points: graph.py LangGraph workflow · llm_cell_generator.py Cell assembly · main.py ASGI application · generate.py Generate endpoint
Components 19
HTTP API
- ASGI application · Mounts API routes and exposes health behavior.
app/main.py - Generate endpoint
app/routes/generate.py - Modify endpoint
app/routes/modify.py - Fix endpoint
app/routes/fix.py - Request/response schemas · Typed boundary for client JSON and workflow results.
app/models.py
Workflow & agents
- Request normalization · Converts flexible JSON into a canonical generation specification.
app/core/request_parser.py - LangGraph workflow · Coordinates mode-specific stages and validation/revision loops.
app/graph.py - Session memory · Maintains history and user preferences.
app/memory.py - Runtime configuration · Loads Groq credentials and model settings.
app/config.py - Generation agent
app/agents/generator.py - Modification agent
app/agents/modifier.py - Repair agent
app/agents/fixer.py - Operation prompts · Separate prompts guide generation, modification, and repair.
app/prompts/generator.py
Notebook pipeline
- Cell assembly · Builds the required functional 12-cell notebook representation.
app/core/llm_cell_generator.py - Dependency ordering · Supports static and LLM-informed code-change ordering.
app/utils/cell_names.py - Notebook exporter · Serializes the internal model as Jupyter notebooks or Python.
app/utils/notebook_exporter.py
Other components
- Container deployment · Runs the ASGI service with environment configuration.
Dockerfile - Compose environment
docker-compose.yml - Notebook artifacts
test_outputs/test_tsp_problem.ipynb
Connections 26
- Compose environment → Container deployment: builds
- Container deployment → ASGI application: runs
- ASGI application → Generate endpoint: mounts
- ASGI application → Modify endpoint: mounts
- ASGI application → Fix endpoint: mounts
- Generate endpoint → Request/response schemas: validates with
- Modify endpoint → Request/response schemas: validates with
- Fix endpoint → Request/response schemas: validates with
- Generate endpoint → Request normalization: normalizes input
- Generate endpoint → LangGraph workflow: starts generate flow
- Modify endpoint → LangGraph workflow: starts modify flow
- Fix endpoint → LangGraph workflow: starts repair flow
- LangGraph workflow → Session memory: uses context
- LangGraph workflow → Generation agent: dispatches generate
- LangGraph workflow → Modification agent: dispatches modify
- LangGraph workflow → Repair agent: dispatches repair
- Generation agent → Operation prompts: uses
- Generation agent → Runtime configuration: uses model settings
- Modification agent → Runtime configuration: uses model settings
- Repair agent → Runtime configuration: uses model settings
- Generation agent → Cell assembly: produces cells
- Modification agent → Cell assembly: updates cells
- Repair agent → Cell assembly: repairs cells
- Cell assembly → Dependency ordering: checks dependencies
- Cell assembly → Notebook exporter: passes cell model
- Notebook exporter → Notebook artifacts: renders