Skip to main content

The prompt store for who a Cogno agent IS — a typed Persona (scope/execution/limits/voice prompts + by-name module binding + custom rules), version-aware loader, retrieval store, embedding selector, and pure prompt composition. Infra-agnostic, host-injected.

Project description

cogno-persona

The prompt store for who a Cogno agent is. A light, infra-agnostic library that models an agent's declaration — the prompts that define its scope, execution behaviour, limits and voice, plus its identity, an opaque by-name binding to the modules it may use, and any tenant custom rules.

Persona = declaration ("who the agent is / may do"). It does not execute anything — allowed_modules is just names the host resolves into real tool dispatchers. Execution ("what it does") is a separate concern (cogno-praxis).

Distilled from the parent Cogno's core/prompt_loader.py + ego/persona*.py, with all the CoreDB / channel / env infra left to the host.

Why

The four prompt slots line up byte-for-byte with what the cogno-anima stages consume, so a host loads a persona and injects its prompts straight into the pipeline:

persona.prompts.* consumed by
system EgoStage.process(..., system_prompt=) — execution
scope SuperegoStage.check_input_scope(..., scope_prompt=)
limits SuperegoStage.evaluate(..., limits_prompt=)
voice SuperegoStage.voice(..., voice_prompt=)

Install

pip install cogno-persona          # model + loader + store + selector + compose
pip install "cogno-persona[yaml]"  # + YAML frontmatter parsing in prompts

Five pieces

1. Persona — the typed container (pydantic)

from cogno_persona import Persona, PersonaPrompts

vet = Persona(
    persona_id="VETERINARY",
    description="pet health specialist",
    allowed_modules=["veterinary", "scheduler"],   # by-name binding (host resolves)
    custom_rules="Always confirm the pet's name first.",
    prompts=PersonaPrompts(system="You are the vet…", scope="…", limits="…", voice="…"),
)
vet.primary_module          # "veterinary"
vet.prompt("voice")         # the voice prompt text

2. loader — version-aware loading from disk

from cogno_persona import load_persona, load_prompt

vet = load_persona("personas/VETERINARY")           # manifest + slot files
vet = load_persona("personas/VETERINARY", version="v1")  # pin a prompt version
text = load_prompt("prompts", "voice.txt", stage="superego", version="v2")

A prompt may carry a sibling <name>_meta.json mapping version labels → files; list_versions / current_version introspect it.

3. store — the retrieval seam (homeo pattern)

from cogno_persona import FilePersonaStore, InMemoryPersonaStore, PersonaStore

store = FilePersonaStore("personas/")        # lazily loads each subdir
store = InMemoryPersonaStore([vet])          # for tests / seeding
# host implements PersonaStore over its own DB:  async get(id) / async list()

4. PersonaSelector — pick a specialist by embedding

from cogno_persona import PersonaSelector

selector = PersonaSelector(embedder, threshold=0.25)   # any cogno-synapse Embedder
result = await selector.select(
    noumeno.rewritten,                       # the canonical-English text (post-NOUMENO)
    candidates=await store.list(),
    base_persona_id="SECRETARY",
    intent_class=intent.intent_class,        # SOCIAL → base, no embedding
    restrict_to=identity.allowed_personas,   # N:N — compete only among allowed
)
result.persona_id, result.matched, result.score

Pure scoring (base penalty + inertia boost + threshold); the host owns candidate loading and embedding caches (pass candidate_vectors= to skip re-embedding). For a tenant with many similar personas, inject a reranker= (a Reranker Protocol — a host-provided cross-encoder) to reorder the above-threshold shortlist; it is off by default and unnecessary for small catalogs. See cognobench/ROUTING_BENCH_RESULTS.md.

5. compose — assemble the effective prompt

from cogno_persona import compose_prompt

system = compose_prompt(vet, "system", base=GLOBAL_RULES,
                        context={"tenant_name": "PetCo"})
# → base + persona.system + mandatory custom_rules block, {placeholders} filled

Pure assembly only — channel brevity, language pins, correction feedback and the like stay host concerns (append them yourself).

Design

Principle How
Declaration, not execution allowed_modules is names; the host runs tools (praxis)
Infra-agnostic no CoreDB / channel / env; the host loads & injects
Runtime-light one dep (pydantic); Embedder is type-only from cogno-synapse
Aligned to anima the four slots match the stage signatures exactly
Pure helpers loader/selector/compose have no I/O beyond reading prompt files

See docs/HOST_INTEGRATION.md and LOGGING.md.

The Cogno ecosystem

cogno-persona is one organ of Cogno — a family of small, composable, Apache-2.0 libraries that together form a complete conversational-agent platform. Each library owns a single concern and stays infra-agnostic; a host assembles them into a running agent:

The Cogno ecosystem

The open-source libraries are the organs; the host is the body that joins them. Our reference host — cogno-host, with its cogno-ui dashboard — is the private product layer, but it holds no special powers: everything it does rides on the public seams documented in each library's docs/HOST_INTEGRATION.md, so you can assemble a body of your own.

Development

pip install -e ".[dev]"
ruff check cogno_persona tests examples
mypy cogno_persona
pytest tests/unit -q --cov=cogno_persona

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cogno_persona-0.1.0.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cogno_persona-0.1.0-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file cogno_persona-0.1.0.tar.gz.

File metadata

  • Download URL: cogno_persona-0.1.0.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for cogno_persona-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cf9ce60e8f4316cd23cfa9fd9ea65eb98f8478fc4354726588a681572798c1ea
MD5 8038b6e05c844ab3898e713dd38adc7d
BLAKE2b-256 cfaf8675c016a3ce334e226e7e9a1af0b36f2deb9c430fe3beb5af5487c93ab2

See more details on using hashes here.

File details

Details for the file cogno_persona-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cogno_persona-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for cogno_persona-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0b1b5d6be82b625c80f05507a91a8ec916e4064b55595ca438a16e8b4dced324
MD5 45bcfa6274f4cc02f1825bbd4f21e752
BLAKE2b-256 4f16fd1bf01d5f2e06c5ddd1578d8173b8c3bd34ea8bacea24bed397c78afd61

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page