Private AI agent operating system built with FastAPI, LangGraph, LiteLLM, OpenRouter model routing, Postgres, Redis, Qdrant, and modular chat gateways.
Agent_Sam now includes a specialist multi-agent runtime with profile-based routing, per-agent model escalation, budget controls, learning events, and approval-gated skill or sub-agent proposals.
cd F:\personal\Agent_Sampython -m pip install -e ".[dev]"python -m scripts.setuppython -m scripts.doctorpython -m scripts.run
python -m scripts.run now opens the Agent_Sam Control Center with:
- Setup / Reconfigure
- Doctor
- Start API
- Start Worker
- Start Gateways
- Start CLI Gateway
- Show Agents
- Show Models
- Show Budgets
- Show Pending Skill Proposals
- Show Pending Sub-Agent Proposals
- Approve Skill Proposal
- Approve Sub-Agent Proposal
- Exit
app/ FastAPI application
agent/ LangGraph state, nodes, and graph assembly
harness/ OpenHands-style execution loop, runtime, tools, and workspaces
gateways/ External entry points such as Telegram, CLI, and webhooks
workers/ Background task worker skeleton
db/ SQLAlchemy models and session helpers
skills/ YAML skill definitions
tools/ Safe tool wrapper registry
.devcontainer/ VS Code Dev Container configuration
deployment/ Linux deployment scripts, systemd units, and nginx example
-
Copy
.env.exampleto.env. -
Start local infrastructure:
docker compose up -d -
Create and activate a virtual environment:
python -m venv .venv .\.venv\Scripts\Activate.ps1 -
Install the project in editable mode:
pip install --upgrade pip pip install -e .[dev]
Seed development IDs before running agent flows that depend on DEFAULT_WORKSPACE_ID and DEFAULT_USER_ID:
docker compose up -d postgres redis qdrant
alembic upgrade head
python scripts/seed_dev.pyCopy the printed DEFAULT_WORKSPACE_ID and DEFAULT_USER_ID values into .env.
Configure gateways with the gateway-only wizard before starting them:
python -m gateways.setupOr use the full Hermes-style setup wizard:
python -m scripts.setup-
Start the API:
uvicorn app.main:app --reload -
Start the worker in a second terminal:
agent-sam-worker
-
Start one or more gateways after setting
DEFAULT_WORKSPACE_IDandDEFAULT_USER_IDto existing database IDs. The shared runner readsENABLED_GATEWAYSfrom.env:agent-sam-gateways
Direct gateway entrypoints still work when you want to run a single transport:
agent-sam-cli agent-sam-telegram
The built-in CLI gateway exits with
/exit. The webhook gateway is served by the API process whenwebhookis included inENABLED_GATEWAYS.
See docs/gateways.md for gateway architecture, the setup wizard, env vars, and the webhook payload contract.
docker compose up -d postgres redis qdrant
alembic upgrade head
python scripts/seed_dev.py
python -m workers.main
python -m gateways.cli.main
python -m gateways.telegram.main
python -m gateways.runnerpython -m gateways.setup
python -m gateways.setup --show-enabled
python -m gateways.setup --test-config
python -m gateways.setup --disable telegramCommon runtime commands from the CLI or Telegram gateway:
Normal conversation gets an inline reply. Use /new <task description> or an explicit work request when you want a tracked task.
If ENABLE_WEB_RESEARCH=true, requests such as checking the internet, finding the latest docs, or browsing public sources are routed as tracked research work instead of answered with a shallow inline guess.
/agents/agent <slug>/route <task_id>/models/budget/skills pending/skills approve <proposal_id>/subagents pending/subagents approve <proposal_id>/code <task description>/test <task_id>/pr <task_id>/events <task_id>/workspace <task_id>
Agent_Sam now includes an OpenHands-inspired harness layer that stays under the existing LangGraph specialist runtime instead of replacing it. When HARNESS_ENABLED=true, coding, testing, browser, and server-oriented tasks can run through a typed action/observation loop with:
- append-only
agent_eventshistory - task-scoped workspaces under
AGENT_WORKSPACES_DIR - patch-based file editing with rollback metadata
- approval-gated installs, GitHub actions, and risky browser flows
- LiteLLM/OpenRouter model calls through the existing
ModelRouter - offline dependency source lookup through
opensrc
See the harness docs for the exact behavior and configuration:
docs/openhands-adaptation.mddocs/harness.mddocs/events.mddocs/workspaces.mddocs/tool-system.mddocs/source-cache.mddocs/github-automation.mddocs/coding-workflow.md
- Worker looks stuck: it is polling the task queue; the worker now logs when it is ready and when there are no pending tasks.
- CLI exits after first message: this should now be fixed; run
python -m scripts.doctorand verify Postgres plus seeded IDs. - Telegram token appears in logs: rotate the token in BotFather immediately.
- Postgres connection refused: run
docker compose up -d postgres. - DEFAULT_WORKSPACE_ID missing: run
python scripts/seed_dev.py. - Alembic ProactorEventLoop error on Windows: use the
WindowsSelectorEventLoopPolicyhelper paths already wired into entrypoints. - Telegram CancelledError on Ctrl+C: expected shutdown is now suppressed; if you still see a token in logs, rotate it.
See docs/setup.md, docs/doctor.md, docs/gateways.md, and docs/troubleshooting.md for the full walkthroughs.
Harness docs:
docs/harness.mddocs/events.mddocs/workspaces.mddocs/tool-system.mddocs/source-cache.mddocs/github-automation.mddocs/coding-workflow.md
Specialist-agent docs:
docs/agents.mddocs/model-routing.mddocs/openrouter.mddocs/budgets.mddocs/self-evolution.md
Open the folder in VS Code and choose Reopen in Container.
The devcontainer uses the root docker-compose.yml for Postgres, Redis, and Qdrant, then adds a dedicated workspace service for Python development. When the app runs inside the devcontainer, use service hostnames in .env:
postgresinstead oflocalhostredisinstead oflocalhostqdrantinstead oflocalhost
Use the deployment bundle in deployment/linux/.
Recommended server sequence:
bash <(curl -fsSL https://raw.githubusercontent.com/samlaggz/Agent-Sam/main/install.sh)If you already have a checkout on the server, bash install.sh still works from the repo root.
For a private GitHub repo, export a read-capable token first and use the GitHub contents API:
export AGENT_SAM_GITHUB_TOKEN=<github_pat_with_repo_read>
bash <(curl -fsSL -H "Authorization: Bearer ${AGENT_SAM_GITHUB_TOKEN}" -H "Accept: application/vnd.github.raw" https://api.github.com/repos/samlaggz/Agent-Sam/contents/install.sh?ref=main)Use the pipe form only for fully non-interactive installs where all required env vars are already exported.
The installer is idempotent, writes .env without printing secrets, bootstraps the app as agentos, runs migrations, auto-seeds DEFAULT_USER_ID and DEFAULT_WORKSPACE_ID when needed, runs the production doctor, and can optionally install nginx plus start services.
Preview the full flow safely with:
bash <(curl -fsSL https://raw.githubusercontent.com/samlaggz/Agent-Sam/main/install.sh) --dry-run
bash install.sh --dry-run
python -m scripts.setup --dry-run
python -m scripts.doctor --production --fixManual fallback sequence:
bash deployment/linux/install-host-assets.sh /opt/agent-sam
sudo rsync -a --delete --exclude '.git' --exclude '.venv' ./ /opt/agent-sam/
sudo chown -R agentos:agentos /opt/agent-sam
sudo -iu agentos
cd /opt/agent-sam
bash deployment/linux/bootstrap-app.sh
# edit /opt/agent-sam/.env
bash deployment/linux/bootstrap-app.sh
python -m scripts.doctor --production
exit
sudo systemctl daemon-reload
sudo systemctl enable agent-api agent-worker agent-telegram
sudo systemctl start agent-api agent-worker agent-telegram
sudo systemctl status agent-api agent-worker agent-telegram
sudo journalctl -u agent-api -f
sudo journalctl -u agent-worker -f
sudo journalctl -u agent-telegram -fThe systemd units run as agentos from /opt/agent-sam, the API binds to 127.0.0.1:8000, and deployment/nginx/agent-api.conf is the reverse-proxy example. deployment/linux/service-control.sh now supports the shorthand forms below if you prefer not to type the raw systemctl commands:
bash deployment/linux/service-control.sh status
bash deployment/linux/service-control.sh logs
bash deployment/linux/service-control.sh restart apiWhen installing the nginx config after the app has been synced to /opt/agent-sam, use the absolute path:
sudo install -m 0644 /opt/agent-sam/deployment/nginx/agent-api.conf /etc/nginx/sites-available/agent-api.confSee deployment/linux/README.md for the full flow.
- Flesh out the LangGraph workflow in
agent/. - Replace the placeholder worker loop with a real queue consumer.
- Add database migrations and richer domain models.
- Flesh out the WhatsApp, Discord, Slack, and outbound webhook adapters.