定制 adachsoft/http-tool 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

adachsoft/http-tool

最新稳定版本:v0.1.0

Composer 安装命令:

composer require adachsoft/http-tool

包简介

AI Tool for making HTTP requests with strict URL policies and response limits.

README 文档

README

adachsoft/http-tool is a PHP library that provides an SPI implementation for adachsoft/ai-tool-call. It exposes an http_tool that allows AI agents to perform controlled HTTP requests (GET, POST, PUT, DELETE) with strict security policies and response size limits.

Features

  • Strict URL Policy: Whitelist and blacklist URL prefixes to control where the agent can send requests.
  • Response Limiting: Automatically truncates large response bodies to prevent context overflow.
  • Error Handling: Returns structured error information (e.g., url_not_allowed, response_too_large, transport_error) instead of throwing exceptions, allowing the agent to react.
  • Guzzle Integration: Uses Guzzle for robust HTTP communication.

Installation

composer require adachsoft/http-tool

Configuration

The tool is configured via a ConfigMap passed to the HttpToolFactory.

Configuration Keys

KeyTypeRequiredDescription
max_body_sizeintYesMaximum response body size in bytes. Larger bodies are truncated.
blocked_url_prefixesstring[]NoList of URL prefixes that are strictly forbidden.
allowed_url_prefixesstring[] | nullNoList of allowed URL prefixes. If null (or omitted), all URLs are allowed (except blocked ones).
default_headersmap<string, string>NoDefault HTTP headers added to every request (can be overridden by the agent).

Example

use AdachSoft\AiToolCall\SPI\Collection\ConfigMap;
use AdachSoft\HttpTool\Tool\HttpToolFactory;

$config = new ConfigMap([
    'max_body_size' => 4096, // Limit responses to 4KB
    'blocked_url_prefixes' => ['http://localhost', 'http://127.0.0.1'], // Block local access
    'allowed_url_prefixes' => ['https://api.example.com', 'https://public-api.com'], // Whitelist
    'default_headers' => [
        'User-Agent' => 'MyAIApp/1.0',
    ],
]);

$factory = new HttpToolFactory();
$tool = $factory->create($config);

// Register $tool with your ToolRegistry...

Tool Usage (AI Agent)

The agent invokes the tool http_tool with the following parameters:

  • method (string, required): GET, POST, PUT, or DELETE.
  • url (string, required): Full URL.
  • headers (map, optional): Custom headers.
  • query (map, optional): Query parameters.
  • body (string, optional): Request body.

Response Structure

The tool returns a structured result:

{
  "status_code": 200,
  "reason_phrase": "OK",
  "headers": { ... },
  "body": "{ ... }",
  "body_truncated": false,
  "error_type": null,
  "error_message": null,
  "request_method": "GET",
  "request_url": "https://api.example.com/data"
}

License

MIT

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固