How naveenkai/agentml works
Purpose and Entry Points
AgentML is a local-first AutoML assistant: users upload CSV data or start a dataset-free ML chat; LLM agents generate and execute Python, stream results, and optionally run an approval-gated ML pipeline. Backend startup is backend/main.py; the React root is src/index.js → src/App.js. The primary interactive boundary is WebSocket streaming at backend/api/routes/ws.py, with HTTP for upload, sessions, settings, and model discovery.
Browser Client and State
The React frontend renders chat, pipeline progress, session navigation, and rich execution results. src/store/chatStore.js is the client-side source of truth for sessions, messages, WebSocket events, streaming state, and HITL actions. src/api/client.js centralizes Axios and WebSocket connectivity; src/components/chat/ChatLayout.jsx and src/components/pipeline/PipelineProgress.jsx project that state into the UI.
API, Session, and Persistence Boundary
FastAPI composes CORS, lifecycle, rate limiting, and route registration in backend/main.py. Upload endpoints validate and ingest CSVs in backend/api/routes/upload.py; WebSocket requests drive runs in backend/api/routes/ws.py. Active session lifecycle, per-session concurrency, expiry, and execution availability are managed in backend/utils/session_manager.py; durable session/message/experiment history is stored locally through SQLite in backend/db/database.py and backend/db/models.py.
Agent Graph and Control Flow
backend/agent/driver.py is the streaming execution entry point: it constructs run context, coordinates session locking, invokes the graph, and relays events. backend/agent/pipeline.py defines the LangGraph topology and transitions. A deterministic entry router selects general chat versus autonomous pipeline behavior; pipeline control proceeds through preprocessing, EDA, feature engineering, modeling, evaluation, plus a Hungry quality-review gate. backend/agent/routing.py provides ordered and backward stage navigation, while backend/agent/hitl.py pauses stage transitions for approve/modify/reject decisions and timeout fallback.
LLM, Prompts, and Structured Output
Agent nodes share LLM acquisition, retries, parsing, and execution conventions in backend/agent/common.py, backend/agent/llm_utils.py, and backend/agent/parser.py. Stage-specific prompts reside under backend/agent/prompts/, including pipeline prompts and modeling/debate specialists. Provider selection is configured in backend/config.py: Ollama is local by default; OpenAI and Anthropic are opt-in external services. Agent output is converted into typed decisions and streamable message parts through backend/agent/schemas_llm.py and backend/agent/events.py.
Code Execution and Recovery
The sole agent tool is backend/agent/tools.py, which validates generated Python then sends it to a persistent, session-scoped Jupyter kernel in backend/executor/notebook.py. The kernel runs in a child process via ZMQ, isolating kernel crashes from FastAPI. backend/agent/ledger.py tracks variables and execution state outside the kernel to aid recovery; plots and tables become rich client events.
Security and Operating Constraints
The intended runtime is a single trusted user on localhost, without authentication. backend/guardrails/code_validator.py applies AST denylist checks before kernel execution, but is explicitly not a sandbox. backend/guardrails/prompt_sanitizer.py neutralizes agent-protocol tags in user/data input, and backend/guardrails/rate_limiter.py protects HTTP and WebSocket routes. Deployment beyond loopback requires external authentication, OS-level isolation, and secrets management.
Main entry points: pipeline.py LangGraph pipeline · main.py FastAPI application · ws.py Streaming run route · driver.py Streaming driver
Components 19
Browser client
- React app
src/App.js - Chat state store · Owns sessions, messages, stream state, and HITL actions.
src/store/chatStore.js - API client
src/api/client.js - Chat and pipeline UI
src/components/chat/ChatLayout.jsx
FastAPI boundary
- FastAPI application · Composes lifecycle, CORS, rate limiting, and routes.
backend/main.py - Streaming run route
backend/api/routes/ws.py - CSV upload route
backend/api/routes/upload.py - Session manager · Controls per-session locking, expiry, and execution availability.
backend/utils/session_manager.py - SQLite history · Stores sessions, messages, and experiments locally.
backend/db/database.py
Agent orchestration
- Streaming driver · Builds run context, invokes the graph, and relays events.
backend/agent/driver.py - LangGraph pipeline · Routes general chat or autonomous ML stages.
backend/agent/pipeline.py - Stage navigation and HITL · Navigates stages and pauses for approve, modify, reject, or timeout.
backend/agent/hitl.py - LLM and structured output · Acquires providers, parses outputs, and emits typed stream events.
backend/agent/llm_utils.py - Stage prompts · Pipeline and modeling/debate specialist instructions.
backend/agent/prompts/base.py
Execution and safety
- Python execution tool · Validates generated Python and dispatches it to the session kernel.
backend/agent/tools.py - AST code validator · Denylist validation; not a security sandbox.
backend/guardrails/code_validator.py - Session Jupyter kernel · Persistent ZMQ kernel isolates crashes from FastAPI.
backend/executor/notebook.py - Execution ledger · Tracks variables and execution state outside the kernel.
backend/agent/ledger.py - Input protections · Sanitizes protocol tags and rate-limits HTTP and WebSocket traffic.
backend/guardrails/prompt_sanitizer.py
Connections 22
- React app → Chat state store: initializes
- Chat state store → API client: connects and sends
- Chat state store → Chat and pipeline UI: projects state
- API client → FastAPI application: HTTP
- API client → Streaming run route: streaming WebSocket
- FastAPI application → CSV upload route: registers
- FastAPI application → Streaming run route: registers
- CSV upload route → Session manager: ingests session data
- Streaming run route → Streaming driver: starts run
- Streaming run route → Session manager: checks lifecycle
- Session manager → SQLite history: persists history
- Streaming driver → LangGraph pipeline: invokes
- Streaming driver → Session manager: acquires session lock
- LangGraph pipeline → Stage navigation and HITL: stage transitions and approval
- LangGraph pipeline → LLM and structured output: agent decisions
- LLM and structured output → Stage prompts: uses
- LangGraph pipeline → Python execution tool: generated Python
- Python execution tool → AST code validator: validates first
- AST code validator → Session Jupyter kernel: approved code
- Session Jupyter kernel → Execution ledger: execution state
- Session Jupyter kernel → Streaming driver: results, plots, tables
- Input protections → FastAPI application: sanitization and rate limits