Skip to content

Commit de91d02

Browse files
committed
fix: address 5 CodeRabbit review findings
- Fix docs/design/engine.md: standard profile Acceptance Criteria column 'Bullet list' -> 'Nested list' (simplify_acceptance_criteria=False) - Add tier 1/2 budget-met invariant to PersonalityTrimInfo validator (after_tokens must not exceed max_tokens for tiers 1 and 2; only tier 3 is best-effort) - Include '## Personality' heading in _estimate_personality_tokens so budget_met reflects actual rendered section cost - Add task_id to PROMPT_PERSONALITY_TRIMMED log in agent_engine for task correlation - Propagate trimming_enabled through _trim_sections so re-renders honor the original personality_trimming_enabled flag instead of defaulting to True
1 parent 60a7e06 commit de91d02

4 files changed

Lines changed: 16 additions & 5 deletions

File tree

docs/design/engine.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ each model tier.
711711
| Profile | Tier | Personality | Max Personality Tokens | Org Policies | Acceptance Criteria | Autonomy |
712712
|------------|--------|----------------------|------------------------|--------------|---------------------|----------|
713713
| **full** | large | Full behavioral enums | 500 | Included | Nested list | Full |
714-
| **standard** | medium | Description + style + traits | 200 | Included | Bullet list | Summary |
714+
| **standard** | medium | Description + style + traits | 200 | Included | Nested list | Summary |
715715
| **basic** | small | Style keyword only | 80 | Excluded | Flat semicolon line | Minimal |
716716

717717
### Personality Trimming

src/synthorg/engine/_prompt_helpers.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ def _check_cross_field_invariants(self) -> Self:
7171
if self.after_tokens > self.before_tokens:
7272
msg = "after_tokens must not exceed before_tokens"
7373
raise ValueError(msg)
74+
if self.trim_tier in {1, 2} and self.after_tokens > self.max_tokens:
75+
msg = (
76+
"after_tokens must not exceed max_tokens for "
77+
f"trim_tier {self.trim_tier} (only tier 3 is best-effort)"
78+
)
79+
raise ValueError(msg)
7480
return self
7581

7682
@computed_field # type: ignore[prop-decorator]
@@ -151,9 +157,9 @@ def _estimate_personality_tokens(
151157
"""Estimate token count of the personality section as the template renders it.
152158
153159
Assembles the text that the Jinja2 template would produce for the
154-
given *personality_mode*, including inline markdown formatting
155-
(bold labels, list prefixes), and runs it through the estimator.
156-
The section heading and template whitespace are not included.
160+
given *personality_mode*, including the section heading and inline
161+
markdown formatting (bold labels, list prefixes), and runs it
162+
through the estimator.
157163
158164
Args:
159165
ctx: Template context dict with personality fields populated.
@@ -163,7 +169,7 @@ def _estimate_personality_tokens(
163169
Returns:
164170
Estimated token count.
165171
"""
166-
parts: list[str] = []
172+
parts: list[str] = ["## Personality"]
167173
desc = ctx.get("personality_description", "")
168174
style = ctx.get("communication_style", "")
169175

src/synthorg/engine/agent_engine.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@ async def _prepare_context( # noqa: PLR0913
892892
PROMPT_PERSONALITY_TRIMMED,
893893
agent_id=agent_id,
894894
agent_name=identity.name,
895+
task_id=task_id,
895896
before_tokens=ti.before_tokens,
896897
after_tokens=ti.after_tokens,
897898
max_tokens=ti.max_tokens,

src/synthorg/engine/prompt.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ def _trim_sections( # noqa: PLR0913
482482
context_budget: str | None = None,
483483
currency: str = DEFAULT_CURRENCY,
484484
profile: PromptProfile | None = None,
485+
trimming_enabled: bool = True,
485486
) -> tuple[
486487
str,
487488
int,
@@ -510,6 +511,7 @@ def _trim_sections( # noqa: PLR0913
510511
context_budget=context_budget,
511512
currency=currency,
512513
profile=profile,
514+
trimming_enabled=trimming_enabled,
513515
)
514516
if estimated <= max_tokens:
515517
break
@@ -543,6 +545,7 @@ def _trim_sections( # noqa: PLR0913
543545
context_budget=context_budget,
544546
currency=currency,
545547
profile=profile,
548+
trimming_enabled=trimming_enabled,
546549
)
547550

548551
_log_trim_results(agent, max_tokens, estimated, trimmed_sections)
@@ -623,6 +626,7 @@ def _render_with_trimming( # noqa: PLR0913
623626
context_budget=context_budget_indicator,
624627
currency=currency,
625628
profile=profile,
629+
trimming_enabled=trimming_enabled,
626630
)
627631

628632
return _build_prompt_result(

0 commit comments

Comments
 (0)