Introducing a new way to review your PRs.

Read the announcement

affaan-m / agentshield

AI agent security scanner. Detect vulnerabilities in agent configurations, MCP servers, and tool permissions. Available as CLI, GitHub Action, ECC plugin, and GitHub App integration. 🛡️

View on GitHub

20 documents · Updated Sep 11, 2026

docs / opus-analysis-orchestration

Opus analysis orchestration

Opus analysis is an optional AI review that adds attacker, defender, and auditor views to a static AgentShield scan. It sends the scanned agent configuration to an Opus model, turns the review into a stable security result, and presents that result as terminal or Markdown output. It is a child of Automation orchestration and complements the GitHub Action entrypoints that start scans in automation.

Analysis pipeline

The Opus pipeline reviews one configuration from three related perspectives. The attacker and defender reviews create evidence first. The auditor then compares both views with the source configuration and produces one practical assessment.

This diagram shows how scan input becomes a final assessment and user-facing output.

flowchart LR
    S[Scan result] --> C[Configuration context]
    C --> A[Attacker review]
    C --> D[Defender review]
    A --> X[Auditor context]
    D --> X
    C --> X
    X --> U[Final assessment]
    U --> R[Terminal or Markdown output]

Pipeline entry

The command-line scan enables Opus with --opus. The --deep option also enables it with the other optional analysis modes. Before the pipeline runs, the command checks for ANTHROPIC_API_KEY. A normal Opus run stops when the key is missing. A deep run keeps the other scan results available.

References: src/index.ts• L269-317 src/index.ts• L575-607

Review stages

The pipeline uses three roles with one shared goal: test the security of an AI agent configuration from different angles. The attacker finds exploit paths. The defender finds missing controls and useful protections. The auditor weighs both views against the original configuration and produces a balanced verdict.

Streamed runs process the roles in order so progress stays readable. Non-streamed runs process the attacker and defender reviews in parallel. The auditor always waits for both reviews because it needs both as input.

References: src/…/pipeline.ts• L345-467 src/types.ts• L204-221

Prompt and result contracts

The prompt layer defines what each role must examine and how it must report its work. Structured tool calls give later stages named fields instead of making them depend only on free-form model text.

Perspective prompts

The attacker prompt asks for concrete attack chains with an entry point, exploit steps, confirmation evidence, and impact. It covers risks such as prompt injection, command injection, data theft, permission escalation, supply-chain abuse, memory poisoning, and unsafe MCP behavior.

The defender prompt asks for control gaps and good practices. It links material exploit paths to prevention, detection, containment, and fix checks. The auditor prompt receives the configuration and both reviews. It favors risks with a real exploit path or observable trigger and weighs impact, persistence, effort, and blast radius.

References: src/…/prompts.ts• L7-76

Structured findings

Each role has a small output contract that gives the next stage stable data to use:

RoleStructured resultMain information
AttackerAttack vectorsAttack chain, entry point, impact, difficulty, evidence, and CVSS estimate
DefenderDefense gaps and good practicesCurrent state, fix, priority, effort, auto-fix status, and control strength
AuditorFinal assessmentRisk level, score, summary, top risks, strengths, and action plan

The pipeline summarizes attacker and defender findings before it adds them to the auditor context. It then converts the richer structured results into a compact three-part OpusAnalysis result. This boundary lets the auditor use detailed evidence while existing output consumers keep a stable shape.

References: src/…/prompts.ts• L78-238 src/…/pipeline.ts• L122-343 src/types.ts• L223-312

Model interaction

Model interaction turns one configuration context into role-specific reviews. Each request has a system prompt, the relevant configuration or audit context, and the tools allowed for that role.

Configuration context

The context builder places each scanned file in a labeled code block. The attacker and defender receive the same source context, so both conclusions use the same evidence. The auditor receives that source context again with separate attacker and defender summaries.

This design preserves the source evidence while giving the auditor the results it must compare. The attacker and defender do not depend on each other’s conclusions.

References: src/…/prompts.ts• L210-238 src/…/pipeline.ts• L379-437

Response handling

The response layer collects model text for reasoning and named tool calls for findings. It supports streamed and non-streamed responses. A streamed request can show detailed model text or a quiet progress indicator. The pipeline parses completed tool inputs into typed results before it sends them to the next stage.

Malformed tool-call JSON is skipped. If the auditor returns no final_assessment call, the parser supplies a medium-risk, 50-point fallback and uses available reasoning as the summary. Auditor scores are limited to the 0–100 range. These rules keep partial model output usable without presenting missing structured data as a strong verdict.

References: src/…/pipeline.ts• L86-120 src/…/pipeline.ts• L182-249 src/…/pipeline.ts• L605-728

Output rendering

The rendering layer turns the compact three-part result into output that a person can read quickly or another report flow can reuse. It keeps the role boundaries visible so the final risk score does not hide the evidence and recommendations.

Terminal presentation

The terminal renderer shows the Opus header, red-team findings, blue-team findings, and auditor assessment. It highlights the risk level and score, then shows the leading recommendations. It limits each finding list to eight items and recommendations to five items. When it shortens a finding list, it states how many items remain.

The wider scan report also records whether Opus output is available and shows its risk level and score in the deep-scan summary. This gives an operator a clear signal when the optional AI review did not run.

References: src/…/render.ts• L4-81 src/…/terminal.ts• L511-524

Markdown presentation

The Markdown renderer preserves the reasoning from all three roles. It adds the auditor risk level, score, and overall assessment in a format suitable for a report or downstream document flow. The public Opus module exports the renderers with the pipeline and parser boundaries.

References: src/…/render.ts• L83-111 src/…/index.ts• L1-14 tests/…/render.test.ts• L80-105

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the role prompt, tool schema, parser, and result type aligned. A field change at one boundary can silently remove evidence before the auditor or renderer sees it.
  • Keep the auditor context labels aligned with the auditor prompt. The auditor relies on the distinction between source configuration, red-team analysis, and blue-team analysis.
  • Keep the compact OpusAnalysis shape aligned with both renderers and the deep-scan summary. These consumers do not use the richer structured result directly.
  • Keep the API-key and stream-mode behavior aligned with CLI options. Terminal mode currently requests streamed progress by default.
  • Keep fallback risk and score behavior visible to consumers. A missing final_assessment is a usable partial result, not proof of medium risk.
  • Keep display limits and overflow text aligned with terminal expectations. Users may otherwise mistake a shortened list for a complete result.

Important failure modes

TriggerConsequenceGuard
--opus runs without ANTHROPIC_API_KEYThe Opus run exits before the model request.Set the key before enabling Opus. A deep run still keeps the other scan results.
A model tool call contains malformed JSONThat finding is skipped, so a role can return reasoning with fewer structured findings.Review the role reasoning and treat missing findings as incomplete evidence.
No final_assessment tool call arrivesThe output uses a medium-risk and 50-point fallback assessment.Do not treat the fallback as a verified auditor verdict.
The model request fails after static scanningOpus output is unavailable, but static scan results remain valid.Use the static report and scan log to separate model failure from scan failure.
Terminal output contains more findings than the display limitThe terminal view shows only the leading items.Use the structured or Markdown output path when the full reasoning is needed.

Key files

FileWhy to read it
src/index.tsShows the CLI boundary, option handling, API-key guard, and place of Opus in the scan lifecycle.
src/…/pipeline.tsShows the staged attacker–defender–auditor flow and the boundary from model responses to usable results.
src/…/prompts.tsDefines the three review goals, their structured report contracts, and the contexts sent to the model.
src/…/render.tsShows how the analysis becomes terminal and Markdown output.
src/types.tsDefines the public analysis shape and the richer structured findings used between stages.
src/…/terminal.tsShows how Opus status appears in the wider deep-scan summary.
tests/…/structured.test.tsSummarizes the guarantees for tool schemas, response parsing, and safe fallback behavior.
tests/…/prompts.test.tsChecks that prompts retain their role goals and that context sections stay distinct.
tests/…/render.test.tsChecks that terminal and Markdown output retain the three perspectives, risk score, and display limits.