Skip to content

API Reference parrot.bots.prompts.identity

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.bots.prompts.identity

View source

File-based identity loader (FEAT-321 — PromptBuilder Identity Capability).

Loads the five composable identity fields (role, goal, capabilities, backstory, rationale) from per-field Markdown files in an agent-local identity/ directory, mirroring the whole-blob convention already used by :func:parrot.bots.prompts.agent_context.load_agent_context.

Missing or empty files fall through silently (field None, debug log only) so agents that only define a subset of the five files keep working. File content is injected verbatim (no $-escaping) so dynamic variable pre-resolution ($current_date, etc.) keeps working exactly as it does for inline identity — see sdd/specs/promptbuilder-identity-capability.spec.md §7.

Attribute IDENTITY_FILES

Type: tuple[str, ...]

Class IdentityFields

The five composable identity fields, loaded from Markdown.

Fields:

Field Type Default Description
role Optional[str] None
goal Optional[str] None
capabilities Optional[str] None
backstory Optional[str] None
rationale Optional[str] None

Method IdentityFields.as_kwargs

Non-empty fields only, for injection as instance attributes.

as_kwargs() -> dict[str, str]

Returns: dict[str, str] — A dict mapping field name to value, excluding any field whose value is None (empty/missing files never reach here).

Function load_identity

Read {role,goal,capabilities,backstory,rationale}.md from a directory.

Each file is read via :func:read_text_cached (mtime-keyed, near-free on repeated calls) and stripped. A missing directory, missing file, empty file, whitespace-only file, or unreadable file all resolve that field to None silently (debug log only) — the same fallthrough discipline as :func:parrot.bots.prompts.agent_context.load_agent_context.

Content is injected verbatim by default — no $-escaping — so dynamic variables ($current_date, etc.) pre-resolve exactly as they do for inline identity (abstract.py lines 1200-1214). Pass escape_placeholders=True to double any $ for locked-down personas that must not participate in dynamic-variable substitution.

load_identity(directory: Union[str, Path], *, escape_placeholders: bool = False) -> IdentityFields

Parameter Type Default Description
directory Union[str, Path] The identity/ directory to read from.
escape_placeholders bool False When True, replace $ with $$ in every loaded field so string.Template treats them literally.

Returns: IdentityFields — class:IdentityFields instance with non-empty fields populated.

Alias read_text_cached

Re-exported from parrot.bots.prompts.agent_context.read_text_cached.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally