Skip to content

feat: Agent Self-Replication, Self-Recoding, and Telepathy (sub-issues 9-11)#6

Merged
kingassune merged 2 commits intomainfrom
copilot/add-agent-self-replication
Feb 24, 2026
Merged

feat: Agent Self-Replication, Self-Recoding, and Telepathy (sub-issues 9-11)#6
kingassune merged 2 commits intomainfrom
copilot/add-agent-self-replication

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 24, 2026

📝 Description

Implements three new Living Agent capabilities: self-replication (spawn child agents inheriting config/skills/memory with mutated trading strategies), self-recoding (runtime config self-modification gated by goodwill), and telepathy (in-process + file-based pub/sub between parent and child agents).

pkg/replication/

  • replicator.goReplicator deep-copies parent config via JSON round-trip, assigns unique gateway port (parentPort + childIndex), splits GMAC balance by GMACSharePercent, recursively copies skills/ and memory/ dirs. Goodwill check is interface-based (func() int) so it compiles without Phase 2 merged.
  • mutation.gomutateSystemPrompt() picks randomly from 8 strategy archetypes (contrarian, momentum, HFT, risk-averse, etc.). Mutation is written to TRADING_STRATEGY.md in the child workspace — picked up automatically by LoadBootstrapFiles.
  • persistence.go — Atomic save/load of replication/children.json via temp+rename.
  • telepathy.go — In-process TelepathyBus: broadcast, point-to-point send, subscribe/unsubscribe, 500-msg ring buffer history, BroadcastTradeSignal convenience method.
  • telepathy_file.go — File-based telepathy for multi-process agents: poll-based watcher, JSON message files named {ts}-{agent}.json, configurable poll interval and message TTL (default 2s / 1h).

pkg/recode/

  • recoder.goRecoder supports ModifySystemPrompt (appends to recode/prompt_additions.txt), AddCronJob, InstallSkill, AdjustTradingParams (patches GDEXConfig fields by name). All actions are logged with RecodeAction; Rollback(index) marks an entry un-approved.

pkg/tools/

  • gdex_replicate.goreplicate tool: goodwill-gated, calls Replicator.Replicate(), returns child descriptor JSON.
  • gdex_recode.goself_recode tool: dispatches modify_prompt | add_cron | install_skill | adjust_trading; cron/skill args use SCHEDULE|TASK pipe convention, trading params accept JSON.
  • gdex_telepathy.gotelepathy tool: broadcast or targeted send via TelepathyBus; defaults to="*", priority=1.

🗣️ Type of Change

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 📖 Documentation update
  • ⚡ Code refactoring (no functional changes, no api changes)

🤖 AI Code Generation

  • 🤖 Fully AI-generated (100% AI, 0% Human)
  • 🛠️ Mostly AI-generated (AI draft, Human verified/modified)
  • 👨‍💻 Mostly Human-written (Human lead, AI assisted or none)

🔗 Related Issue

Parent epic: #3

📚 Technical Context (Skip for Docs)

  • Reference URL: pkg/metabolism/metabolism.go, pkg/bus/bus.go, pkg/agent/context.go
  • Reasoning: Goodwill checks use func() int callbacks rather than direct *Metabolism references so all three packages build independently of the Phase 2 metabolism/goodwill merge. Mutations land in TRADING_STRATEGY.md because LoadBootstrapFiles already scans the workspace for markdown files — no agent loop changes required.

🧪 Test Environment

  • Hardware: CI / sandbox
  • OS: Linux
  • Model/Provider: N/A
  • Channels: N/A

📸 Evidence (Optional)

Click to view Logs/Screenshots
ok  github.com/GemachDAO/Gclaw/pkg/replication  [no test files]
ok  github.com/GemachDAO/Gclaw/pkg/recode       [no test files]
ok  github.com/GemachDAO/Gclaw/pkg/tools        0.710s
# All existing tests pass; go build ./pkg/... succeeds; CodeQL: 0 alerts

☑️ Checklist

  • My code/docs follow the style of this project.
  • I have performed a self-review of my own changes.
  • I have updated the documentation accordingly.
Original prompt

Parent Epic: #3 — Living Agent — GMAC Metabolism, GDEX SDK Trading, Self-Replication, Telepathy

This PR covers sub-issues 9-11 from the epic: Agent Self-Replication, Agent Self-Recoding, and Telepathy (Parent-Child Agent Communication).

Important: This PR should be buildable independently. Where it references the metabolism/goodwill system from Phase 2, use interfaces so it compiles even if Phase 2 hasn't merged yet.


Sub-Issue 9: Agent Self-Replication

When an agent's goodwill score crosses the replication threshold (default 50), it earns the ability to clone itself into a new persistent Gclaw instance.

New Package: pkg/replication/

File: pkg/replication/replicator.go

package replication

// Replicator handles spawning persistent child Gclaw agents
// that inherit config, skills, and memory from the parent.

type ReplicationConfig struct {
    Enabled           bool    `json:"enabled"`
    MaxChildren       int     `json:"max_children"`        // max child agents (default 3)
    GMACSharePercent  float64 `json:"gmac_share_percent"`  // % of parent GMAC given to child (default 50)
    MutatePrompt      bool    `json:"mutate_prompt"`       // allow prompt mutation in children (default true)
    InheritSkills     bool    `json:"inherit_skills"`      // copy parent skills to child (default true)
    InheritMemory     bool    `json:"inherit_memory"`      // copy parent memory to child (default true)
    ChildWorkspaceDir string  `json:"child_workspace_dir"` // base dir for child workspaces
}

type ChildAgent struct {
    ID            string    `json:"id"`             // unique child ID e.g. "gclaw-child-1"
    ParentID      string    `json:"parent_id"`
    Generation    int       `json:"generation"`     // parent gen + 1
    WorkspacePath string    `json:"workspace_path"`
    ConfigPath    string    `json:"config_path"`
    CreatedAt     int64     `json:"created_at"`
    GMACBalance   float64   `json:"initial_gmac"`
    Status        string    `json:"status"`         // "running", "hibernating", "stopped"
    Mutations     []string  `json:"mutations"`      // list of prompt mutations applied
}

type Replicator struct {
    config    ReplicationConfig
    children  []*ChildAgent
    parentID  string
    mu        sync.RWMutex
}

Implement these methods:

  • NewReplicator(parentID string, config ReplicationConfig) *Replicator
  • CanReplicate(goodwill int, threshold int) bool
  • Replicate(parentConfig *config.Config, parentWorkspace string, parentGMAC float64) (*ChildAgent, error):
    1. Generate unique child ID (gclaw-child-{timestamp})
    2. Create child workspace directory under ChildWorkspaceDir
    3. Deep-copy parent config to child config
    4. If MutatePrompt is true, call mutateSystemPrompt() to add a random trading strategy variation
    5. If InheritSkills is true, copy {parentWorkspace}/skills/ to child workspace
    6. If InheritMemory is true, copy {parentWorkspace}/memory/ to child workspace
    7. Split GMAC: deduct GMACSharePercent from parent, give to child
    8. Generate a new child config file with a unique port for the gateway (parent port + child index)
    9. Return the ChildAgent struct
  • ListChildren() []*ChildAgent
  • GetChild(id string) (*ChildAgent, bool)
  • StopChild(id string) error

File: pkg/replication/mutation.go

// mutateSystemPrompt takes a parent system prompt and adds
// a random trading strategy mutation to create diversity.
func mutateSystemPrompt(parentPrompt string) string

Mutations should be selected randomly from a pool:

  • "You prefer high-frequency small trades over large positions"
  • "You are contrarian — buy when others sell, sell when others buy"
  • "You focus exclusively on newly launched tokens under 1 hour old"
  • "You prioritize tokens with high liquidity and low volatility"
  • "You are a momentum trader — chase tokens with >50% gains in 1 hour"
  • "You specialize in copy trading the top 3 performers"
  • "You are risk-averse — never risk more than 1% of balance per trade"
  • "You are aggressive — willing to risk 10% of balance for high-conviction trades"

The mutation gets appended to the child's system prompt, creating natural diversity.

File: pkg/replication/persistence.go

  • SaveChildren(path string) error — persist children list to {workspace}/replication/children.json
  • LoadChildren(path string) error — restore on startup

New Tool: pkg/tools/gdex_replicate.go

Create a ReplicateTool that the agent can call:

  • Name: replicate
  • Description: "Create a child agent that inherits your config, skills, and memory. Requires sufficient goodwill. The child gets a portion of your GMAC balance and a mutated trading strategy."
  • Parameters: name (string, optional — label for the child), strategy_hint (string, optional — influence the mutation)
  • Execute: Check goodwill threshold, call Replicator.Replicate(), return child info

Sub-Issue 10: Agent S...

This pull request was created from Copilot chat.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…ssues 9-11)

Co-authored-by: kingassune <6126851+kingassune@users.noreply.github.com>
Copilot AI changed the title [WIP] Add agent self-replication functionality feat: Agent Self-Replication, Self-Recoding, and Telepathy (sub-issues 9-11) Feb 24, 2026
Copilot AI requested a review from kingassune February 24, 2026 22:50
@kingassune kingassune marked this pull request as ready for review February 24, 2026 22:50
@kingassune kingassune merged commit 848fcc6 into main Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants