AAnvio
Skills, Personas, Souls & Learning

Souls & Soul Gate

SOUL.md is an agent's durable identity and its harness policy gate — both parsed from the same Markdown file, never invented.

7 min read

A Soul is the long-term identity of an agent. It is not a system prompt — it is durable state that survives sessions, restarts, model upgrades, and provider changes. The Soul Gate enforces the trust boundaries encoded in that same file: who the agent reports to, who can approve risky actions, which channels are trusted, and what must be redacted.

Both concerns — identity and policy — are read from one file: SOUL.md.

Soul vs Persona vs Agent

Rendering diagram…
  • Persona (kind: Persona) — reusable tone/style template; see Personas.
  • Soul (kind: Soul) — persisted identity that evolves over time for one specific agent.
  • Agent (kind: Agent) — binds soul + skills + model + tools for execution.

The real file: workspace/souls/architect-soul/SOUL.md

This is a genuine, working example from the repo. Notice it combines the identity sections (Hermes-style) with the policy sections (slaude-style harness gate) in a single Markdown document:

# Architect Soul — identity + harness policy

## Identity
- Name: Architect Soul
- Role: Senior Software Architect
- Description: Long-term architectural thinking partner

## Reporting
- Manager: cli:local-user

## Approvers
- cli:local-user: anything ; catchall

## Approval timeout
- seconds: 3600

## Values
- simplicity
- maintainability
- honesty

## Personality
- thoughtful
- structured

## Preferences
- conversation: professional
- diagrams: when helpful

## Communication
- Tone: professional and thoughtful
- Format: structured with clear rationale

## Long-term goals
- help the user build maintainable systems
- improve architecture over time

## Behavioral tendencies
- consider tradeoffs before recommending
- prefer simplicity over cleverness

## Mandate
- Help the team ship maintainable systems.
- Request human approval before mutating production or shared infrastructure.

The file path convention is workspace/souls/<slug>/SOUL.md. A flat workspace/souls/<slug>.md or legacy workspace/souls/<slug>.yaml are also accepted (see Lookup order below), but the directory-with-SOUL.md form is the one used by the real example and is what save() writes.

Two parsers, one file

The same SOUL.md is read by two different parsers depending on what the caller needs:

ParserPackageProducesUsed for
parseSoulDefinitionMdpackages/core/src/markdown/soul-md-definition.tsSoulDefinition (identity: values, personality, goals, preferences, communication style)Soul context assembly, anvio soul show
parseSoulMdpackages/soul-gate/src/soul-md-parser.tsSoulPolicy (manager, approvers, allowed/trusted zones, blocked users, redaction, mandate)Harness enforcement — the Soul Gate

Both parsers use the same regex-first section extraction: find a ## Heading, take bullet lines (- value) or Label: value lines until the next ##. Neither invents structure that isn't in the file.

Soul identity schema

soulSpecSchema (packages/core/src/schemas/soul.schema.ts):

FieldDefault
namerequired
identity.role, identity.descriptionoptional
values[]
personality[]
preferences{} (record)
communicationStyle.toneprofessional
communicationStyle.formatclear and concise
longTermGoals[]
behavioralTendencies[]
relationshipMemory.providerfilesystem
relationshipMemory.pathrelationship
evolution.allowAutoUpdatetrue
evolution.requireApprovalfalse

Soul policy schema (Soul Gate)

soulPolicySchema (packages/core/src/schemas/soul-policy.schema.ts):

FieldNotes
identity.name / role / voice
manager, backupManager{ channel, userId }
allowedZones, trustedZones[{ channel, ids: [] }]
blockedUsers[{ channel, userId }]
approvers[{ channel, userId, scope, catchall }]
redactPatternsstring[]
approvalTimeoutSecondsnumber, default 0
mandatefree text
valuesstring[]

Soul Gate: verified, not trusted

The critical security property of the Soul Gate parser is that it never invents an ID that isn't verbatim in the source file. After the regex parser (or the LLM extractor) produces a draft SoulPolicy, verifyPolicyIds (packages/soul-gate/src/verifier.ts) filters every user/channel reference:

// packages/soul-gate/src/verifier.ts
export function verifyPolicyIds(source: string, policy: SoulPolicy): SoulPolicy {
  const verified = structuredClone(policy);
  verified.blockedUsers = verified.blockedUsers.filter((u) => source.includes(u.userId));
  verified.approvers = verified.approvers.filter((a) => source.includes(a.userId));
  if (verified.manager && !source.includes(verified.manager.userId)) {
    verified.manager = undefined;
  }
  // ... same pattern for backupManager, allowedZones, trustedZones
  return verified;
}

This means even if an LLM-based extraction hallucinates an approver or manager ID, it gets silently dropped unless that exact string appears in the SOUL.md source. extractIdsFromLine recognizes channel-prefixed IDs (slack:U123, telegram:456, cli:local-user, ...) and raw Slack-style tokens (<@U123>, U0123ABC).

This verification step is a hard security boundary, not a formatting nicety. Any custom tooling that constructs a SoulPolicy object programmatically (rather than parsing it from SOUL.md) bypasses verifyPolicyIds entirely — treat that path as trusted input only.

Regex-first, LLM-optional

parseSoulMd (regex-first, no model call) is always available and always runs as the fallback. extractSoulPolicy (packages/soul-gate/src/soul-policy-llm.ts) additionally calls a model provider (when one is configured and isn't the mock provider) with a strict system prompt instructing it to extract policy JSON and only include IDs verbatim in the source. Whatever the LLM returns is merged over the regex draft, then run back through verifyPolicyIds — so LLM extraction can only ever narrow/reformat what regex already found, never add new trusted identities.

// packages/soul-gate/src/soul-policy-llm.ts
export async function extractSoulPolicy(source, slug, modelProvider) {
  const regexPolicy = parseSoulMd(source, slug);
  if (!isUsableModelProvider(modelProvider)) return regexPolicy;
  // ... call modelProvider.chat(), parse JSON, merge over regexPolicy
  return verifyPolicyIds(source, merged); // still re-verified
}

Policy caching

loadSoulPolicy (packages/soul-gate/src/soul-md-parser.ts) hashes the SOUL.md source (SHA-256, truncated to 16 hex chars) and caches the resulting SoulPolicy under workspace/souls/_cache/soul.<hash>.json (packages/soul-gate/src/policy-cache.ts). If the file hasn't changed, the cached policy is reused — no re-parse, no repeat LLM call. Edit the SOUL.md and the hash changes, invalidating the cache automatically.

Soul context assembly

Soul context is injected as structured metadata, not concatenated raw text into the system prompt. SoulEngineImpl.assembleContext (packages/souls/src/index.ts) does:

Rendering diagram…

SoulContext carries: soulId, name, identity, values, personality, preferences, communicationStyle, longTermGoals, behavioralTendencies, relationshipFacts (up to 20 recent fact-type memory entries for that user). renderSoulContext turns this into readable lines the runtime merges into context assembly — a separate step from the persona's systemPrompt.

Lookup order

FilesystemSoulStore.get(slug) (packages/souls/src/index.ts) tries, in order:

  1. souls/{slug}/SOUL.md
  2. souls/{slug}.md
  3. souls/{slug}.yaml
  4. souls/{slug}.yml

The first one found wins and is parsed with the matching parser (parseSoulDefinitionMd for Markdown, parseSoulDefinition for YAML). save() always writes back as souls/{slug}/SOUL.md, rendered from the current SoulDefinition — so even a soul that started life as YAML gets normalized to the Markdown form the next time it's saved.

Evolution & safety

A soul's spec.evolution block gates whether the learning loop is allowed to touch it:

SettingEffect
allowAutoUpdate: falseLearning loop skips this soul entirely (onSessionCompleted / onToolUseCompleted return early with skipped: 'soul evolution disabled')
allowAutoUpdate: true, requireApproval: false (default)Runtime tool-learning skill drafts are auto-promoted into workspace/skills/ immediately
allowAutoUpdate: true, requireApproval: trueDrafts are written but not auto-promoted; a human runs anvio learning promote <slug>

The architect-soul example above doesn't set spec.extensions.policy or an explicit evolution block in its SOUL.md, so it inherits the schema defaults (allowAutoUpdate: true, requireApproval: false).

CLI

anvio soul list
anvio soul show architect-soul
anvio soul show architect-soul --context   # dump the assembled SoulContext
anvio soul create --slug architect-soul --name "Architect Soul" --from-persona architect
anvio soul import path/to/SOUL.md
anvio soul validate-policy path/to/SOUL.md

Operational notes

ScenarioAction
Back up soulsgit add workspace/souls && git commit — it's plain files
Migrate to a new machineCopy workspace/souls/
Reset relationship memoryDelete workspace/souls/{slug}/relationship/
Invalidate a stale cached policyEdit SOUL.md (hash changes) or delete workspace/souls/_cache/soul.<hash>.json

Package boundaries

  • Schemas: packages/core/src/schemas/soul.schema.ts, packages/core/src/schemas/soul-policy.schema.ts
  • Markdown parsers: packages/core/src/markdown/soul-md-definition.ts (identity), packages/soul-gate/src/soul-md-parser.ts (policy)
  • Engine/store: packages/souls/src/index.ts (FilesystemSoulStore, SoulEngineImpl, SoulService)
  • Gate: packages/soul-gate/src/verifier.ts, packages/soul-gate/src/soul-policy-llm.ts, packages/soul-gate/src/policy-cache.ts
Edit on GitHub

Last updated on

On this page