How laude-institute/headlong works
Purpose and entry points
Headlong is a Bash-first persistent-agent harness. An identity maintains one append-only thought trajectory; background thinkers continue LLM-driven work while chat inputs become observations in that same stream. Installation and lifecycle begin at install.sh, status.sh, and uninstall.sh. Primary runtime commands are Bash executables in bin/, while host-side orchestration lives in tools/.
Agent execution core
shellm is the recursive LLM execution loop: render context, call an LLM, execute generated Bash, record results, and repeat. llm abstracts Anthropic, OpenAI, Gemini, and OpenRouter; shellm-docker constrains model-generated commands when Docker is available. Core paths: bin/shellm, bin/llm, bin/shellm-docker. The host-only Docker policy boundary is tools/shellm-docker-broker.
Durable trajectory and context
The system records work as append-only JSONL trajectory DAGs, supporting fork/merge rather than mutable session state. Context is a derived, tiered projection: recent events stay detailed while older history is progressively summarized and remains retrievable. This separates durable history from prompt construction. Core paths: bin/traj, bin/context, bin/recap. Memory and reusable procedures are filesystem-backed extensions: bin/mem, bin/skills.
Persistent thinker control plane
Thinkers implement the continuously running “mind”: a dispatcher invokes specialized thought processes, reacts to new observations, and applies inactivity/backoff behavior. The monolith is the general reasoning loop; responder handles conversational replies; retrieval builds/searches supporting indexes. Paths: thinkers/monolith/step, thinkers/responder/step, thinkers/retrieval/step. Shared shell behavior is centralized in thinkers/_lib/common.sh; subscriptions define which trajectory events wake each thinker.
Identity and human interaction boundary
Identities package persona, trajectory, memories, activation, and named user commands. Human messages and goals are written into the trajectory through the core CLIs; host utilities create/manage identities and expose named personas. Paths: bin/chat, bin/focus, tools/identity, tools/persona, tools/headlong-init. Skills provide agent-visible operational integrations, including Slack, Telegram, Google Workspace, and web research: skills/slack/SKILL.md, skills/telegram/SKILL.md, skills/web-research/SKILL.md.
External channels and dashboard
Slack and Telegram are separate Python bridge services that translate platform events into the shared trajectory and render agent-selected outbound responses. Paths: slack/src/headlong_slack/inbound.py, slack/src/headlong_slack/outbound.py, telegram/src/headlong_telegram/inbound.py, telegram/src/headlong_telegram/outbound.py. The dashboard is a Python API/server with a Bun/React viewer, covering trajectory, chat, thinker control, health, memories, and usage: web/src/headlong_web/server.py, web/src/headlong_web/chat.py, web/viewer/app/routes/timeline.tsx.
Deployment and operational runtime
A local install can run directly or sandbox generated commands with Docker; the long-lived deployment model uses systemd services for thinkers, web, and message bridges. Paths: deploy/thinkers-service.sh, deploy/headlong-web.service, deploy/headlong-slack-bridge.service. Terraform provisions dedicated AWS-based deployments and Slack alerting: deploy/terraform/main.tf, deploy/terraform-slack/main.tf, deploy/terraform-slack/lambda/slack_alert.py. Material dependencies are Bash, git, curl, jq, LLM provider APIs, Docker for recommended isolation, Python/uv for services, and Bun/Node for the web viewer.
Main entry points: traj Trajectory DAG · shellm Recursive execution loop · common.sh Thinker dispatcher · thinkers-service.sh Long-lived services
Components 20
Agent Core
- Recursive execution loop · Renders context, invokes a model, executes Bash, and records results.
bin/shellm - LLM provider adapter · Abstracts Anthropic, OpenAI, Gemini, and OpenRouter.
bin/llm - Sandboxed command runner
bin/shellm-docker - Docker policy broker · Host-only boundary for constrained generated commands.
tools/shellm-docker-broker
Durable State
- Trajectory DAG · Durable forkable and mergeable event history.
bin/traj - Tiered context projection · Keeps recent events detailed and summarizes older history.
bin/context - History recap
bin/recap - Memory & skills · Reusable procedures and agent-visible integrations.
bin/mem
Thinker Control Plane
- Thinker dispatcher · Subscriptions wake specialized processes on trajectory events.
thinkers/_lib/common.sh - General reasoning thinker
thinkers/monolith/step - Conversation responder
thinkers/responder/step - Retrieval thinker · Builds and searches supporting indexes.
thinkers/retrieval/step
Human & Channel Interfaces
- Identity management · Creates and manages personas, activation, and identity state.
tools/identity - Chat & goals · Writes human messages and goals as trajectory observations.
bin/chat - Slack & Telegram bridges · Translate channel events to trajectory observations and outbound replies.
slack/src/headlong_slack/inbound.py - Dashboard API · Provides trajectory, chat, thinker, health, memory, and usage operations.
web/src/headlong_web/server.py - Timeline viewer
web/viewer/app/routes/timeline.tsx
Deployment & Operations
- Install & lifecycle
install.sh - Long-lived services · Runs thinkers, web, and message bridges.
deploy/thinkers-service.sh - AWS deployment & alerts · Provisions dedicated deployments and Slack alerting.
deploy/terraform/main.tf
Connections 26
- Install & lifecycle → Identity management: initializes
- Identity management → Trajectory DAG: owns
- Chat & goals → Trajectory DAG: appends observations
- Trajectory DAG → Tiered context projection: projects
- History recap → Trajectory DAG: summarizes history
- Tiered context projection → Recursive execution loop: renders prompt context
- Recursive execution loop → LLM provider adapter: calls
- Recursive execution loop → Sandboxed command runner: uses when sandboxed
- Sandboxed command runner → Docker policy broker: enforces policy through
- Recursive execution loop → Trajectory DAG: records execution
- Memory & skills → Recursive execution loop: extends operations
- Trajectory DAG → Thinker dispatcher: event subscriptions
- Thinker dispatcher → General reasoning thinker: invokes
- Thinker dispatcher → Conversation responder: invokes
- Thinker dispatcher → Retrieval thinker: invokes
- General reasoning thinker → Recursive execution loop: drives reasoning work
- Conversation responder → Trajectory DAG: writes replies
- Retrieval thinker → Memory & skills: builds/searches support
- Slack & Telegram bridges → Trajectory DAG: translates inbound events
- Trajectory DAG → Slack & Telegram bridges: selected outbound responses
- Dashboard API → Trajectory DAG: reads and writes
- Timeline viewer → Dashboard API: uses
- Long-lived services → Thinker dispatcher: runs
- Long-lived services → Dashboard API: runs
- Long-lived services → Slack & Telegram bridges: runs
- AWS deployment & alerts → Long-lived services: provisions deployment