{"_id":"@agentxin-ai/plugin-middleware-reflection","name":"@agentxin-ai/plugin-middleware-reflection","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@agentxin-ai/plugin-middleware-reflection","version":"0.0.1","description":"Reflection middleware plugin for AgentXinAI — post-execution quality evaluation, SOP distillation and KEDB archiving.","keywords":["middleware","reflection","agent","agentxin-ai"],"author":{"name":"AgentXinAI Team"},"license":"BUSL-1.1","dependencies":{},"main":"./index.cjs","module":"./index.js","peerDependencies":{"@agentxin-ai/chatkit-types":"^0.0.18","@agentxin-ai/plugin-sdk":"*"},"_id":"@agentxin-ai/plugin-middleware-reflection@0.0.1","_nodeVersion":"22.22.0","_npmVersion":"10.9.4","dist":{"integrity":"sha512-NcRi55TKe+iz0/PCuUzPBCwexGbxQFeOwghu7p9ernj8xWWaeNbe6XMKIGR94msMYJ6f/fzAFdMo3a12yNG9JQ==","shasum":"d46803ee6852f9b0914f79c04b811e9ce45359c9","tarball":"https://registry.npmjs.org/@agentxin-ai/plugin-middleware-reflection/-/plugin-middleware-reflection-0.0.1.tgz","fileCount":15,"unpackedSize":58343,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQC2m4DUaPC8IXwIhV6yRAzAV81GgBp1sNY6MmZtCqVGLQIgYusSY2iJoZYiEYjN8U6UPwCIfrzUJImDFlbPCyW2Gus="}]},"_npmUser":{"name":"agentxin-ai","email":"1304040880@qq.com"},"directories":{},"maintainers":[{"name":"agentxin-ai","email":"1304040880@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/plugin-middleware-reflection_0.0.1_1775187379585_0.5559526326952988"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-03T03:36:19.497Z","0.0.1":"2026-04-03T03:36:19.760Z","modified":"2026-04-03T03:36:20.016Z"},"maintainers":[{"name":"agentxin-ai","email":"1304040880@qq.com"}],"description":"Reflection middleware plugin for AgentXinAI — post-execution quality evaluation, SOP distillation and KEDB archiving.","keywords":["middleware","reflection","agent","agentxin-ai"],"author":{"name":"AgentXinAI Team"},"license":"BUSL-1.1","readme":"# @agentxin-ai/plugin-middleware-reflection\n\n> Post-execution reflection middleware for AgentXinAI agents — evaluates agent performance, distills SOPs from high-scoring executions, and archives known errors from failures.\n\n## Features\n\n- **Quality Evaluation** — LLM-based scoring across tool selection, process adherence, and resolution quality (1–5 scale)\n- **SOP Distillation** — Automatically extracts Standard Operating Procedures from high-scoring executions into a knowledge base\n- **KEDB Archiving** — Archives failure patterns into a Known Error Database for future retrieval\n- **Knowledge Retrieval Augmentation** — Injects relevant SOPs/KEDBs into agent system prompts via `wrapModelCall`\n- **Custom KPIs** — Add domain-specific evaluation metrics\n- **Blended Scoring** — Combines LLM evaluation with optional user ratings\n\n## Installation\n\n```bash\nnpm install @agentxin-ai/plugin-middleware-reflection\n```\n\n## Activation\n\nAdd the plugin to the `PLUGINS` environment variable in your AgentXinAI host project:\n\n```env\nPLUGINS=@agentxin-ai/plugin-middleware-reflection\n```\n\nFor multiple plugins, separate with commas:\n\n```env\nPLUGINS=@agentxin-ai/plugin-middleware-reflection,@agentxin-ai/plugin-agent-middlewares\n```\n\nSee [Plugin Publish & Use](https://docs.agentxinai.cn/zh-Hans/ai/plugin/publish-and-use) for full host-loading documentation.\n\n## Configuration\n\nOnce loaded, navigate to an Agent's middleware settings in AgentXin Studio and add **Reflection Middleware**. Available options:\n\n| Field | Description |\n|---|---|\n| **Evaluation Model** | LLM used for reflection scoring, SOP distillation and KEDB archiving |\n| **Domain Context** | Business domain description for context-aware evaluation |\n| **SOP Knowledge Base** | Knowledge base ID for storing distilled SOPs |\n| **SOP Distill Threshold** | Minimum overall score (1–5) to trigger SOP distillation (default: 4) |\n| **KEDB Knowledge Base** | Knowledge base ID for archiving known errors |\n| **Error Archive Threshold** | Maximum overall score (1–5) to trigger KEDB archiving (default: 2) |\n| **Custom KPIs** | Domain-specific evaluation metrics (key, type, description) |\n| **Reflection Prompt** | Advanced: fully override the built-in evaluation prompt |\n| **SOP Distill Prompt** | Advanced: override the SOP distillation prompt |\n| **KEDB Prompt** | Advanced: override the KEDB archiving prompt |\n\n## How It Works\n\n```\nUser ──► Agent executes ──► afterAgent hook fires\n                                │\n                          ┌─────▼──────┐\n                          │  LLM Score  │  (Phase 1: evaluate execution)\n                          └─────┬──────┘\n                                │\n                    ┌───────────┼───────────┐\n                    ▼           │           ▼\n              Score ≥ 4         │      Score ≤ 2\n           ┌────────┐          │      ┌────────┐\n           │Distill │          │      │Archive │\n           │  SOP   │          │      │  KEDB  │\n           └────────┘          │      └────────┘\n                               ▼\n                     (no write for 3)\n```\n\nOn the next conversation turn, `wrapModelCall` retrieves relevant SOPs/KEDBs and injects them into the agent's system prompt.\n\n## Development\n\n```bash\n# Build\nnpx nx build middleware-reflection\n\n# Test\nnpx nx test middleware-reflection\n\n# Publish\nnpx nx run @agentxin-ai/plugin-middleware-reflection:nx-release-publish --access public\n```\n\n## License\n\nBUSL-1.1\n","readmeFilename":"README.md","_rev":"1-639f9408f3e678e664ac381d8078c1e5"}