adachsoft/agent-rule-tool
Composer 安装命令:
composer require adachsoft/agent-rule-tool
包简介
SPI tools for exposing and administrating agent rules in the AdachSoft AI tool call ecosystem.
README 文档
README
SPI tool agent_rule for adachsoft/ai-tool-call that exposes effective agent rules from RuleReaderInterface as structured JSON, and SPI tool agent_rule_admin for creating, updating and deleting rules via RuleWriterInterface.
Tool definitions
agent_rule
- Tool name:
agent_rule - Description:
Returns effective agent rules resolved by the injected rule reader. - Tags:
['agent:rules', 'rules', 'agent:general']
agent_rule_admin
- Tool name:
agent_rule_admin - Responsibility: create, update and delete rules using
RuleWriterInterfacewhile enforcing the same content-size limits as theagent_ruletool.
Input parameters for agent_rule (JSON, snake_case)
{
"project_id": 1 // optional, integer or null; when omitted or null -> only global rules; when integer -> global + project rules
}
Rules:
project_idmay beinteger,nullor absent.- Any other type for
project_idcausesInvalidToolCallException.
Mapping to reader:
- missing /
null->getAllByProject(null)(only global rules) - integer
1->getAllByProject(1)(global + project rules for project 1)
Output shape for agent_rule (KeyValueMap → JSON)
The tool result is a KeyValueMap that can be serialized to JSON with the following shape:
{
"project_id": 1, // integer or null
"count": 2, // number of rules
"rules": [
{
"id": "rule_1", // RuleId as string
"type": "REQUIREMENT", // RuleTypeEnum::name
"target": "AGENT", // RuleTargetEnum::name
"content": "...", // string
"priority": 100 // integer
}
]
}
Notes:
rules[*].type/targetare string values from corresponding enums inadachsoft/agent-rule-contract(RuleTypeEnum::name,RuleTargetEnum::name).metadatafromRuleis intentionally not exposed.- Sorting is stable by
prioritydescending and preserves original order for ties.
Safety limits (ConfigMap, shared)
Both tools share the same configuration object AgentRuleToolConfig, which is built from a ConfigMap passed to the factories under the tool names agent_rule and agent_rule_admin.
Supported keys (snake_case):
max_rules(int, default: 100)max_rule_content_bytes(int, default: 500)max_payload_bytes(int, default: 64000)
Semantics:
max_rules: maximum number of rules included in theagent_ruleresponse.max_rule_content_bytes: maximumstrlen(content)per rule; enforced centrally for both read and write paths:agent_rule: refuses to return rules whose content exceeds this limit.agent_rule_admin: refuses to create or update a rule whose content exceeds this limit.
max_payload_bytes: maximumstrlen(json_encode(finalResult))for the wholeagent_rulepayload.
Exceptions:
- invalid input types ->
InvalidToolCallException - invalid config (types, <=0) ->
ToolConfigurationException - exceeded limits (
max_rules,max_rule_content_bytes,max_payload_bytes) ->ToolExecutionException - exceptions from
RuleReaderInterface/RuleWriterInterfaceare propagated as-is.
Quick Start (agent_rule)
- Install dependencies in your project:
composer require adachsoft/ai-tool-call adachsoft/agent-rule-contract adachsoft/agent-rule-tool
Implement
AdachSoft\\AgentRuleContract\\Contract\\RuleReaderInterfacein your application or useadachsoft/agent-ruleJSON-based implementation.Register the tool using
AiToolCallFacadeBuilder:
use AdachSoft\\AiToolCall\\PublicApi\\Builder\\AiToolCallFacadeBuilder;
use AdachSoft\\AiToolCall\\PublicApi\\Dto\\ToolCallRequestDto;
use AdachSoft\\AiToolCall\\SPI\\Collection\\ConfigMap;
use AdachSoft\\AgentRuleTool\\Tool\\AgentRuleToolFactory;
use AdachSoft\\AgentRuleContract\\Contract\\RuleReaderInterface;
$reader = /* your RuleReaderInterface implementation */;
$builder = AiToolCallFacadeBuilder::new()
->withSpiFactories([
new AgentRuleToolFactory($reader),
])
->withToolConfigs([
'agent_rule' => new ConfigMap([
'max_rules' => 100,
'max_rule_content_bytes' => 500,
'max_payload_bytes' => 64000,
]),
]);
$facade = $builder->build();
$result = $facade->callTool(new ToolCallRequestDto('agent_rule', ['project_id' => 1]));
// or
$result = $facade->callTool(new ToolCallRequestDto('agent_rule', []));
The $result is a KeyValueMap that can be converted to an array / JSON according to adachsoft/ai-tool-call documentation.
Quick Start (agent_rule_admin)
To use the admin tool, you need an implementation of RuleWriterInterface:
use AdachSoft\\AiToolCall\\PublicApi\\Builder\\AiToolCallFacadeBuilder;
use AdachSoft\\AiToolCall\\PublicApi\\Dto\\ToolCallRequestDto;
use AdachSoft\\AiToolCall\\SPI\\Collection\\ConfigMap;
use AdachSoft\\AgentRuleTool\\Tool\\AgentRuleAdminToolFactory;
use AdachSoft\\AgentRuleContract\\Contract\\RuleWriterInterface;
$writer = /* your RuleWriterInterface implementation */;
$builder = AiToolCallFacadeBuilder::new()
->withSpiFactories([
new AgentRuleAdminToolFactory($writer),
])
->withToolConfigs([
'agent_rule_admin' => new ConfigMap([
'max_rules' => 100,
'max_rule_content_bytes' => 500, // must match read-side limit to avoid inconsistencies
'max_payload_bytes' => 64000,
]),
]);
$facade = $builder->build();
// Example: create a rule within the configured content limit
$result = $facade->callTool(new ToolCallRequestDto('agent_rule_admin', [
'action' => 'create',
'rule' => [
'id' => 'rule_1',
'type' => 'REQUIREMENT',
'target' => 'AGENT',
'content' => 'Short rule content',
'priority' => 100,
],
'project_id' => null,
]));
If the content value exceeds max_rule_content_bytes, the admin tool will throw a ToolExecutionException with a message indicating that the maximum rule content size has been exceeded, and the rule will not be persisted.
adachsoft/agent-rule-tool 适用场景与选型建议
adachsoft/agent-rule-tool 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「tools」 「rules」 「Agent」 「ai」 「adachsoft」 「ai-tool-call」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 adachsoft/agent-rule-tool 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 adachsoft/agent-rule-tool 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 adachsoft/agent-rule-tool 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
A Laravel package to retrieve data from Google Search Console
Magento 2 module which adds support for Speculation Rules API for instant page loads.
The coding standard applying to all Youdot PHP projects, based on Doctrine set of PHPCS rules, with additional checks.
Business rules engine tools.
Custom laravel monolog logger for datadog logs management, both api and agent ways
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 34
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-08