Skip to content

MAINT: Document TargetSendContext as a supported send hook - #4825

Open
Adrian Gavrila (adrian-gavrila) wants to merge 2 commits into
microsoft:mainfrom
adrian-gavrila:adrian-gavrila-target-send-context-hook
Open

Adrian Gavrila (adrian-gavrila) wants to merge 2 commits into
microsoft:mainfrom
adrian-gavrila:adrian-gavrila-target-send-context-hook

Conversation

@adrian-gavrila

@adrian-gavrila Adrian Gavrila (adrian-gavrila) commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 3051ceaffd14a9a7be6e820ce0c563e7a2d7ad36

Dimension Assessment Rationale
Change confidence 9.5/10 ↑ An export, docstrings, and three import paths moved to the new export; no behavior changes.
↑ check_public_imports is clean across all tracked files, fixing the failed pre-commit job.
↑ The prompt_target, prompt_normalizer, message_send_service, request tracing, and lazy-import tests pass (603), and the changed modules import cleanly in any order.
↑ All CI checks pass on this head.

Description

A caller that keeps a conversation outside PyRIT memory can pass send_context to PromptTarget.send_prompt_async to choose the history a send uses, but TargetSendContext was internal and its contract wasn't written down. This makes it a supported hook. The Co-PyRIT Agent pane, in a follow-up PR, keeps its conversations in their own tables and sends them this way.

  • Export TargetSendContext from pyrit.prompt_target.
  • Document what a context provides: select_history returns a new list the target appends the request to, and target_invocation_count tells the normalizer whether a failed send raises or is saved.
  • Stop calling it internal in PromptTarget, PromptNormalizer, and the targets docs.
  • Test a context that supplies a send's whole history while nothing is saved to memory.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 3, 2026 20:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Three existing TargetSendContext imports still violate check-public-imports after the export change, leaving CI failing until they use the public import path.

1 open issue
What changed in this PR

Makes TargetSendContext a supported public hook for callers that manage conversation history outside PyRIT memory, without changing send behavior.

Changes:

  • Exports TargetSendContext through the public target package.
  • Documents history selection and send lifecycle semantics.
  • Adds a test for caller-supplied history without memory persistence.
File Description
tests/​unit/​prompt_target/​target/​test_prompt_target.py Tests caller-owned history and no persistence.
pyrit/​prompt_target/​common/​target_send_context.py Documents the supported context contract.
pyrit/​prompt_target/​common/​prompt_target.py Updates send-context parameter documentation.
pyrit/​prompt_target/​__init__.py Adds the public lazy export.
pyrit/​prompt_normalizer/​prompt_normalizer.py Uses the public import and updates documentation.
doc/​code/​targets/​11_message_normalizer.py Removes the protocol’s internal-only description.
doc/​code/​targets/​11_message_normalizer.ipynb Mirrors the documentation wording change.
doc/​code/​targets/​0_prompt_targets.md Describes the supported history-selection hook.

Review effort: Balanced

Comment thread pyrit/prompt_target/__init__.py Resolved
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
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