Skip to content

FEAT: Add an Agent pane to Co-PyRIT - #4838

Open
Adrian Gavrila (adrian-gavrila) wants to merge 43 commits into
microsoft:mainfrom
adrian-gavrila:adrian-gavrila-copyrit-agent-pane-v1
Open

Adrian Gavrila (adrian-gavrila) wants to merge 43 commits into
microsoft:mainfrom
adrian-gavrila:adrian-gavrila-copyrit-agent-pane-v1

Conversation

@adrian-gavrila

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

Copy link
Copy Markdown
Contributor

Description

Co-PyRIT gets an Agent pane: a chat that sits beside any page, where you can ask about your attacks and scans, have the agent look things up, and start a scan once you've agreed to it. The agent is one of your own registered targets, and it works through Co-PyRIT's REST API as you.

This builds on #4825, which makes TargetSendContext a supported hook. The branch includes that commit until #4825 merges.

What you can do

  • Open Agent from the header on any page. The pane sits beside the page, or over it in a narrow window.
  • Pick the agent. Any registered OpenAI Responses, OpenAI chat, or LiteLLM target whose model handles tool calls can act as the agent; the picker says why the others can't.
  • Ask. The agent looks things up with the same REST operations the MCP endpoint offers, called as you, so it sees what you can see. Each reply has a one-line summary of its lookups that you can expand.
  • Start a scan. The agent describes the scan it would start and waits for your go-ahead in the conversation. The scan carries your operator label. If you stop a reply after the agent started a scan, the conversation still names that scan, so it isn't started twice.
  • Share the page you're on. A chip above the message box names the attack, scan, or page you're viewing; the agent can look it up. Remove the chip to leave it out.
  • Follow links. Links in a reply to an attack, a scan, or an operation open in the same tab and keep the conversation and your draft.
  • Pick up where you left off. Conversations are saved. History lists them, starting with yours, and a refresh brings back the one you had open. Other operators' conversations open read only.

How it's built

  • Turns. AgentService sends each turn through a copy of the chosen target, using PyRIT's own tool loop, with the turn's history supplied through a TargetSendContext. Turns run in the backend process, one at a time per conversation. Stop, a failure, the five-minute limit, and shutdown each save how the turn ended.
  • Storage. Two new tables, AgentConversationEntries and AgentMessageEntries, added by an Alembic migration. Messages are stored as PyRIT MessagePieces, but apart from attack memory, so they never show up in attack history, scoring, or analytics.
  • API. /api/agent endpoints for status, conversations, turns, and Stop, plus GET /api/labels?source=agent_conversations for History's operator filter.
  • Frontend. The pane, its drawer, History, and the page chip.
  • Existing pages. Chat's Conversations panel now closes when the chat area gets too narrow, instead of covering the chat, and comes back when there's room; the Agent pane follows the same rule. A few pieces moved out of existing code so the pane can share them: the sidebar's navigation items, Chat's follow-the-latest scrolling, and the signed-in user's alias on the backend. History's operator filter is the one Attack history already uses.
  • Docs. The GUI guide and the backend README's agent section.

There's no separate approval step before the agent starts a scan in this version; the go-ahead is part of the conversation.

Demo

About a minute, recorded on an isolated database with waits for replies shortened: asking about an attack, expanding the lookups, starting a small scan after confirming it, following the reply's link, History with another operator's conversation open read only, and the narrow-window overlay.

agent-pane-demo.webm

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

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.

🔵 Needs a closer look

The persistence and credential-forwarded execution changes need maintainer validation because SQL Server migration/runtime behavior and agent execution in the production Docker image remain unverified.

No open issues 🎉

What changed in this PR

Adds an Agent pane to Co-PyRIT for discussing attacks and scans, querying data, and starting scans through registered targets and the existing REST API.

Changes:

  • Adds a responsive conversation pane with History, page sharing, lookup summaries, and in-app links.
  • Adds separate conversation storage, agent API types, target eligibility checks, and lifecycle integration.
  • Builds on #4825’s supported TargetSendContext hook, with supporting tests and documentation.
File Description
tests/​unit/​prompt_target/​target/​test_request_tracing.py Uses the public context export.
tests/​unit/​prompt_target/​target/​test_prompt_target.py Tests caller-owned history without persistence.
tests/​unit/​models/​test_agent_conversation.py Tests conversation validation and turn outcomes.
tests/​unit/​mocks.py Adds a reusable agent target mock.
tests/​unit/​memory/​test_agent_conversation_migration.py Checks migration behavior and SQL Server column bounds.
tests/​unit/​memory/​memory_interface/​test_interface_agent_conversations.py Tests isolated storage, ordering, and pagination.
tests/​unit/​backend/​test_runtime_lifecycle.py Tests active-turn reinitialization protection.
tests/​unit/​backend/​test_api_routes.py Tests agent operator labels.
tests/​unit/​backend/​test_agent_tools.py Tests tool attribution and recording.
tests/​unit/​backend/​test_agent_targets.py Tests eligibility and target-copy isolation.
tests/​unit/​backend/​mocks.py Adds a REST toolset mock.
tests/​unit/​backend/​conftest.py Adds isolated agent fixtures.
pyrit/​prompt_target/​common/​target_send_context.py Documents the supported send-context contract.
pyrit/​prompt_target/​common/​prompt_target.py Updates send-context documentation.
pyrit/​prompt_target/​__init__.py Publicly exports TargetSendContext.
pyrit/​prompt_normalizer/​prompt_normalizer.py Uses and documents the public context.
pyrit/​prompt_normalizer/​normalizer_request.py Uses the public context import.
pyrit/​models/​agent_conversation.py Defines conversations and turn-end records.
pyrit/​models/​__init__.py Exports agent models.
pyrit/​memory/​memory_models.py Adds separate agent storage models.
pyrit/​memory/​alembic/​versions/​ffd3cf3adbd9_add_agent_conversations.py Creates agent tables and indexes.
pyrit/​backend/​services/​service_lifecycle.py Integrates agent shutdown and activity checks.
pyrit/​backend/​services/​runtime_lifecycle.py Blocks reinitialization during agent turns.
pyrit/​backend/​services/​message_send_service.py Uses the public context import.
pyrit/​backend/​services/​agent_tools.py Wraps REST tools with caller attribution and recording.
pyrit/​backend/​services/​agent_targets.py Checks eligibility and configures target copies.
pyrit/​backend/​routes/​labels.py Exposes agent conversation operators.
pyrit/​backend/​routes/​attacks.py Reuses the signed-in alias helper.
pyrit/​backend/​README.md Documents agent endpoints and lifecycle.
pyrit/​backend/​models/​agent.py Defines agent API request and response types.
pyrit/​backend/​middleware/​auth.py Extracts the shared user-alias helper.
pyrit/​backend/​main.py Registers agent routes.
frontend/​src/​utils/​userPreferences.ts Validates and restores pane preferences.
frontend/​src/​utils/​agentPaneWidth.ts Defines responsive pane width bounds.
frontend/​src/​utils/​agentPaneWidth.test.ts Tests pane width bounds.
frontend/​src/​utils/​agentAppLink.ts Restricts same-tab reply navigation.
frontend/​src/​utils/​agentAppLink.test.ts Tests accepted and rejected links.
frontend/​src/​types/​index.ts Adds agent UI and API types.
frontend/​src/​test-utils/​layout.ts Adds responsive-layout test helpers.
frontend/​src/​test-utils/​agentFixtures.ts Adds conversation and preference fixtures.
frontend/​src/​services/​api.ts Adds agent API calls and label support.
frontend/​src/​services/​api.test.ts Tests agent request construction.
frontend/​src/​hooks/​useUserPreferences.test.tsx Tests saved pane preference handling.
frontend/​src/​hooks/​useMeasuredElement.ts Tracks element width changes.
frontend/​src/​hooks/​useMeasuredElement.test.ts Tests measurement and observer cleanup.
frontend/​src/​hooks/​useFollowLatest.ts Shares transcript-following behavior.
frontend/​src/​hooks/​useAgentStatus.ts Loads and refreshes target eligibility.
frontend/​src/​hooks/​useAgentStatus.test.ts Tests status refresh and stale responses.
frontend/​src/​hooks/​useAgentPane.tsx Manages persistent pane state and drafts.
frontend/​src/​hooks/​useAgentPane.test.tsx Tests pane persistence and minimum width.
frontend/​src/​hooks/​useAgentPageReference.ts Tracks page-sharing selection.
frontend/​src/​components/​Sidebar/​navigationViews.tsx Extracts shared navigation definitions.
frontend/​src/​components/​Sidebar/​Navigation.tsx Consumes shared navigation definitions.
frontend/​src/​components/​Registry/​Registry.styles.ts Allows tabs to scroll beside the pane.
frontend/​src/​components/​Markdown/​MarkdownContent.tsx Supports allowlisted router links.
frontend/​src/​components/​Markdown/​MarkdownContent.test.tsx Tests preserved new-tab link behavior.
frontend/​src/​components/​Layout/​MainLayout.tsx Adds the Agent button and drawer.
frontend/​src/​components/​Layout/​MainLayout.styles.ts Styles the button and shared workspace.
frontend/​src/​components/​Home/​Home.styles.ts Makes grids adapt to available space.
frontend/​src/​components/​helpDefinitions.ts Adds agent-target help text.
frontend/​src/​components/​ContextualHelpLabel.tsx Supports visually hidden labels.
frontend/​src/​components/​Chat/​TargetBadge.tsx Supports registry-name display.
frontend/​src/​components/​Chat/​MessageList.tsx Reuses transcript-following behavior.
frontend/​src/​components/​Chat/​ChatWindow.styles.ts Constrains the conversation drawer to Chat.
frontend/​src/​components/​Chat/​ChatTargetPicker.tsx Makes the picker reusable for agents.
frontend/​src/​components/​Chat/​ChatTargetPicker.styles.ts Supports compact picker layout.
frontend/​src/​components/​Agent/​PaneResizeHandle.tsx Adds pointer and keyboard resizing.
frontend/​src/​components/​Agent/​PaneResizeHandle.test.tsx Tests resizing controls and announcements.
frontend/​src/​components/​Agent/​PaneResizeHandle.styles.ts Styles the accessible resize handle.
frontend/​src/​components/​Agent/​pageReference.ts Maps routes to shared page references.
frontend/​src/​components/​Agent/​pageReference.test.ts Tests page-reference mapping.
frontend/​src/​components/​Agent/​agentPaneIds.ts Shares pane and composer element IDs.
frontend/​src/​components/​Agent/​AgentPaneDrawer.tsx Handles docking, overlays, resizing, and focus.
frontend/​src/​components/​Agent/​AgentPaneDrawer.styles.ts Bounds drawer width.
frontend/​src/​components/​Agent/​AgentPane.styles.ts Styles pane controls and notices.
frontend/​src/​components/​Agent/​AgentConversationList.tsx Adds filtered, paginated conversation History.
frontend/​src/​components/​Agent/​AgentConversationList.styles.ts Styles History and its filters.
frontend/​src/​components/​Agent/​AgentConversation.tsx Renders replies, lookup summaries, and turn state.
frontend/​src/​components/​Agent/​AgentConversation.test.tsx Tests transcript controls and lookup summaries.
frontend/​src/​components/​Agent/​AgentConversation.styles.ts Styles the transcript and lookup details.
frontend/​src/​components/​Agent/​AgentComposer.test.tsx Tests sending and page-reference chips.
frontend/​src/​components/​Agent/​AgentComposer.styles.ts Styles the composer and sharing controls.
frontend/​src/​App.tsx Integrates agent state and linked-conversation checks.
frontend/​src/​App.test.tsx Tests pane integration and navigation.
frontend/​src/​App.targets.test.tsx Adds agent-status mocking.
frontend/​src/​App.labels.test.tsx Adds agent-status mocking.
frontend/​src/​App.drafts.test.tsx Adds agent-status mocking.
doc/​gui/​0_gui.md Documents pane usage and responsive behavior.
doc/​code/​targets/​11_message_normalizer.py Removes the context’s internal-only wording.
doc/​code/​targets/​11_message_normalizer.ipynb Mirrors the context documentation change.
doc/​code/​targets/​0_prompt_targets.md Documents supported caller-owned send history.

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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