Skip to content

[#754] Centralise relationships into a SocialGraph resource#772

Merged
milkyskies merged 12 commits into
mainfrom
feature/#754.social-graph
May 10, 2026
Merged

[#754] Centralise relationships into a SocialGraph resource#772
milkyskies merged 12 commits into
mainfrom
feature/#754.social-graph

Conversation

@milkyskies

Copy link
Copy Markdown
Owner

closes #754

Pulls canonical Affection / Trust / Respect off per-agent MindGraph triples and onto a centralised SocialGraph resource keyed by directed (observer, target) Entity pairs. Edges live on the resource, not on either entity — the LOD-survival prerequisite #752 needs.

What moved

  • New psyche::social_graph module: SocialGraph resource + RelationshipEdge (affection / trust / respect / power_balance / last_interaction_tick / kind) + RelationshipKind enum + NEUTRAL constant + affection/trust/respect/get/get_mut/set/knows/iter/forget_agent API.
  • Writers (relationships::update_relationships, decay_relationships, recognition::init_relationship_dimensions, world::spawner::setup_wolf_pack_bonds, TestWorld helpers, scenario builder) write to SocialGraph.
  • Readers (every mind.get(target, Affection|Trust|Respect) site: brain_system, emotional, drift, flocking, greetings, converse, generic_action's TargetAffectionAtLeast gate, other_regarding's affection_channel, plus test/scenario fixtures and TestWorld inspection helpers) read from SocialGraph.
  • MindGraph still owns categorical IsA Friend|Rival|Kin classifications — those are recognition-perceiver-side narrative, not canonical edge state.

ActionContext, PreferenceContext, EmotionalInputs, and ChannelContext now carry the SocialGraph reference plus the observer entity, so all consumers look up directed edges through the central store.

Behavioural intent

Zero drift expected — the values flowing through the pipeline are the same; only their storage shape changed. Existing relationship tests should pass unchanged.

Out of scope

  • Respawn-reconnect (re-materialised entity re-binding to its old edge) needs a stable AgentId. Without one, despawning a Bevy entity leaves orphan edges keyed by the dead entity id. The data outlives the entity (assertion in unit tests) but the lookup path requires AgentId — filed for [Thinking] [Performance] [LOD] Architecture to support 1000-agent simulation #752.
  • History-on-edge (the issue mentions Vec<RelationshipEvent> on the edge). Per-agent RelationshipHistory log already covers this; folding it into the edge is a follow-up to keep this PR's diff bounded.

Test plan

  • SocialGraph unit tests: add/get round-trip, directed-edge asymmetry, NEUTRAL default for unknown pair, mutating one direction doesn't affect the reverse, forget_agent evicts both sides
  • LOD-survival assertion: edge data outlives entity in resource-only lifecycle (unit-level)
  • Existing relationship tests still pass via CI (full sweep)
  • cargo check --tests clean, cargo fmt

🤖 Generated with Claude Code

milkyskies and others added 6 commits May 10, 2026 13:48
Move canonical Affection / Trust / Respect off per-agent MindGraph
triples and onto a centralised `SocialGraph` resource keyed by
directed `(observer, target)` Entity pairs. Edges live on the resource,
not on either entity, which is the LOD-survival prerequisite #752
needs (demoting an agent's entity must not destroy their
relationships).

Migration scope:
- New `psyche::social_graph` module: SocialGraph + RelationshipEdge +
  RelationshipKind + NEUTRAL constant + affection/trust/respect
  accessors and forget_agent / iter helpers.
- `relationships::update_relationships` and `decay_relationships`
  now read/write the SocialGraph instead of MindGraph triples.
- `recognition::init_relationship_dimensions` writes a SocialGraph
  edge.
- All callers of `mind.get(target, Affection|Trust|Respect)` migrated
  to `social_graph.affection(observer, target)` etc:
  brain_system, emotional, drift, flocking, greetings, converse,
  generic_action::TargetAffectionAtLeast gate, other_regarding's
  affection_channel, the test fixtures, scenarios, and TestWorld
  helpers.
- Drops the (Self_, Affection|Trust|Respect, Other) MindGraph writes
  in spawner, recognition, and TestWorld pack-bond setup. Categorical
  IsA Friend / Rival / Kin still lives in MindGraph since classification
  is recognition-perceiver-side, not canonical edge data.
- ActionContext + PreferenceContext + EmotionalInputs + ChannelContext
  carry the SocialGraph + observer entity; consumers look up directed
  edges through the central store.

Behavioural drift expected to be zero — the values flowing through the
pipeline are the same; only their storage shape changed.

Filed for #752 follow-up: respawn-reconnect (re-materialised entity
re-binding to its old edge) needs a stable AgentId — out of scope here.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Move Node/Predicate/Value out of the parent module (only used in
mod tests now that the canonical relationship triples no longer live
in MindGraph) and drop Quantity from spawn_wolf_pack's local use
since we write SocialGraph edges instead of Quantity::Exact triples.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Test was still asserting affection through a MindGraph triple. After
the migration the gate reads through the SocialGraph edge — seed it
there.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Compassion's affection_channel reads through the SocialGraph after the
migration. The test_other_regarding fixture was still writing affection
into MindGraph, so high-affection scenarios returned NEUTRAL=0.5 from
the channel and produced no Compassion urgency.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Resolves: ActionContext / PreferenceContext callsites picked up an
additional world_positions field from #773 alongside this branch's
social_graph + agent_entity additions; reconciled both in production
and test contexts. Bundled SocialGraph into brain_system's side_queries
tuple to stay under the Bevy 16-param SystemParam cap.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@milkyskies milkyskies marked this pull request as ready for review May 10, 2026 05:25
milkyskies and others added 6 commits May 10, 2026 14:29
The depth-clamp tests added in #765 (newly-merged main) call
regressive_plan with the pre-#773 4-arg signature. Update them to
pass `inventory: None` and a default WorldEntityPositions like the
other in-file callsites.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The test_relationship_decay fixtures still wrote/read trust through
MindGraph triples; migrate them to set/read on the SocialGraph
resource so the decay system actually sees the seeded edge.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Mirrors testing/world.rs's wolf_pack_bonds_established_at_spawn unit
test — pack-bond trust lives on the SocialGraph resource now, not on
each wolf's MindGraph.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@milkyskies milkyskies merged commit 99aa774 into main May 10, 2026
2 checks passed
@milkyskies milkyskies deleted the feature/#754.social-graph branch May 10, 2026 06:01
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.

Centralise relationships into a SocialGraph resource

1 participant