Repository navigation
AI Agent Mission
The agent_mission mission allows Marsy to accept a natural-language goal, ask a Groq-hosted LLM to convert it into a structured plan, validate the plan, and execute it through the existing Marsy skills layer.
The LLM never controls motors directly and cannot generate arbitrary Python code. It may only select whitelisted skills with bounded arguments.
The first AI Agent implementation includes:
- natural-language mission goals;
- Groq-based plan generation;
- strict JSON Structured Outputs;
- local plan validation before execution;
- a whitelist of safe Marsy skills;
- deterministic sonar-based direction selection;
- obstacle-aware short movements;
- bounded exploration through the shared
explore_areabehavior; - one or more optional replanning attempts after a blocked step;
- a single-entry plan cache;
- a single latest-run JSON journal;
- dashboard controls for real and simulated operation;
- live sonar values in the dashboard camera HUD;
- generated-plan display, including raw JSON;
- latest map viewing from the dashboard;
- a unified simulator launcher.
RGB LED control is currently disabled for this mission. The rover is initialized with LED brightness 0, so the AI Agent does not require rpi_ws281x access to /dev/mem.
Natural-language goal
β
Groq planner
β
Strict JSON plan
β
Plan validator
β
Agent executor
β
Marsy skills
β
Safety checks
β
Simulator or real rover
When a step is blocked:
Skill result: blocked / no clear direction / stale scan
β
Executor collects the failure and observations
β
Groq receives the remaining goal and execution context
β
Groq returns a replacement plan
β
Validator checks the replacement plan
β
Execution continues
The default maximum is one replanning attempt. The dashboard and CLI allow 0, 1, or 2.
marsy_agent/
βββ __init__.py
βββ cache.py
βββ executor.py
βββ journal.py
βββ models.py
βββ planner.py
βββ prompts.py
βββ specs.py
βββ validator.py
behaviors/
βββ explore_area.py
missions/
βββ agent_mission.py
βββ explore_area.py
scripts/
βββ run_real_dashboard.sh
βββ run_simulator.sh
The AI Agent does not launch missions.explore_area as a nested mission. Both agent_mission and the standalone explore_area mission use the shared behavior runner in:
behaviors/explore_area.py
The dashboard currently offers:
| Model | Recommended use |
|---|---|
openai/gpt-oss-20b |
Default model; fast and suitable for most Marsy plans |
openai/gpt-oss-120b |
Stronger model for more complex or ambiguous goals |
The default is:
openai/gpt-oss-20b
A model can also be selected with:
export MARSY_LLM_MODEL="openai/gpt-oss-20b"or through the dashboard dropdown.
- Create or sign in to a Groq Cloud account.
- Open the API Keys section.
- Create a new key.
- Copy it immediately and store it securely.
Never commit the key to GitHub or place it directly in project source files.
Activate the existing Marsy environment:
conda activate /Users/margarita_matson/opt/anaconda3/envs/marsyInstall the SDK:
python -m pip install groqCheck the installation:
python -c "from groq import Groq; print('Groq SDK OK')"Create a private environment file:
mkdir -p ~/.config/marsy
nano ~/.config/marsy/groq.envAdd:
export GROQ_API_KEY="YOUR_GROQ_API_KEY"Save the file and restrict its permissions:
chmod 600 ~/.config/marsy/groq.envLoad it in the current terminal:
source ~/.config/marsy/groq.envCheck that the key is available without printing it:
python -c "import os; print('Groq key loaded:', bool(os.getenv('GROQ_API_KEY')))"The Marsy simulator and real-dashboard launchers automatically load:
~/.config/marsy/groq.env
A different file can be selected with:
export MARSY_GROQ_ENV="/path/to/another/groq.env"Raspberry Pi OS may reject a system-wide pip install with:
error: externally-managed-environment
Create a project virtual environment instead. --system-site-packages keeps access to the Raspberry Pi GPIO and hardware packages already installed by the operating system.
cd /home/astrosheep/marsy
python3 -m venv --system-site-packages .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install groqIf the venv module is missing:
sudo apt update
sudo apt install -y python3-venvThen repeat the environment creation commands.
Check the SDK:
/home/astrosheep/marsy/.venv/bin/python \
-c "from groq import Groq; print('Groq SDK OK')"Store the key on the rover:
mkdir -p ~/.config/marsy
nano ~/.config/marsy/groq.envAdd:
export GROQ_API_KEY="YOUR_GROQ_API_KEY"Then:
chmod 600 ~/.config/marsy/groq.env
source ~/.config/marsy/groq.envThe real-dashboard launcher automatically uses:
/home/astrosheep/marsy/.venv/bin/python
when that environment exists.
Activate the Marsy environment:
conda activate /Users/margarita_matson/opt/anaconda3/envs/marsyFrom the project root:
chmod +x scripts/run_simulator.sh
./scripts/run_simulator.shThe launcher:
- selects the active Conda Python,
.venv, or another configured Python; - loads the Groq key;
- starts the PyQt simulator;
- waits for the simulator API on port
8523; - starts the Marsy dashboard in
simmode on port8080; - opens the dashboard in the browser;
- stops both processes when the simulator closes or
Ctrl+Cis pressed.
Dashboard:
http://127.0.0.1:8080/
Map viewer:
http://127.0.0.1:8080/maps
Simulator logs:
artifacts/logs/simulator_latest.log
artifacts/logs/simulator_dashboard_latest.log
To prevent the browser from opening automatically:
MARSY_OPEN_BROWSER=0 ./scripts/run_simulator.shOpen:
Missions β AI Agent
Available controls:
- Mission goal β multiline natural-language instruction;
- Groq model β model dropdown;
-
Maximum replans β
0,1, or2; - Generate a fresh plan β bypasses the current cached plan;
- Start mission;
- Open map;
- Stop current mission.
During execution, the dashboard displays:
- planning status;
- plan source;
- selected model;
- generated steps;
- currently executing step;
- replanned remaining steps;
- full raw JSON;
- live sonar samples;
- mission status;
- the latest occupancy map.
Simple smoke test:
Look around, choose the clearest direction, make one cautious 6 cm step, and stop.
Repeated scan and movement:
Look around, choose the clearest direction, make one cautious 6 cm step, scan again, choose the clearest direction again, make one more cautious 6 cm step, wait for 2 seconds, and stop. If a path is blocked, try another direction.
Exploration:
Look around, choose the clearest direction, make three cautious steps, explore for 30 seconds, and stop. If the path is blocked, try another direction.
For a new goal, enable Generate a fresh plan once. Later runs with exactly the same goal and model can use the cached plan.
Connect to the rover:
ssh astrosheep@marsrover.local
cd /home/astrosheep/marsyRestart the dashboard using the project scripts:
./scripts/kill_dashboard.sh
./scripts/run_real_dashboard.shThe launcher sets:
MARSY_MODE=real
MARSY_CAMERA_ROTATION=90
MARSY_WEB_PORT=8080
It also loads the stored Groq key and selects .venv/bin/python when available.
Open the dashboard:
http://marsrover.local:8080/
Use:
Missions β AI Agent
For the first physical test, use:
Look around, choose the clearest direction, make one cautious 6 cm step, and stop.
Set:
Model: GPT-OSS 20B
Maximum replans: 0
Generate a fresh plan: enabled
After the first successful run, longer missions and replanning can be enabled.
Before starting:
- place Marsy on a clear floor area;
- keep hands away from wheels and steering servos;
- use short distances and low speeds for first tests;
- keep physical power controls accessible;
- do not run the standalone mission while the dashboard is using the hardware;
- use Stop current mission if movement is unexpected;
- stop the dashboard before running a standalone real-mode command.
The executor always attempts a final stop even after a failure or interruption.
This does not load the simulator or real backend:
python -m missions.agent_mission \
--goal "Look around, make one cautious step, and stop" \
--dry-runForce a new Groq request:
python -m missions.agent_mission \
--goal "Look around, make one cautious step, and stop" \
--refresh-plan \
--dry-runDisable the cache:
python -m missions.agent_mission \
--goal "Look around, make one cautious step, and stop" \
--no-cache \
--dry-runThe mock planner allows testing without Groq:
MARSY_MODE=sim python -m missions.agent_mission \
--planner mock \
--goal "Look around, make a cautious step, explore briefly, and stop"It produces a deterministic cautious plan.
The simulator must already be running:
MARSY_MODE=sim python -m missions.agent_mission \
--model openai/gpt-oss-20b \
--max-replans 1 \
--goal "Look around, choose the clearest direction, make three cautious steps, explore for 30 seconds, and stop."The unified scripts/run_simulator.sh dashboard workflow is recommended instead of this standalone form.
Stop the dashboard first:
./scripts/kill_dashboard.shThen:
MARSY_MODE=real \
/home/astrosheep/marsy/.venv/bin/python \
-m missions.agent_mission \
--model openai/gpt-oss-20b \
--max-replans 0 \
--goal "Look around, choose the clearest direction, make one cautious 6 cm step, and stop."Restart the dashboard afterward:
./scripts/run_real_dashboard.shThe Groq planner receives:
- the user goal;
- the allowed skill catalog;
- hard argument limits;
- instructions to return only a strict JSON plan.
Example:
{
"version": 1,
"goal": "Look around and make one cautious step",
"steps": [
{
"id": "step_1",
"skill": "turn_to_clear_direction",
"arguments": {
"rotate_speed": 22
}
},
{
"id": "step_2",
"skill": "move_forward",
"arguments": {
"distance_cm": 6,
"speed": 22,
"require_recent_scan": true
}
},
{
"id": "step_3",
"skill": "stop",
"arguments": {
"brake": false,
"reset_pose": true
}
}
]
}Groq Structured Outputs ensure that the response matches the JSON schema. Marsy still performs its own local validation before execution.
The current whitelist is:
| Skill | Purpose |
|---|---|
scan_arc |
Sweep the mast sonar over a bounded arc |
turn_to_clear_direction |
Select and verify a clear direction using deterministic sonar logic |
move_forward |
Move forward with recent-scan and obstacle checks |
move_backward |
Short bounded reverse movement |
turn_left |
Bounded left arc |
turn_right |
Bounded right arc |
rotate |
Bounded in-place rotation |
explore_for |
Run the shared deterministic exploration behavior |
wait |
Wait without moving |
stop |
Stop and reset the rover pose |
The LLM cannot call hardware methods such as rover.forward() directly.
Important current limits include:
Maximum plan steps: 8
Maximum replans: 2 through CLI/dashboard
Maximum movement speed: 35
Maximum forward distance: 30 cm
Maximum reverse distance: 15 cm
Maximum rotation: 180Β°
Maximum wait: 30 seconds
Maximum exploration: 180 seconds
The validator also checks:
- plan version;
- known skills only;
- exact required arguments;
- no additional arguments;
- numeric ranges;
- unique step IDs;
- final
stopstep; - no steps after
stop.
turn_to_clear_direction does not ask the LLM to interpret raw sonar numbers.
It:
- performs a seven-angle scan;
- chooses the best valid side;
- commits to that turn direction;
- rotates in approximately 30Β° increments;
- scans again after each turn;
- continues for up to four turns;
- returns success when a usable corridor is found;
- returns a replannable failure if no corridor is found.
This prevents the LLM from choosing arbitrary steering angles and avoids oscillating between left and right after every scan.
explore_for uses the same implementation as the standalone explore_area mission.
The behavior:
- scans the environment;
- uses deterministic obstacle avoidance;
- makes cautious progress when sonar readings are incomplete;
- performs committed turns;
- updates the SLAM-lite occupancy map;
- stops after the requested duration or maximum number of steps.
The tested cautious movement setting is:
Step distance: 6 cm
Speed: 22
Replanning is attempted only for selected recoverable outcomes, including:
blocked
range_unknown
stale_scan
unknown
no_clear_direction
no_progress
Groq receives:
- the original goal;
- completed steps;
- the failed step;
- failure status and message;
- sensor observations;
- remaining replanning allowance.
It returns only a new remaining plan. The replacement plan is validated before execution.
A cached initial plan does not eliminate the need for a Groq key: replanning may still require a new API request.
Marsy stores only the latest initial plan:
artifacts/agent_cache/agent_plan_latest.json
A cache hit requires an exact match for:
- normalized goal text;
- planner;
- model;
- planner schema and system-prompt fingerprint.
The cache is automatically ignored if the skill schema or prompt changes.
Dashboard option:
Generate a fresh plan
CLI options:
--refresh-plan
--no-cache
Replanned plans are not reused as the initial plan for future missions.
Marsy stores only the latest agent run:
artifacts/agent_runs/agent_mission_latest.json
The journal contains:
- goal;
- planner;
- model;
- plan source;
- initial plan;
- execution report;
- step records;
- replans;
- final status;
- error information.
Older timestamped agent journals are removed automatically.
The latest map is stored as:
artifacts/maps/explore_area_latest.json
artifacts/maps/explore_area_latest.svg
Open the map viewer from the mission card or directly:
http://127.0.0.1:8080/maps
For the real rover:
http://marsrover.local:8080/maps
The dashboard keeps the current map artifacts rather than accumulating one pair per run.
The Generated plan panel shows:
-
Groq,plan cache, orGroq replanas the source; - model name;
- plan revision;
- number of steps;
- skill names;
- skill arguments;
- current executing step;
- raw JSON.
After replanning, the panel is replaced with the new remaining plan.
Run the agent and dashboard integration tests:
python -m unittest \
tests.test_agent_mission \
tests.test_agent_dashboard_integration \
-vCompile the main runtime files:
python -m py_compile \
behaviors/explore_area.py \
missions/explore_area.py \
missions/agent_mission.py \
marsy_agent/*.pyLoad the key:
source ~/.config/marsy/groq.envThen verify:
python -c "import os; print(bool(os.getenv('GROQ_API_KEY')))"A matching cached plan may run without a new initial API request, but replanning still needs the key.
Install it in the active environment:
python -m pip install groqOn Raspberry Pi OS, use the project .venv rather than system-wide pip.
Create the Raspberry Pi virtual environment:
python3 -m venv --system-site-packages .venv
source .venv/bin/activate
python -m pip install groqDo not use --break-system-packages.
The simulator launcher uses:
Simulator API: 127.0.0.1:8523
Dashboard: 127.0.0.1:8080
Stop an older simulator/dashboard instance before restarting.
Activate the Marsy Conda environment before running:
conda activate /Users/margarita_matson/opt/anaconda3/envs/marsy
./scripts/run_simulator.shThe launcher prints which Python interpreter it selected.
Do not run both against the same real rover hardware.
Before a standalone mission:
./scripts/kill_dashboard.shAfterward:
./scripts/run_real_dashboard.shEnable:
Generate a fresh plan
or run with:
--refresh-planThe new plan replaces the single cached plan.
Dashboard:
Stop current mission
Standalone CLI:
Ctrl+C
The executor attempts a final motor stop in both cases.
- The AI Agent currently uses sonar and rover state, not camera/VLM observations.
- Only whitelisted skills can appear in plans.
-
turn_to_clear_directionis deterministic rather than LLM-controlled. - The plan is currently flat; nested conditions and loops are not part of the schema.
- Only the latest cache, journal, and map are retained.
- Replanning is bounded to prevent indefinite autonomous behavior.
- RGB LED status is currently disabled.