Skip to content

Repository files navigation

Long-Running Autonomous Agent

An open-source, persistent autonomous AI agent that can run for hours or days, with:

  • Continuous execution loop
  • Goal planning and adaptation (Groq)
  • E2B sandbox execution for actions
  • Long-term memory in SQLite
  • Resume across sessions
  • API control plane for start/stop/status/output
  • Results-only output mode (computation output only)

This repository is designed to be self-hosted and extended locally. It includes a Python backend, a Vite/React frontend, and .env.example files to make setup reproducible.

Architecture

  • FastAPI API server for orchestration.
  • AutonomousAgent background loop for planning, execution, reflection, and memory updates.
  • GroqPlanner for planning and episode summarization.
  • E2BExecutor for Python code execution in a secure sandbox.
  • AgentStorage for persistent sessions, episodes, and long-term memory.

Project Structure

  • src/autonomous_agent/app.py - FastAPI app and routes
  • src/autonomous_agent/agent.py - long-running control loop
  • src/autonomous_agent/llm.py - Groq integration
  • src/autonomous_agent/e2b_runner.py - E2B code execution adapter
  • src/autonomous_agent/storage.py - SQLite persistent state
  • src/autonomous_agent/main.py - API/CLI entrypoint

Environment

Use .env (already present in your workspace):

  • GROQ_API_KEY
  • GROQ_MODEL
  • E2B_API_KEY
  • E2B_TIMEOUT_SECONDS
  • E2B_STEP_TIMEOUT_SECONDS
  • AGENT_DB_PATH
  • AGENT_MAX_FULL_EPISODES
  • AGENT_MAX_ITERATIONS
  • AGENT_CYCLE_SLEEP_SECONDS
  • FRONTEND_ORIGINS
  • FRONTEND_ORIGIN_REGEX

Frontend-specific variables live in frontend/.env.example.

Install

pip install -r requirements.txt
pip install -e .

Run API

python -m autonomous_agent.main --mode api

API endpoints:

  • GET /health
  • POST /agent/start body: { "goal": "...", "session_id": "optional" }
  • POST /agent/stop
  • GET /agent/status?session_id=...
  • GET /agent/output?session_id=...&limit=20
  • GET /agent/logs?session_id=...&limit=200
  • GET /system/logs?limit=300

Run CLI (results-only)

python -m autonomous_agent.main --mode cli --goal "Solve X step by step"

CLI prints only computation output generated by the agent. Internal logs are stored in logs/agent.log.

Frontend UI

The project now includes a production-ready frontend in frontend/ with:

  • Goal input and start/resume controls
  • Stop control
  • Live session status and iteration tracking
  • Computation output stream view (results-only)
  • Live runtime logs and system/API logs panel

Frontend setup:

cd frontend
copy .env.example .env
npm install
npm run dev

Frontend environment variable:

  • VITE_API_BASE_URL (default http://localhost:8000)

Build frontend for production:

cd frontend
npm run build

Production Notes

  • State persists in SQLite (data/agent_state.db) across process restarts.
  • Memory updates happen each iteration using concise episode summaries.
  • The loop is resumable by reusing session_id.
  • Logging is file-only for clean stdout behavior.
  • Use process supervision in production (systemd, Docker restart policy, PM2, or Kubernetes).

Open Source

This project is open source. If you publish or redistribute it, add the appropriate LICENSE file for the terms you want to use and keep the existing setup instructions current.

Example Start Request

curl -X POST http://localhost:8000/agent/start \
  -H "Content-Type: application/json" \
  -d '{"goal":"Collect top 5 AI headlines and summarize trends"}'

Output-Only Contract

To satisfy your requirement that the program should only show computation output:

  • CLI stdout prints only episode outputs.
  • API output endpoint returns only outputs list and session status.
  • Internal diagnostics are written to logs/agent.log.

About

A self-hosted autonomous AI agent that runs continuously, plans with LLMs, executes code in a secure sandbox, and maintains persistent memory,featuring resumable sessions, API control, and results-only output.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Contributors

Languages