Skip to content

Compact request event history in role prompts - #5

Merged
rica-v3 merged 2 commits into
release/enhancementfrom
enhancement/prompt-context-compaction
Jul 27, 2026
Merged

Compact request event history in role prompts#5
rica-v3 merged 2 commits into
release/enhancementfrom
enhancement/prompt-context-compaction

Conversation

@rica-v3

@rica-v3 rica-v3 commented Jul 27, 2026

Copy link
Copy Markdown
Member

Summary

  • Add global prompt_context configuration with defaults enabled: true, recent_events: 8, and max_events: 16.
  • Project long request histories for model prompts by keeping the recent tail and backfilling the newest older evidence for roles missing from that tail.
  • Apply the shared projection to normal role tasks, contract repairs, research decisions, and version-controller prompts.
  • Add a content-free compaction notice with total/included/omitted counts and the canonical request-record path.
  • Document compaction, backfill, an exact input/output example, rollback, and telemetry comparison guidance outside the README.

Behavior and boundaries

  • Persisted .teams_runtime/requests/<request_id>.json records are unchanged and retain every event.
  • Selected events are copied without payload truncation, summarization, or mutation.
  • Deep Research payload shaping and session rollover are unchanged.
  • Config changes require role-service restart.
  • Rollback is prompt_context.enabled: false, which restores full event-history prompt inclusion.

Selection policy

  1. Include the final recent_events entries by list position.
  2. Seed roles already represented in that tail.
  3. Scan older events newest-first.
  4. Add the newest qualifying evidence for each missing role until max_events is reached.
  5. Render selected events in their original chronological order.

Role evidence is a role_report in type or legacy event_type, or an event with non-empty payload.role and payload.status. Identity uses payload.role, then actor.

Validation

  • python -m unittest discover -s teams_runtime/tests (769 tests passed)
  • python -m unittest teams_runtime.tests.test_prompt_context (9 tests passed)
  • python -m compileall -q teams_runtime
  • git diff --check
  • Synthetic 100-event prompt remains at or below 16 events and 30% of the disabled-policy prompt size.

Tracks #2.

@rica-v3 rica-v3 self-assigned this Jul 27, 2026
@rica-v3
rica-v3 marked this pull request as ready for review July 27, 2026 06:48
@rica-v3
rica-v3 requested a review from Copilot July 27, 2026 06:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a configurable prompt-time projection of persisted request event history to keep model prompts bounded while preserving full audit history on disk. It adds a shared selection/backfill algorithm (recent tail + newest missing role evidence), propagates configuration through runtimes, and documents how to validate and measure the impact via telemetry.

Changes:

  • Add global prompt_context runtime configuration (default enabled, recent_events=8, max_events=16) and validation during config load/scaffold.
  • Introduce shared/prompt_context.py to project request event histories for prompts and render a content-free compaction notice.
  • Apply the projection + notice to normal role prompts, contract repair prompts, and the research decision prompt; propagate config through TeamService to model-facing runtimes; add dedicated unit tests and documentation.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
workflows/roles/research.py Projects request history for the research decision prompt and emits a compaction notice + runtime log line when applicable.
workflows/orchestration/team_service.py Propagates prompt_context config into all model-facing runtimes created by TeamService.
runtime/base_runtime.py Centralizes request projection + compaction logging and injects the notice + projected request record into normal and repair prompts.
runtime/research_runtime.py Passes the runtime prompt_context_config through to the research decision prompt builder.
shared/prompt_context.py Implements the projection/backfill algorithm and renders the content-free compaction notice.
shared/models.py Adds PromptContextRuntimeConfig and wires it into TeamRuntimeConfig.
shared/config.py Loads/validates prompt_context from team_runtime.yaml (type checks, positivity, and max_events >= recent_events).
templates/scaffold/team_runtime.yaml Adds default prompt_context section to new scaffolds.
tests/test_prompt_context.py Adds focused unit tests for projection/backfill behavior, prompt integration, config defaults/validation, and TeamService propagation.
models.py Re-exports PromptContextRuntimeConfig via the compatibility module.
docs/configuration_guide.md Documents prompt_context configuration, algorithm, and a worked example.
docs/specification.md Updates config specification and adds prompt projection policy description.
docs/operations_guide.md Updates operational description of prompt request records to reflect bounded projection and canonical history path.
docs/telemetry.md Adds guidance for measuring prompt compaction impact using telemetry and runtime logs.
docs/implementation.md Documents ownership/location of the new prompt-context projection module.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rica-v3
rica-v3 merged commit f70b011 into release/enhancement Jul 27, 2026
1 check passed
@rica-v3
rica-v3 deleted the enhancement/prompt-context-compaction branch July 27, 2026 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants