@agentxin-ai/plugin-model-retry 0.0.5

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 +79 -0
  2. package/package.json +45 -0
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # AgentXin Plugin: Model Retry Middleware
2
+
3
+ `@agentxin-ai/plugin-model-retry` adds retry logic around AgentXin agent model calls. It keeps LangChain-style retry semantics while exposing only JSON-serializable configuration that can be edited in the AgentXin middleware UI.
4
+
5
+ ## Key Features
6
+
7
+ - Retries failed model calls with configurable retry count, exponential backoff, max delay, and optional jitter.
8
+ - Supports platform-safe retry matching by error name, HTTP status code, and message substring.
9
+ - Returns an `AIMessage` when retries are exhausted in `continue` mode, or rethrows the last error in `error` mode.
10
+ - Wraps retry attempts with `WrapWorkflowNodeExecutionCommand` so middleware-level execution tracking remains visible in AgentXin.
11
+ - Registers as a global middleware plugin so the strategy is available across the platform.
12
+ - Treats `AIMessage.response_metadata.finish_reason === "network_error"` as a retryable model failure, even when the provider returns a message instead of throwing.
13
+ - Treats empty `AIMessage` results with no `tool_calls` and no `invalid_tool_calls` as retryable model failures.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ pnpm add @agentxin-ai/plugin-model-retry
19
+ # or
20
+ npm install @agentxin-ai/plugin-model-retry
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ 1. Register the plugin:
26
+ ```sh
27
+ PLUGINS=@agentxin-ai/plugin-model-retry
28
+ ```
29
+ 2. Add a middleware entry using strategy `ModelRetryMiddleware`.
30
+ 3. Configure retries:
31
+ ```json
32
+ {
33
+ "type": "ModelRetryMiddleware",
34
+ "options": {
35
+ "maxRetries": 2,
36
+ "initialDelayMs": 1000,
37
+ "backoffFactor": 2,
38
+ "maxDelayMs": 60000,
39
+ "jitter": true,
40
+ "retryAllErrors": false,
41
+ "retryableErrorNames": ["RateLimitError"],
42
+ "retryableStatusCodes": [429, 503],
43
+ "retryableMessageIncludes": ["timeout", "temporarily unavailable"],
44
+ "onFailure": "continue"
45
+ }
46
+ }
47
+ ```
48
+
49
+ ## Configuration
50
+
51
+ | Field | Type | Description | Default |
52
+ | ----- | ---- | ----------- | ------- |
53
+ | `maxRetries` | number | Number of retry attempts after the initial failure. `0` disables retries. | `2` |
54
+ | `initialDelayMs` | number | Delay before the first retry attempt, in milliseconds. | `1000` |
55
+ | `backoffFactor` | number | Exponential multiplier applied per retry attempt. `0` keeps a constant delay. | `2` |
56
+ | `maxDelayMs` | number | Upper bound for the computed retry delay. | `60000` |
57
+ | `jitter` | boolean | Adds a bounded random factor to each delay to reduce synchronized retries. | `true` |
58
+ | `retryAllErrors` | boolean | Retry every thrown error when `true`. | `true` |
59
+ | `retryableErrorNames` | string[] | Retry only matching `error.name` values when `retryAllErrors=false`. | `[]` |
60
+ | `retryableStatusCodes` | number[] | Retry matching HTTP-style status codes from `status`, `statusCode`, or `response.status`. | `[]` |
61
+ | `retryableMessageIncludes` | string[] | Retry when the error message contains any configured fragment. Matching is case-insensitive. | `[]` |
62
+ | `onFailure` | `"continue"` \| `"error"` | Return an `AIMessage` or rethrow after retries are exhausted. | `"continue"` |
63
+
64
+ ## LangChain Differences
65
+
66
+ - Function-based `retryOn` and `onFailure` are intentionally not supported because AgentXin middleware configuration must remain serializable.
67
+ - Retry matching uses declarative JSON fields instead of runtime classes or callback functions.
68
+ - Retry attempts are execution-tracked with AgentXin workflow commands, but no model client is recreated during retries.
69
+ - Provider responses that finish with `network_error` are normalized into an internal `ModelNetworkError` and routed through the same retry policy.
70
+ - Provider responses with empty content and no tool call payload are normalized into an internal `ModelEmptyResponseError` and routed through the same retry policy.
71
+
72
+ ## Development & Testing
73
+
74
+ ```bash
75
+ NX_DAEMON=false pnpm -C /path/to/agentxin-plugins/agentxinai exec nx build @agentxin-ai/plugin-model-retry
76
+ NX_DAEMON=false pnpm -C /path/to/agentxin-plugins/agentxinai exec nx test @agentxin-ai/plugin-model-retry
77
+ ```
78
+
79
+ TypeScript output is emitted to `middlewares/model-retry/dist`.
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@agentxin-ai/plugin-model-retry",
3
+ "version": "0.0.5",
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
+ "@nestjs/cqrs": "^11.0.3",
42
+ "@metad/contracts": "^3.8.1",
43
+ "@langchain/core": "0.3.72"
44
+ }
45
+ }