@agentxin-ai/plugin-model-fallback 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +78 -0
  2. package/package.json +44 -0
package/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # AgentXin Plugin: Model Fallback Middleware
2
+
3
+ `@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.
4
+
5
+ ## Key Features
6
+
7
+ - Ordered fallback chain: try primary once, then cycle through `fallbackModels` until one succeeds.
8
+ - Works with any configured LLM (`ICopilotModel`) and reuses AgentXin’s `CreateModelClientCommand` for provider-specific setup and usage reporting.
9
+ - Keeps execution telemetry by wrapping each fallback attempt in `WrapWorkflowNodeExecutionCommand`.
10
+ - Surfaces the last failure if all models are exhausted so callers can handle errors explicitly.
11
+ - Opt-in middleware (non-global) that plugs into the AgentXin agent pipeline.
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ pnpm add @agentxin-ai/plugin-model-fallback
17
+ # or
18
+ npm install @agentxin-ai/plugin-model-fallback
19
+ ```
20
+
21
+ > **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.
22
+
23
+ ## Quick Start
24
+
25
+ 1. **Register the Plugin**
26
+ - Global env-based loading:
27
+ ```sh
28
+ PLUGINS=@agentxin-ai/plugin-model-fallback
29
+ ```
30
+ - Or install dynamically via the system plugin management UI (manual add from the interface).
31
+ The plugin exposes the `ModelFallbackPlugin` module (non-global).
32
+ 2. **Attach the Middleware**
33
+ In the AgentXin console (or agent definition), add a middleware entry with strategy `ModelFallbackMiddleware`.
34
+ 3. **Configure Fallback Models**
35
+ Example middleware block:
36
+ ```json
37
+ {
38
+ "type": "ModelFallbackMiddleware",
39
+ "options": {
40
+ "fallbackModels": [
41
+ { "provider": "openai", "model": "gpt-3.5-turbo" },
42
+ { "provider": "anthropic", "model": "claude-3-sonnet-20240229" }
43
+ ]
44
+ }
45
+ }
46
+ ```
47
+ Models are tried in array order after the primary model defined on the agent.
48
+
49
+ ## Configuration
50
+
51
+ | Field | Type | Description | Default |
52
+ | ----- | ---- | ----------- | ------- |
53
+ | `fallbackModels` | `ICopilotModel[]` | Ordered list of backup models to try when the primary fails. Must contain at least one entry. | – |
54
+
55
+ > Tips
56
+ > - Keep the first fallback close in capability/price to the primary; use later slots for cheaper or more reliable providers.
57
+ > - The UI uses `ai-model-select` with `modelType = LLM`; ensure each entry is a valid LLM configuration.
58
+
59
+ ## Behavior Notes
60
+
61
+ - The primary model is attempted once; any thrown error triggers the fallback loop. Success short-circuits remaining fallbacks.
62
+ - Each fallback attempt creates its own model client via `CreateModelClientCommand` and is wrapped by `WrapWorkflowNodeExecutionCommand` so usage and workflow telemetry stay intact.
63
+ - If every fallback fails, the middleware rethrows the last encountered error to the caller.
64
+ - Environment hooks (e.g., `FORCE_MODEL_ERROR`) can be used during testing to simulate failures before the fallback sequence.
65
+
66
+ ## Development & Testing
67
+
68
+ ```bash
69
+ npm install
70
+ npx nx build @agentxin-ai/plugin-model-fallback
71
+ npx nx test @agentxin-ai/plugin-model-fallback
72
+ ```
73
+
74
+ TypeScript output lands in `packages/model-fallback/dist`. Validate fallback behavior against a staging agent before publishing.
75
+
76
+ ## License
77
+
78
+ This project follows the [AGPL-3.0 License](../../../LICENSE) located at the repository root.
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@agentxin-ai/plugin-model-fallback",
3
+ "version": "0.0.3",
4
+ "author": {
5
+ "name": "AgentXinAI",
6
+ "url": "https://agentxinai.cn"
7
+ },
8
+ "license": "AGPL-3.0",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/agentxin-ai/agentxin-plugins.git"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/agentxin-ai/agentxin-plugins/issues"
15
+ },
16
+ "type": "module",
17
+ "main": "./dist/index.js",
18
+ "module": "./dist/index.js",
19
+ "types": "./dist/index.d.ts",
20
+ "exports": {
21
+ "./package.json": "./package.json",
22
+ ".": {
23
+ "@agentxin-plugins-starter/source": "./src/index.ts",
24
+ "types": "./dist/index.d.ts",
25
+ "import": "./dist/index.js",
26
+ "default": "./dist/index.js"
27
+ }
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "!**/*.tsbuildinfo"
32
+ ],
33
+ "dependencies": {
34
+ "tslib": "^2.3.0"
35
+ },
36
+ "peerDependencies": {
37
+ "zod": "3.25.67",
38
+ "@agentxin-ai/plugin-sdk": "^3.8.1",
39
+ "chalk": "4.1.2",
40
+ "@nestjs/common": "^11.1.6",
41
+ "@metad/contracts": "^3.8.1",
42
+ "@langchain/core": "0.3.72"
43
+ }
44
+ }