@agentxin-ai/plugin-tool-call-limit 0.0.1

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 +81 -0
  2. package/package.json +44 -0
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # AgentXin Plugin: Tool Call Limit Middleware
2
+
3
+ `@agentxin-ai/plugin-tool-call-limit` enforces tool call quotas for [AgentXin AI](https://github.com/agentxin-ai/agentxin) agents. It tracks tool usage per thread and per run, blocking or ending execution once limits are exceeded while surfacing clear feedback to both the model and the user.
4
+
5
+ ## Key Features
6
+
7
+ - Enforce tool call budgets per thread (persistent) and per run (per invocation), with optional per-tool targeting.
8
+ - Three exit behaviors: `continue` (strip blocked calls, keep going), `error` (throw), and `end` (stop the run with a final message).
9
+ - Injects tool-level error messages so the model knows a limit was hit; adds user-facing notices for blocked calls.
10
+ - Guards against misconfigured tool filters and prevents “end” exits when other tools would continue running.
11
+ - Ships as a global NestJS module that slots directly into the AgentXin middleware pipeline.
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ pnpm add @agentxin-ai/plugin-tool-call-limit
17
+ # or
18
+ npm install @agentxin-ai/plugin-tool-call-limit
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 deps.
22
+
23
+ ## Quick Start
24
+
25
+ 1. **Register the Plugin**
26
+ - Global env-based loading:
27
+ ```sh
28
+ PLUGINS=@agentxin-ai/plugin-tool-call-limit
29
+ ```
30
+ - Or install dynamically via the system plugin management UI (manual add from the interface).
31
+ The plugin registers the global `ToolCallLimitPlugin` module.
32
+ 2. **Attach the Middleware**
33
+ In the AgentXin console (or agent definition), add a middleware entry using strategy `ToolCallLimitMiddleware`.
34
+ 3. **Set Limits and Exit Behavior**
35
+ Example middleware block:
36
+ ```json
37
+ {
38
+ "type": "ToolCallLimitMiddleware",
39
+ "options": {
40
+ "toolName": null,
41
+ "threadLimit": 50,
42
+ "runLimit": 5,
43
+ "exitBehavior": "continue"
44
+ }
45
+ }
46
+ ```
47
+ Set `toolName` to target a specific tool, or leave `null` to count all tool calls. Provide at least one limit; `runLimit` cannot exceed `threadLimit`.
48
+
49
+ ## Configuration
50
+
51
+ | Field | Type | Description | Default |
52
+ | ----- | ---- | ----------- | ------- |
53
+ | `toolName` | string \| null | Tool name to limit; `null` applies limits to all tool calls. | `null` |
54
+ | `threadLimit` | number \| null | Max tool calls per thread (persists across runs). | `null` (no thread cap) |
55
+ | `runLimit` | number \| null | Max tool calls per run (reset each invocation). | `null` (no run cap) |
56
+ | `exitBehavior` | `"continue"` \| `"error"` \| `"end"` | How to react when limits are hit: `continue` blocks excess calls and keeps the run alive; `error` throws; `end` stops the run and returns a final message (only when no other tools would continue). | `"continue"` |
57
+
58
+ > Rules
59
+ > - At least one of `threadLimit` or `runLimit` must be provided.
60
+ > - If both are set, `runLimit` must be less than or equal to `threadLimit`.
61
+
62
+ ## Behavior Notes
63
+
64
+ - Run counts reset at the start of each invocation; thread counts accumulate for the conversation/thread.
65
+ - Blocked tool calls are replaced with `ToolMessage` errors so the model avoids retrying them; user-facing AI messages describe the limit that was hit.
66
+ - For `exitBehavior="end"`, the middleware requires all tool calls to match the filter; otherwise it rejects the configuration to avoid partial execution.
67
+ - Non-matching tools are allowed and not counted, with warnings to help catch misconfigured `toolName` filters.
68
+
69
+ ## Development & Testing
70
+
71
+ ```bash
72
+ npm install
73
+ npx nx build @agentxin-ai/plugin-tool-call-limit
74
+ npx nx test @agentxin-ai/plugin-tool-call-limit
75
+ ```
76
+
77
+ TypeScript output lands in `packages/tool-call-limit/dist`. Validate middleware behavior in a staging agent before publishing.
78
+
79
+ ## License
80
+
81
+ 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-tool-call-limit",
3
+ "version": "0.0.1",
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.7.0",
39
+ "chalk": "4.1.2",
40
+ "@nestjs/common": "^11.1.6",
41
+ "@metad/contracts": "^3.7.0",
42
+ "@langchain/core": "0.3.72"
43
+ }
44
+ }