How gparab/absolute-self-governance works
Purpose and Entry Points
Absolute Self-Governance (ASG) is a Python 3.11+ agent-orchestration package that sizes role-based software-agent swarms, reaches roster consensus, and coordinates phase handoffs. Primary entry points are the packaged CLI in src/self_governance/cli.py, local watcher/dev runtime in src/self_governance/nudger.py and src/self_governance/devserver.py, GitHub webhook service in src/self_governance/github_app.py, and stdio MCP server in src/self_governance/mcp_server.py.
Core Orchestration Lifecycle
A filesystem bus connects external IDE/agent runners to ASG. ContinuousNudger watches a workspace handoff.md; a completed handoff triggers candidate extraction, consensus, swarm sizing, and generated next-phase prompt/configuration output. Dry-run approval can pause this transition before execution.
• src/self_governance/nudger.py
• src/self_governance/consensus.py
• src/self_governance/dimensioning.py
Consensus and Swarm Sizing
TETD consensus iteratively approves a successor roster, adjusting temperature and approval thresholds to avoid deadlock. Dimensioning converts a requirement vector through a transition matrix into per-role counts. Its lazy agent representation allows large theoretical swarms without eagerly allocating every agent.
• src/self_governance/consensus.py
• src/self_governance/dimensioning.py
• src/self_governance/models.py
Agent Execution and Provider Boundary
Adapters separate orchestration from LLM-backed execution. The Gemini adapter supports structured file-edit responses and sandbox/path safeguards; provider routing can select Gemini or OpenRouter-compatible models based on credentials. Persona and capability injection supply role-specific instructions from the catalog and ability definitions.
• src/self_governance/base_adapter.py
• src/self_governance/gemini_adapter.py
• src/self_governance/providers.py
• src/self_governance/agency_agents_adapter.py
Governance, Safety, and Learning
Policy rules, injection defense, anti-drift controls, and security checks constrain commands, paths, budgets, rate limits, and sandbox routing. Feedback/learning modules adapt swarm behavior, while memory modules retain procedural, graph, and extracted-fact context across work.
• src/self_governance/policy.py
• src/self_governance/policy_rules/
• src/self_governance/injection_defense.py
• src/self_governance/learning.py
• src/self_governance/graph_memory.py
Service and Persistence Plane
The GitHub-facing FastAPI application exposes authenticated webhook/status operations for multi-tenant use. SQLAlchemy persistence supports SQLite or PostgreSQL; Alembic owns schema migration. Auth, billing, and alerts provide tenant protection, token/cost accounting, and operational escalation.
• src/self_governance/github_app.py
• src/self_governance/db.py
• src/self_governance/auth.py
• src/self_governance/billing.py
• alembic/versions/d6c85050648f_initial_schema.py
Operations and Deployment
Local dev mode provides a localhost dashboard and Prometheus metrics. Telemetry supports structured correlation/logging and OpenTelemetry OTLP or console tracing. Production packaging includes a non-root Docker image and Kubernetes webhook deployment reference; PostgreSQL, GitHub webhooks/HMAC secrets, Gemini/OpenRouter, Prometheus, and OTLP are material external integrations.
• src/self_governance/dashboard.py
• src/self_governance/metrics.py
• src/self_governance/tracing.py
• Dockerfile
• k8s-webhook.yaml
Main entry points: nudger.py Continuous Nudger · github_app.py GitHub Webhook API · base_adapter.py Agent Adapter Layer · providers.py Provider Router
Components 18
Entry Points
- Packaged CLI
src/self_governance/cli.py - MCP Server
src/self_governance/mcp_server.py
Orchestration Core
- Continuous Nudger · Watches handoff.md and coordinates phase transitions.
src/self_governance/nudger.py - TETD Consensus · Iteratively approves successor rosters while avoiding deadlock.
src/self_governance/consensus.py - Swarm Dimensioning · Maps requirements to per-role swarm counts.
src/self_governance/dimensioning.py - Lazy Agent Models · Represents large theoretical swarms without eager allocation.
src/self_governance/models.py - Learning & Graph Memory · Retains procedural, graph, and extracted-fact context.
src/self_governance/learning.py
Agent Execution & Safety
- Agent Adapter Layer
src/self_governance/base_adapter.py - Provider Router · Selects Gemini or OpenRouter-compatible providers by credentials.
src/self_governance/providers.py - Gemini Adapter · Handles structured file edits and sandbox safeguards.
src/self_governance/gemini_adapter.py - Persona & Capabilities
src/self_governance/agency_agents_adapter.py - Governance Guardrails · Constrains commands, paths, budgets, rates, and prompt injection.
src/self_governance/policy.py
Service & Persistence
- GitHub Webhook API · Authenticated multi-tenant webhook and status service.
src/self_governance/github_app.py - SQLAlchemy Persistence · Supports SQLite and PostgreSQL tenant state.
src/self_governance/db.py - Auth & Billing · Protects tenants and tracks tokens and cost.
src/self_governance/auth.py
Operations
- Dashboard & Metrics · Provides localhost dashboard and Prometheus metrics.
src/self_governance/dashboard.py - Telemetry Tracing · Emits correlated logs and OTLP or console traces.
src/self_governance/tracing.py
Other components
- LLM Providers · Gemini and OpenRouter-compatible models.
Connections 19
- Packaged CLI → Continuous Nudger: runs local lifecycle
- MCP Server → Continuous Nudger: invokes orchestration
- GitHub Webhook API → Continuous Nudger: webhook-triggered work
- Continuous Nudger → TETD Consensus: extracts candidates
- TETD Consensus → Swarm Dimensioning: approved roster
- Swarm Dimensioning → Lazy Agent Models: creates lazy swarm
- Continuous Nudger → Agent Adapter Layer: generates next-phase execution
- Agent Adapter Layer → Provider Router: routes model calls
- Provider Router → Gemini Adapter: Gemini selection
- Provider Router → LLM Providers: provider requests
- Persona & Capabilities → Agent Adapter Layer: role instructions
- Governance Guardrails → Agent Adapter Layer: enforces safety
- Continuous Nudger → Learning & Graph Memory: reads and updates context
- GitHub Webhook API → Auth & Billing: authenticates and accounts
- GitHub Webhook API → SQLAlchemy Persistence: persists tenant state
- Auth & Billing → SQLAlchemy Persistence: stores account data
- Continuous Nudger → Dashboard & Metrics: publishes local status
- GitHub Webhook API → Telemetry Tracing: emits service telemetry
- Continuous Nudger → Telemetry Tracing: emits lifecycle telemetry