plugins/_infection_check/README.md
Safety middleware that analyzes agent output for prompt injection and suspicious external influence before allowing tool execution.
This plugin collects streamed reasoning and response text, analyzes that content with a configurable audit model, and blocks tool execution until the safety check either passes, requests clarification, or terminates the agent.
reasoning_stream_chunk and response_stream_chunk extensions.gate() blocks until the check completes. If the background task already finished (thoughts mode), the result is reused instantly. Otherwise the task is rebuilt with full tool context (name + arguments) for maximum accuracy.<ok/> — Tool execution proceeds silently.<terminate/> — Agent is stopped immediately with a warning log and desktop notification.<clarify> — The agent is asked to explain; a back-and-forth loop runs until resolved.| Mode | What is Analyzed | When Analysis Starts | Latency |
|---|---|---|---|
| thoughts (default) | Reasoning + thoughts | When heading or tool_name appear in response stream | Low — runs in parallel while tool args still stream |
| complete | Reasoning + full response | After the entire response stream ends | Higher — blocking wait before tool execution |
When the check model returns <clarify>:
When the check results in <terminate/> (directly or after exhausting clarifications):
[BLOCKED].process_chain_end extension does not fire after HandledException).HandledException is raised to stop the agent.| Setting | Default | Description |
|---|---|---|
| Mode | thoughts | thoughts or complete |
| Model | utility | utility (faster/cheaper) or main (more capable) |
| Max Clarifications | 3 | Clarification rounds before auto-terminate |
| History Size | 10 | Recent messages included as context |
| Prompt | (built-in) | Fully customizable security audit system prompt |
helpers/checker.py implements stream collection, background analysis, gating, clarification, and termination.extensions/python/reasoning_stream_chunk/_50_infection_collect.pyextensions/python/response_stream_chunk/_50_infection_collect.pyextensions/python/response_stream/_50_infection_analyze.pyextensions/python/response_stream_end/_50_infection_analyze.pyextensions/python/tool_execute_before/_50_infection_check.py| Extension Point | File | Purpose |
|---|---|---|
reasoning_stream_chunk | _50_infection_collect.py | Accumulate reasoning text |
response_stream_chunk | _50_infection_collect.py | Accumulate response text |
response_stream | _50_infection_analyze.py | Detect thoughts complete → start background analysis |
response_stream_end | _50_infection_analyze.py | Start analysis (complete mode / fallback) |
tool_execute_before | _50_infection_check.py | Await check result → gate tool execution |
agenttruetrue_infection_checkInfection Check