Add GMAC Metabolism Engine, Goodwill Scoring, Metabolism-Gated Tools & Config Extensions#5
Merged
kingassune merged 2 commits intomainfrom Feb 24, 2026
Merged
Conversation
… and config extensions Co-authored-by: kingassune <6126851+kingassune@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add GMAC metabolism engine and related features
Add GMAC Metabolism Engine, Goodwill Scoring, Metabolism-Gated Tools & Config Extensions
Feb 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Description
Implements the GMAC metabolism infrastructure (sub-issues 5–8 of epic #3): a token-balance engine that enforces "trade to live" mechanics, a goodwill score system gating agent abilities, optional per-tool GMAC cost deduction, and the corresponding config surface. This layer is fully independent of Phase 1 GDEX tools — it provides the infrastructure that GDEX tools will later plug into.
pkg/metabolism/— new packagemetabolism.go—Metabolismstruct with thread-safeDebit/Credit/CanAfford/InSurvivalMode, ledger recording, and goodwill-threshold ability gates (CanReplicate,CanSelfRecode,CanLeadSwarm,CanArchitect)errors.go—ErrInsufficientGMAC,ErrHibernatingpersistence.go— atomicSaveToFile/LoadFromFile; state instate.json, ledger in append-onlyledger.jsonlgoodwill.go— seven goodwill constants +GoodwillTrackerwithRecordTradeResult,RecordTaskResult,RecordUserFeedback,RecordSelfFunding,GetAbilitiesmetabolism_test.go— full coverage: balance math, survival mode, all threshold gates, ledger integrity, save/load round-trip, all tracker helperspkg/tools/registry.go— metabolism-gated executionAdded optional
*metabolism.Metabolism+toolCoststoToolRegistry. When set,ExecuteWithContextchecks balance and debits before running. Zero-cost whenmetabolism == nil— all existing behavior unchanged.pkg/config/config.go+config/config.example.jsonNew
MetabolismConfigstruct withEnabled,InitialGMAC,HeartbeatCost,InferenceCostPer1k,SurvivalThreshold, and nestedThresholds; added asMetabolism MetabolismConfigonConfig. Example config ships with sane defaults (disabled by default).pkg/agent/loop.goWhen
cfg.Metabolism.Enabled,registerSharedToolscallsloadOrCreateMetabolism(loads persisted state or creates fresh from config) and attaches it to each agent's tool registry withDefaultToolCosts.ProcessHeartbeatdebitsHeartbeatCostper tick with explicit error logging.🗣️ Type of Change
🤖 AI Code Generation
🔗 Related Issue
Closes #5, #6, #7, #8 (sub-issues of epic #3)
📚 Technical Context (Skip for Docs)
metabolism == nilpath is zero-overhead and preserves full backward compatibility with existing tool tests.🧪 Test Environment
📸 Evidence (Optional)
Click to view Logs/Screenshots
All
pkg/...tests pass. CodeQL: 0 alerts.☑️ Checklist
Original prompt
Parent Epic: #3 — Living Agent — GMAC Metabolism, GDEX SDK Trading, Self-Replication, Telepathy
This PR covers sub-issues 5-8 from the epic: the GMAC metabolism engine, goodwill scoring, metabolism-gated tool execution, and config extensions.
Important: This PR should NOT depend on Phase 1 (GDEX tools). It builds the metabolism infrastructure that Phase 1 tools will later plug into.
Sub-Issue 5: GMAC Metabolism Engine
New Package:
pkg/metabolism/Create
pkg/metabolism/metabolism.go:Implement these methods:
NewMetabolism(initialBalance float64, thresholds Thresholds) *MetabolismCanAfford(cost float64) boolDebit(amount float64, action, details string) error— returnsErrInsufficientGMACif balance too lowCredit(amount float64, action, details string)GetBalance() float64GetGoodwill() intAddGoodwill(points int, reason string)— clamp to minimum 0CanReplicate() bool— goodwill >= thresholds.ReplicateCanSelfRecode() bool— goodwill >= thresholds.SelfRecodeCanLeadSwarm() bool— goodwill >= thresholds.SwarmLeaderCanArchitect() bool— goodwill >= thresholds.ArchitectInSurvivalMode() bool— balance < thresholds.HibernateGetLedger() []LedgerEntryGetStatus() MetabolismStatus— returns a summary struct with balance, goodwill, generation, survival mode flag, unlocked abilities listCreate
pkg/metabolism/persistence.go:SaveToFile(path string) error— JSON serialize metabolism state to diskLoadFromFile(path string) (*Metabolism, error)— restore from disk{workspace}/metabolism/state.json{workspace}/metabolism/ledger.jsonl(append-only)Create
pkg/metabolism/errors.go:var ErrInsufficientGMAC = errors.New("insufficient GMAC balance")var ErrHibernating = errors.New("agent is hibernating — GMAC balance critically low")Create
pkg/metabolism/metabolism_test.go:Sub-Issue 6: Goodwill Score System
In
pkg/metabolism/goodwill.go, define the goodwill point values as constants:Create a
GoodwillTrackerthat wrapsMetabolism.AddGoodwill()with:RecordTradeResult(profitPercent float64)— auto-calculates goodwill from trade P&LRecordTaskResult(success bool)RecordUserFeedback(positive bool)RecordSelfFunding()— when agent pays for its own inferenceGetAbilities() []string— returns list of unlocked abilities based on current goodwillSub-Issue 7: Metabolism-Gated Tool Execution
Modify
pkg/tools/registry.goto support optional metabolism gating:Add a new field to
ToolRegistry:Add methods:
SetMetabolism(m *metabolism.Metabolism)SetToolCost(toolName string, cost float64)Modify `ExecuteWithCont...
This pull request was created from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.