{"_id":"@agentxin-ai/plugin-model-fallback","name":"@agentxin-ai/plugin-model-fallback","dist-tags":{"latest":"0.0.3"},"versions":{"0.0.3":{"name":"@agentxin-ai/plugin-model-fallback","version":"0.0.3","author":{"name":"AgentXinAI","url":"https://agentxinai.cn"},"license":"AGPL-3.0","repository":{"type":"git","url":"git+https://github.com/agentxin-ai/agentxin-plugins.git"},"bugs":{"url":"https://github.com/agentxin-ai/agentxin-plugins/issues"},"type":"module","main":"./dist/index.js","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{"./package.json":"./package.json",".":{"@agentxin-plugins-starter/source":"./src/index.ts","types":"./dist/index.d.ts","import":"./dist/index.js","default":"./dist/index.js"}},"dependencies":{"tslib":"^2.3.0"},"peerDependencies":{"zod":"3.25.67","@agentxin-ai/plugin-sdk":"^3.8.1","chalk":"4.1.2","@nestjs/common":"^11.1.6","@metad/contracts":"^3.8.1","@langchain/core":"0.3.72"},"_id":"@agentxin-ai/plugin-model-fallback@0.0.3","description":"`@agentxin-ai/plugin-model-fallback` retries failed model calls with alternative models in sequence. It wraps agent LLM invocations so outages, throttling, or quality issues on the primary model can be absorbed automatically while preserving execution tra","homepage":"https://github.com/agentxin-ai/agentxin-plugins#readme","_nodeVersion":"22.22.0","_npmVersion":"10.9.4","dist":{"integrity":"sha512-63p4adFDx1mlfUoeU2NGdEe9JlS3PxkomRujYsXJf7qUg1HIJjXDm6ktaZlEUTrEk/mLTjEYj/c8UA0gy5g4ww==","shasum":"9cbed47afa0aa950580fdf0f128a25abd43b0c3c","tarball":"https://registry.npmjs.org/@agentxin-ai/plugin-model-fallback/-/plugin-model-fallback-0.0.3.tgz","fileCount":2,"unpackedSize":4510,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCZ/YflEOP3MTEQ/RDMfMG2mqfWtsA5oxgilwccUAGC+QIgOaTUHO+jvWc0evvFsg+iFIq/ujAhqKE04MHIOqJhi0U="}]},"_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-model-fallback_0.0.3_1773917503212_0.9453547113127685"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-19T10:51:43.136Z","0.0.3":"2026-03-19T10:51:43.385Z","modified":"2026-03-19T10:51:43.572Z"},"maintainers":[{"name":"agentxin-ai","email":"1304040880@qq.com"}],"description":"`@agentxin-ai/plugin-model-fallback` retries failed model calls with alternative models in sequence. It wraps agent LLM invocations so outages, throttling, or quality issues on the primary model can be absorbed automatically while preserving execution tra","homepage":"https://github.com/agentxin-ai/agentxin-plugins#readme","repository":{"type":"git","url":"git+https://github.com/agentxin-ai/agentxin-plugins.git"},"author":{"name":"AgentXinAI","url":"https://agentxinai.cn"},"bugs":{"url":"https://github.com/agentxin-ai/agentxin-plugins/issues"},"license":"AGPL-3.0","readme":"# AgentXin Plugin: Model Fallback Middleware\n\n`@agentxin-ai/plugin-model-fallback` retries failed model calls with alternative models in sequence. It wraps agent LLM invocations so outages, throttling, or quality issues on the primary model can be absorbed automatically while preserving execution tracking and usage metrics.\n\n## Key Features\n\n- Ordered fallback chain: try primary once, then cycle through `fallbackModels` until one succeeds.\n- Works with any configured LLM (`ICopilotModel`) and reuses AgentXin’s `CreateModelClientCommand` for provider-specific setup and usage reporting.\n- Keeps execution telemetry by wrapping each fallback attempt in `WrapWorkflowNodeExecutionCommand`.\n- Surfaces the last failure if all models are exhausted so callers can handle errors explicitly.\n- Opt-in middleware (non-global) that plugs into the AgentXin agent pipeline.\n\n## Installation\n\n```bash\npnpm add @agentxin-ai/plugin-model-fallback\n# or\nnpm install @agentxin-ai/plugin-model-fallback\n```\n\n> **Note**: Ensure the host already provides `@agentxin-ai/plugin-sdk`, `@nestjs/common@^11`, `@langchain/core@^0.3`, `zod`, `chalk`, and `@metad/contracts` as peer/runtime dependencies.\n\n## Quick Start\n\n1. **Register the Plugin**  \n   - Global env-based loading:\n     ```sh\n     PLUGINS=@agentxin-ai/plugin-model-fallback\n     ```\n   - Or install dynamically via the system plugin management UI (manual add from the interface).  \n   The plugin exposes the `ModelFallbackPlugin` module (non-global).\n2. **Attach the Middleware**  \n   In the AgentXin console (or agent definition), add a middleware entry with strategy `ModelFallbackMiddleware`.\n3. **Configure Fallback Models**  \n   Example middleware block:\n   ```json\n   {\n     \"type\": \"ModelFallbackMiddleware\",\n     \"options\": {\n       \"fallbackModels\": [\n         { \"provider\": \"openai\", \"model\": \"gpt-3.5-turbo\" },\n         { \"provider\": \"anthropic\", \"model\": \"claude-3-sonnet-20240229\" }\n       ]\n     }\n   }\n   ```\n   Models are tried in array order after the primary model defined on the agent.\n\n## Configuration\n\n| Field | Type | Description | Default |\n| ----- | ---- | ----------- | ------- |\n| `fallbackModels` | `ICopilotModel[]` | Ordered list of backup models to try when the primary fails. Must contain at least one entry. | – |\n\n> Tips  \n> - Keep the first fallback close in capability/price to the primary; use later slots for cheaper or more reliable providers.  \n> - The UI uses `ai-model-select` with `modelType = LLM`; ensure each entry is a valid LLM configuration.\n\n## Behavior Notes\n\n- The primary model is attempted once; any thrown error triggers the fallback loop. Success short-circuits remaining fallbacks.\n- Each fallback attempt creates its own model client via `CreateModelClientCommand` and is wrapped by `WrapWorkflowNodeExecutionCommand` so usage and workflow telemetry stay intact.\n- If every fallback fails, the middleware rethrows the last encountered error to the caller.\n- Environment hooks (e.g., `FORCE_MODEL_ERROR`) can be used during testing to simulate failures before the fallback sequence.\n\n## Development & Testing\n\n```bash\nnpm install\nnpx nx build @agentxin-ai/plugin-model-fallback\nnpx nx test @agentxin-ai/plugin-model-fallback\n```\n\nTypeScript output lands in `packages/model-fallback/dist`. Validate fallback behavior against a staging agent before publishing.\n\n## License\n\nThis project follows the [AGPL-3.0 License](../../../LICENSE) located at the repository root.\n","readmeFilename":"README.md","_rev":"1-5d0281167e9d022aa033a489579628e1"}