Run, track, and iterate on federated learning (FL) experiments from a single terminal.
- Flower powers the server/client runtime.
- MongoDB stores runs/rounds/metrics.
- A lightweight LLM agent (via Google Gemini using
google-genai) turns natural language into actions like
run 3 rounds with FedAdam (lr 0.005, local-epochs 2, fraction-train 0.6)
and suggests the next configuration based on results.
Federated experiments involve lots of knobs (strategy, rounds, epochs, lr, sampling…). Keeping track of runs and quickly doing the “next sensible thing” is tedious. This project:
- Orchestrates Flower runs from natural language.
- Logs everything to Mongo (
runs,rounds) with robust metric capture. - Suggests next configs based on recent outcomes, so you can iterate faster.
aicontroller/
aicontroller/
__init__.py
agent_runner.py
client_app.py # dataset/model/training (SOCOFing demo task)
llm_agent_cli.py # the terminal agent (entrypoint you run)
server_app.py # Flower ServerApp entrypoint
tracking_strategy.py # strategy wrapper -> unified hooks + Mongo logging
data/ # put dataset under here (see below)
pyproject.toml
README.md
- Python 3.9+ (tested on 3.9)
- Flower (>= 1.22 recommended)
- MongoDB running locally (or set
MONGODB_URI) - Google API access (set
GOOGLE_API_KEY) and installgoogle-genai - PyTorch (CPU is fine)
- SOCOFing dataset (for the included demo task)
You can switch the Gemini model in
llm_agent_cli.pyor viaAIC_GOOGLE_MODEL.
# 1) Clone and enter
git clone <YOUR_REPO_URL> FlowerHackathon
cd FlowerHackathon/aicontroller
# 2) Create env and install
python -m venv env
source env/bin/activate
python -m pip install -U pip
pip install -e .
# 3) Optional quick checks
flwr --version
python -c "import pymongo; print('pymongo ok')"
python -c "from google import genai; print('google-genai ok')"Place the dataset under data/SOCOFing or set AIC_DATA_ROOT (see env vars).
Expected layout:
data/
SOCOFing/
Real/...
Altered/
Altered-Easy/...
Altered-Medium/...
Altered-Hard/...
If the scanner prints “found 0 images”, your path is wrong or the layout doesn’t match.
Most have sensible defaults, but you can override:
| Var | What it does | Default |
|---|---|---|
MONGODB_URI |
Mongo connection | mongodb://localhost:27017 |
MONGODB_DB |
Database name | flwr_runs |
GOOGLE_API_KEY |
API key for Gemini (google-genai) | — (required) |
AIC_GOOGLE_MODEL |
Gemini model name | gemini-2.0-flash |
AIC_DATA_ROOT |
Dataset root | <repo>/data |
AIC_LABEL_MODE |
binary or fourclass |
binary |
AIC_NUM_PARTITIONS |
Num of client partitions | 5 |
AIC_AGENT_LOG_LEVEL |
Agent logging | INFO |
AIC_AGENT_MONGO_LOCK_ENABLE |
Avoid overlapping runs | true |
Logs are written to ~/.cache/aicontroller/llm_agent.log and a JSONL event stream.
From the app directory (aicontroller/):
cd aicontroller
source env/bin/activate
export GOOGLE_API_KEY=<your_key>
python -m aicontroller.llm_agent_cli --model "${AIC_GOOGLE_MODEL:-gemini-2.0-flash}"You’ll see a prompt like:
agent>
These do not involve the LLM and are guaranteed to work deterministically:
status– shows whether a run is in progress.tool list– prints available tools.listorlist runs– table of recent runs from Mongo.unlock– clears a stuck run-lock if a previous run crashed.- Run shortcut
The agent converts it into
run 1 rounds with FedAvg (lr 0.01, local-epochs 2, fraction-train 0.6)flwr run . --run-config ...for you. - Show round details
show rounds <RUN_OBJECT_ID> - Summaries
summarize latest summarize <RUN_OBJECT_ID> - Suggestions
suggest next suggest <RUN_OBJECT_ID> - Compare strategies
compare strategies FedAvg, FedAdam (limit 20)
You can still chat in natural language; the agent will try to interpret and route to a tool. The local commands above are the fastest path during demos.
The agent exposes a small toolbelt; each tool is also wired to a local command.
| Tool name | Purpose | Inputs | Output (shown as rich tables/panels) |
|---|---|---|---|
run_flower |
Launch Flower with a config | num-server-rounds, local-epochs, fraction-train, lr, strategy, data-root, label-mode, num-partitions |
Starts run; prints launch status |
list_runs |
List recent runs from Mongo | limit, strategy (optional filter) |
Table with Run ID, strategy, timestamps, status |
show_rounds |
Per-round metrics for a run | run_id |
Table with round/phase/eval acc/avg train loss |
summarize_run |
Compact summary | run_id or latest=true |
Panel with best acc, last train loss, tips |
suggest_next |
Suggest a next run config | run_id or latest=true |
Strategy/rounds/epochs/lr proposal with rationale |
compare_strategies |
Quick leaderboard by strategy | strategies[], limit |
Grouped tables with best/last acc, loss, hyperparams |
-
LLM Agent (
llm_agent_cli.py)- Talks to Ollama for natural language.
- Parses your commands or the LLM’s JSON and dispatches tools.
- Enforces a run lock to prevent overlapping runs.
- Shows results cleanly (no raw JSON).
-
ServerApp (
server_app.py) +TrackingStrategy- Wraps the Flower strategy to normalize
aggregate_*signatures across versions. - Logs runs and rounds to Mongo (including client metrics when available).
- Marks runs
running → completed/failedreliably.
- Wraps the Flower strategy to normalize
-
ClientApp (
client_app.py)- Implements the demo SOCOFing task:
- Small CNN (grayscale, 96×96).
- IID partitioning, 80/20 split per partition.
label-mode:binary(Real vs Altered) orfourclass(alteration type).
- Implements the demo SOCOFing task:
# 1) Start the agent
python -m aicontroller.llm_agent_cli
# 2) Launch a short run
agent> run 1 rounds with FedAvg (lr 0.01, local-epochs 1, fraction-train 0.6)
# 3) Watch status and list runs
agent> status
agent> list
# 4) Summarize and inspect
agent> summarize latest
# copy a Run ID from the list:
agent> show rounds 68d73981da6ed952028f442e
# 5) Get a next-step proposal
agent> suggest next
# 6) Try a different strategy
agent> run 1 rounds with FedAdam (lr 0.01, local-epochs 1, fraction-train 0.6)
# 7) Compare strategies
agent> compare strategies FedAvg, FedAdam (limit 10)
You can bypass the agent and invoke Flower yourself:
cd aicontroller && source env/bin/activate
flwr run . --run-config 'num-server-rounds=3 local-epochs=2 fraction-train=0.6 lr=0.01 strategy="FedAvg" data-root="/ABS/PATH/TO/data" label-mode="binary" num-partitions=5'Start the federation in three terminals:
# Terminal 1: SuperLink
flower-superlink \
--insecure \
--fleet-api-address 0.0.0.0:9092 \
--control-api-address 0.0.0.0:9093
# Terminal 2: SuperNode (client partition 0)
flower-supernode \
--insecure \
--superlink localhost:9092 \
--node-config 'partition-id=0 num-partitions=5'
# Terminal 3: SuperNode (client partition 1)
flower-supernode \
--insecure \
--superlink localhost:9092 \
--node-config 'partition-id=1 num-partitions=5' \
--clientappio-api-address 0.0.0.0:9095Then launch the agent and target the configured federation remote-federation (from pyproject.toml):
cd aicontroller && source env/bin/activate
export GOOGLE_API_KEY=<your_key>
# Option A: env var
export FLWR_FEDERATION=remote-federation
python -m aicontroller.llm_agent_cli --model "${AIC_GOOGLE_MODEL:-gemini-2.0-flash}"
# Option B: set inside the REPL
# agent> use federation remote-federationRun a short test round from the REPL:
agent> run 1 rounds with FedAvg (lr 0.01, local-epochs 1, fraction-train 0.6)
agent> list
agent> summarize latest
-
“found 0 images”
Fix your dataset path/layout. CheckAIC_DATA_ROOTand ensuredata/SOCOFing/...exists as shown above. -
Show/Suggest “does nothing”
Use the local forms (show rounds <id>,suggest next) which bypass the LLM. -
“Project configuration could not be loaded. pyproject.toml does not exist.”
Run the agent fromaicontroller/(wherepyproject.tomllives) or set the working directory accordingly. The agent also auto-detectsaicontroller/when launched from repo root. -
“run lock present” after a crash
Rununlockat the prompt. -
Mongo not updating
Ensure Mongo is reachable (MONGODB_URI). Collections used:runs,rounds. -
Gemini errors
EnsureGOOGLE_API_KEYis set and that your key has access to the requested model (e.g.,gemini-2.0-flash). You can change the model via--modelorAIC_GOOGLE_MODEL. -
Flower aggregate_ signature errors*
The includedtracking_strategy.pyhandles multiple signatures. If you see version-mismatch issues, upgrade Flower and reinstall this package:pip install -e .
- Built for the Flower Hackathon; uses the excellent Flower FL framework.
- Demo task adapted to the SOCOFing fingerprint dataset.
- Local LLM orchestration via Ollama.
status tool list list run 1 rounds with FedAvg (lr 0.01, local-epochs 1, fraction-train 0.6) status list summarize latest
show rounds <RUN_ID> suggest next compare strategies FedAvg, FedAdam (limit 5) unlock

