Skip to content

feat: token-based personality trimming via PromptProfile.max_personality_tokens #1045

@Aureliolo

Description

@Aureliolo

Context

PromptProfile.max_personality_tokens was introduced in #805 (capability-aware prompt profiles) as a validated field (gt=0) with per-tier values (large=500, medium=200, small=80). Currently it serves only as an ordering proxy -- no code reads the field to actually trim personality content.

The field is documented as "reserved for future token-based trimming" but the infrastructure is now in place to activate it.

Scope

Token-based personality trimming (engine/_prompt_helpers.py or engine/prompt.py)

  • In build_core_context(), after assembling personality fields, estimate the token count of the personality section
  • If the estimate exceeds profile.max_personality_tokens, progressively trim:
    1. Drop behavioral enum fields (risk_tolerance, creativity, verbosity, decision_making, collaboration, conflict_approach) -- these are already excluded by personality_mode != "full" but trimming adds a token-budget safety net
    2. Truncate personality_description to fit within the remaining budget
    3. If still over, fall back to communication_style only (minimal mode)
  • Log the trimming action with before/after token counts

Integration with existing profile modes

  • Token trimming should be a secondary control after personality_mode -- the mode selects which fields are included, the token limit enforces a hard cap on the combined result
  • For the full profile (500 tokens), trimming should rarely activate -- it is a safety net for unusually verbose personality descriptions
  • For basic profile (80 tokens), the minimal mode already excludes most fields, so the cap reinforces the structural reduction

Estimator reuse

  • Reuse the existing PromptTokenEstimator (char/4 heuristic) or accept a configurable estimator
  • The personality section is a small fraction of the total prompt, so precision matters less than consistency

Deliverables

  • Token estimation for personality section content
  • Progressive trimming logic respecting max_personality_tokens
  • Logging of trim actions (event constants in events.prompt)
  • Unit tests for trimming at each tier's limit
  • Update PromptProfile.max_personality_tokens docstring to remove "reserved for future" caveat

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    prio:mediumShould do, but not blockingscope:smallLess than 1 day of workspec:task-workflowDESIGN_SPEC Section 6 - Task & Workflow Enginetype:featureNew feature implementationv0.6Minor version v0.6v0.6.3Patch release v0.6.3

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions