Skip to content

Add opt-in author identity to agent board posts - #66

Merged
AvnehSBhatia merged 1 commit into
exea-labs:mainfrom
man-coding-j:codex/pr-agent-identity-board
Nov 22, 2026
Merged

AvnehSBhatia merged 1 commit into
exea-labs:mainfrom
man-coding-j:codex/pr-agent-identity-board

Conversation

@man-coding-j

Copy link
Copy Markdown
Contributor

Summary

Add an opt-in learned author signal to AG board values. This gives a reader a way to distinguish writers that post the same content. Set board_identity_size to the number of learned IDs. Each layer's table starts at zero and trains through board reads.

In-batch swarms use swarm-local row indices or explicit MemoryContext.agent_ids. Persistent boards use the stored author ID at read time, so local and HTTP board formats stay compatible. IDs outside the table contribute zero. A standalone agent without external posts keeps its original behavior. Default configurations and legacy checkpoints load without identity tensors.

Experiment result

A matched CPU experiment used the tiny preset, 120 steps, eight two-agent swarms per batch, 16 tokens per row, AdamW at 0.003, and the same 16 fixed validation batches for both arms. Partners read identical tokens, and the target depended on the writer's ID. Enabling two IDs added 32 parameters to the 127,432-parameter baseline.

Seed Default accuracy Identity accuracy Default bits/target Identity bits/target
0 50% 100% 1.001186 0.002106
1 50% 100% 1.001159 0.002243

The experiment measures whether a reader can use author identity when content is identical.

Validation

The full local pytest suite reported 250 passed in 89.58 seconds.

Tests cover identity-specific gradients, earlier-chunk visibility, swarm isolation, persistent authors, unknown IDs, strict loading of legacy and new checkpoints, and standalone parity.

OMP_NUM_THREADS=1 python -m pytest -q tests/test_board_identity.py tests/test_board_usage.py tests/test_memory.py
OMP_NUM_THREADS=1 python -m pytest -q -ra
Reproduce the synthetic identity experiment

Run from the repository root.

OMP_NUM_THREADS=1 python - <<'PY'
import json
import math

import torch

from exealm import ExeaLM, MemoryContext, count_params, get_config

STEPS = 120
SWARMS = 8
CHUNK = get_config("tiny").chunk

def batches(seed, count):
    rng = torch.Generator().manual_seed(seed)
    for _ in range(count):
        # Swarm partners read identical tokens, while the assignment of author IDs varies by swarm.
        x = torch.randint(16, 256, (SWARMS, 2 * CHUNK), generator=rng).repeat_interleave(2, dim=0)
        role = torch.randint(0, 2, (SWARMS,), generator=rng)
        authors = torch.stack((role, 1 - role), dim=1)
        targets = torch.full_like(x, -100)
        targets[:, -1] = 4 + authors.flip(1).flatten()
        yield x, targets, MemoryContext(swarm_size=2, agent_ids=authors.flatten())

@torch.no_grad()
def metrics(model, val):
    model.eval()
    accuracy, losses = [], []
    for x, y, mem in val:
        logits, loss = model(x, mem, y)
        accuracy.append(float((logits[:, -1].argmax(-1) == y[:, -1]).float().mean()))
        losses.append(float(loss) / math.log(2))
    return dict(accuracy=sum(accuracy) / len(val), bits=sum(losses) / len(val))

val = list(batches(10000, 16))
for seed in (0, 1):
    training = list(batches(seed, STEPS))
    for capacity in (0, 2):
        torch.manual_seed(seed)
        model = ExeaLM(get_config("tiny", board_identity_size=capacity, board_read_self=False))
        optimizer = torch.optim.AdamW(model.parameters(), lr=3e-3, weight_decay=0)
        model.train()
        for x, y, mem in training:
            optimizer.zero_grad(set_to_none=True)
            loss = model(x, mem, y)[1]
            loss.backward()
            torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0)
            optimizer.step()
        print(json.dumps(dict(seed=seed, board_identity_size=capacity, params=count_params(model),
                              steps=STEPS, **metrics(model, val))), flush=True)
PY

@AvnehSBhatia
AvnehSBhatia merged commit 1b60de4 into exea-labs:main Nov 22, 2026
1 check passed
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