An ai gateway upstream adapter automatic generation verification publishing method and system
Patent Information
- Application Number
- CN202611210935.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-11
- Publication Date
- 2026-10-16
AI Technical Summary
[0008]第二,AI辅助生成适配器时缺少可验证闭环
本发明通过对外接口规范、上游调用规范、统一协议对象模型三层架构,将客户端接口承诺、上游原生规则、内部统一语义完全解耦;适配器仅负责协议转换,上游差异不会侵入网关核心逻辑,避免专用适配代码扩散,大幅降低多上游接入的维护复杂度与变更风险;以上游官方文档、真实录制报文等独立证据为唯一基准生成测试预期,测试与实现解耦生成,结合只读审查机制,从根源上避免AI生成的“自验证”缺陷,显著提升适配逻辑与上游真实接口行为的一致性;通过五维联合准入校验与默认拒绝策略,未通过完整验证的适配器绝对无法接入生产流量;结合灰度发布与条件化自动回滚能力,将上线风险控制在最小范围,大幅提升AI网关的运行稳定性与接入边界安全性。
Smart Images

Figure CN122933425A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence gateway technology, and in particular to an AI gateway upstream adapter automatic generation, verification, and release method and system for the full-link control of adapter automatic generation, closed-loop verification, and access release for upstream service access scenarios of AI gateway platforms. Background Technology
[0002] With the development of large-scale model applications, intelligent agent applications, multimodal generation applications, and enterprise-level AI platforms, more and more business systems need to access different upstream services through AI gateway platforms. These upstream services refer to external or internal AI model services, generation services, real-time communication services, or asynchronous task services that the AI gateway platform forwards requests to, such as OpenAI API-formatted text services, image generation services, audio processing services, video generation services, or task-oriented interface services.
[0003] When an AI gateway platform connects to different upstream services, an adapter layer is typically needed to handle interface differences. This adapter is responsible for rewriting the unified requests within the AI gateway platform into requests that the upstream services can accept, and then organizing the results, errors, streaming events, or task statuses returned by the upstream into a unified format within the AI gateway platform. If a dedicated adaptation link is manually added for each upstream service connected, differences in interface addresses, authentication headers, request bodies, response bodies, error formats, streaming events, and task statuses can easily become scattered throughout the gateway's main link. The dedicated adaptation link can include a provider-specific processing module, dedicated configuration, dedicated error classification logic, and corresponding tests.
[0004] To avoid reinterpreting interface behavior for each upstream service, this invention breaks down access information into three types of technical objects: external interface specifications, which describe the AI gateway platform's interface commitments to clients; upstream call specifications, which describe the calling method of a specific upstream service; and a unified protocol object model, which uniformly expresses protocol semantics such as requests, responses, errors, streaming events, and usage fields within the AI gateway platform. All three types of technical objects can be represented using structured data and can be invoked in verification, test generation, adapter generation, and review processes.
[0005] Upstream interface evidence refers to materials that can prove the behavior of upstream service interfaces, such as upstream documentation, software development kit examples, command-line request examples, recorded responses, existing adapter code, or manually verified samples. Test baseline samples refer to fixed sample data used to verify protocol behavior, such as request samples, response samples, error samples, or streaming event samples. The protocol coverage matrix records the correspondence between key protocol paths, test baseline samples, and test cases. Adapter versions refer to adapter implementation objects that can be published, bound, rolled back, and audited by the AI gateway platform, and may include adapter change patches, upstream call specification changes, adapter implementation files, build files, or combinations thereof. Version summaries are used to verify the consistency of adapter version content and for release tracking and rollback location.
[0006] The existing solutions have the following main problems.
[0007] First, differences in upstream services can easily intrude into the core processing chain. Different upstream services differ in interface addresses, authentication headers, request fields, response fields, error formats, streaming events, and task statuses. If these differences are addressed by adding provider-specific processing modules, adapter packages, or processing branches to the main project, protocol conversion, error classification, test evidence, and release strategies will become mixed up in the core system.
[0008] Second, AI-assisted adapter generation lacks a verifiable closed loop. If the model simply reads the documentation and generates code directly, it is easy to write interface behaviors that have not been confirmed by the source materials into the adapter implementation. If the test expectations and implementations are generated by the same process, and there is a lack of independent upstream interface evidence or manually confirmed examples, then even if the test passes, it is difficult to prove that the adapter meets the requirements of the real upstream interface.
[0009] Third, the adapter generation results lack an auditable release admission mechanism. Even if adapter change patches, configuration files, or adapter versions are generated, without linking upstream interface evidence, unified protocol object models, test benchmarks, protocol coverage matrices, test results, read-only review results, version summaries, and admission records, it is difficult to determine whether the adapter can be put into production access, and it is also difficult to locate the specific adapter version and rollback target in case of anomalies.
[0010] In summary, existing technologies cannot simultaneously meet the triple requirements of upstream access efficiency, adaptation logic accuracy, and release governance security. There is an urgent need for a standardized, evidence-driven, and process-controllable solution for the automatic generation, verification, and release of adapters. Summary of the Invention
[0011] The purpose of this invention is to address the shortcomings of existing technologies by providing an automatic generation, verification, and release method and system for upstream adapters in AI gateways. This method clarifies client commitments, upstream call methods, and internal protocol semantics through external interface specifications, upstream call specifications, and a unified protocol object model. It transforms protocol behavior into repeatable and verifiable evidence through test benchmark examples, protocol coverage matrices, simulated end-to-end testing, and replay end-to-end testing. A controlled AI agent participates in stages in document summarization, protocol model draft generation, protocol coverage matrix generation, adapter change patch generation, failure log interpretation, and semantic review. Furthermore, a deterministic process control module controls state progression, generation quality verification, read-only review, failure rework, and release access verification, ensuring that candidate adapter versions have verifiable, auditable, and rollbackable evidence before entering production access.
[0012] To achieve the above objectives, the technical solution of the present invention is as follows: This invention provides a method for automatically generating verification and publishing for an AI gateway upstream adapter, comprising the following steps: Receive the adapter basic specifications and upstream interface evidence. After the specifications are verified, extract interface feature items and establish evidence index through the controlled upstream document summarization agent. Generate external interface specifications and upstream call specifications respectively, and compile them into a unified protocol object model. Extract the set of key protocol paths from the unified protocol object model, match test benchmark samples for each key protocol path based on upstream interface evidence, establish a protocol coverage matrix that maps key protocol paths, test benchmark samples, and test cases one by one, generate and execute multiple types of test cases, and calculate protocol path coverage. The code generation agent, which has restricted write permissions, generates adapter implementation code or change patches based on the unified protocol object model, protocol coverage matrix, and test benchmark samples. When a test fails, the repair agent determines the cause of failure in a hierarchical manner and performs automatic repair within the authorized scope. After all tests pass, the read-only review agent performs semantic compliance review and generates candidate adapter versions after reviewing for no blocking items. Perform multi-dimensional joint admission verification on candidate adapter versions. If the release admission judgment meets the requirements, an admitted adapter version is generated. Otherwise, the default rejection policy is executed, and the adapter is not bound to any production route. The admitted adapter version is released in a canary manner according to the preset rules. During the operation, the operation observation data is continuously collected. When the preset rollback conditions are met, the version rollback is automatically triggered. The entire process is managed by a deterministic process control module, which controls the flow of task status, generation quality verification, and failure rework decisions. This restricts each AI agent to perform operations within a specified scope at its corresponding stage and prohibits it from changing acceptance criteria or releasing versions on its own.
[0013] As a further aspect of this invention, the external interface specification is a unified interface commitment from the AI gateway platform to the client; the upstream call specification is the native call rule of the target upstream service; and the unified protocol object model is a unified protocol semantic benchmark within the gateway, serving as a unified basis for testing, generation, review, and release. The specification verification includes structural verification and semantic verification: structural verification is used to check the integrity of fields and the correctness of data types; semantic verification is used to verify the logical consistency of capability declarations, upstream addresses, authentication methods, and field mappings; when verification fails, the error reason and pending confirmation items are output, terminating the process of entering the candidate adapter generation stage.
[0014] As a further aspect of the present invention, the upstream interface evidence includes upstream official documentation, software development kit examples, command line request examples, recorded response messages, existing adapter code, and manual confirmation examples; the evidence index records the evidence source and confidence level corresponding to each interface feature item; interface behaviors that cannot be confirmed from the upstream interface evidence are marked as items to be confirmed and are not included in the stable specification.
[0015] As a further aspect of the present invention, when there is a conflict between upstream interface evidence from different sources, the corresponding protocol path is marked as pending confirmation and is not included in the protocol coverage matrix and the scope of release access verification until manual confirmation is completed.
[0016] As a further aspect of the present invention, the key protocol paths include six categories: request field mapping path, response field mapping path, error classification mapping path, streaming event processing path, task status synchronization path, and usage field extraction path; the test benchmark samples include request samples, response samples, error samples, streaming event samples, task submission samples, and task query samples.
[0017] As a further aspect of the present invention, multiple types of test cases are generated and executed, including three categories: unit tests, simulated end-to-end tests, and replay end-to-end tests. Unit tests are used to verify the atomic mapping logic of a single critical protocol path; Simulated end-to-end testing verifies the entire protocol conversion process of the adapter by simulating the return of test baseline samples from upstream services. The replay end-to-end test verifies the adapter's compatibility with the actual upstream return structure by playing back the actual recorded upstream responses, streaming events, and task statuses.
[0018] As a further aspect of the present invention, the formula for calculating protocol path coverage is as follows: ; in, This is a set of key protocol paths that have been associated with valid test benchmarks and test cases and have independent evidence to support them. To extract the set of key protocol paths from the unified protocol object model; paths lacking test benchmarks, test cases, or sources of evidence are not included. Protocol paths marked as inapplicable after manual verification are not included. The preset threshold for protocol path coverage is 100%. The system must not proceed with the automatic deployment process if the threshold is not reached. Critical protocol paths that have been manually confirmed and marked as inapplicable are not included in the calculation. gather.
[0019] As a further aspect of the present invention, the scope of writing the code-generated intelligent agent is strictly limited to the target adapter-related files, and modification of test files, test benchmark samples, test cases, acceptance criteria, AI gateway platform public modules, authentication modules, routing modules, log modules, release configurations and key configurations is prohibited.
[0020] As a further aspect of the present invention, the repair agent categorizes the reasons for test failure into five types: implementation defects, specification conflicts, test benchmark conflicts, test disputes, and unknown upstream behavior. Only when an implementation defect is identified can the repair agent generate a fix patch within the target adapter file scope and automatically retest. If the defect is determined to be non-implementation type, or if the automatic repair fails after exceeding the preset maximum number of rounds, the task will be transferred to manual confirmation.
[0021] As a further aspect of the present invention, the read-only review agent only has full read permissions and no write permissions, and the review dimensions include: Does the adapter implementation deviate from the unified protocol object model? Does the test case contain false coverage or empty assertions? Whether to introduce upstream interface behaviors not recorded in the evidence index; Is there any unauthorized modification of unauthorized files? Should test cases be deleted or the strength of test assertions reduced? If any blocking item exists, the task will enter a failed rework or manual confirmation state, and no candidate adapter version may be generated.
[0022] As a further aspect of the present invention, if and only if the admission determination meets the requirements. At that time, an approved adapter version is generated, and the five dimensions of the joint access verification are published as follows: The tests and verifications have passed, including at least specification verification, protocol path coverage verification, unit testing, simulated end-to-end testing, and replay end-to-end testing. Read-only review has no blocking items; The applicable interface scope and capability policy of the candidate adapter version meet the production route binding requirements; Version summary, readiness check evidence, and confirmed sample playback evidence are all complete; It complies with the platform's access control policy and gray-scale management rules.
[0023] As a further aspect of the present invention, the default rejection policy is as follows: when a production route request does not match the corresponding admitted adapter version, the platform standard error code is returned directly, without falling back to the unverified version, the default adaptation logic, or the original pass-through mode; when binding the production route, the admitted adapter version is accurately parsed according to the channel, interface range, and adapter version identifier, and if a match is not found, it is not automatically fallen back to other unverified versions.
[0024] As a further aspect of the present invention, the canary release supports traffic allocation by channel, user group, token identifier, model matching rule, and routing dimension; the operation observation data includes at least the unique request identifier, the hit adapter version, the interface range, the error classification, and the response time; the preset rollback conditions include the error rate threshold, the timeout rate threshold, the number of readiness check failures, and the number of binding exceptions. When a rollback is triggered, the system restores to the previous stable and approved version according to the pre-registered rollback target, and records the rollback time, the rollback reason, the original adapter version, and the target adapter version.
[0025] As a further aspect of the present invention, the deterministic flow control module maintains a finite state machine, and the task states include at least: pending specification verification, protocol model generated, test generated, test failed, test passed, pending review, review blocked, admission rejected, admitted, published, and rolled back; all state transitions are triggered only by deterministic rules, and each AI agent has no right to actively change the task state. Secondly, the present invention also provides an AI gateway upstream adapter automatic generation verification and release system, including a deterministic process control module, a specification and evidence processing module, a test benchmark sample generation and coverage verification module, a candidate adapter version generation and review module, and a release admission and production route binding module; The deterministic process control module is used to maintain the full-link task state machine, manage the execution order and state transition of each module, perform generation quality verification, failure rework and manual confirmation scheduling, restrict each AI agent to operate on the specified object only in the specified stage, and shall not change the acceptance criteria or release the candidate adapter version on its own. The specification and evidence processing module is used to receive adapter specifications and upstream interface evidence, perform specification verification, extract interface feature items through a controlled upstream document summarization agent and establish an evidence index, generate external interface specifications and upstream call specifications, and compile them into a unified protocol object model, which serves as a unified benchmark for subsequent testing, generation, review and release. The test benchmark sample generation and coverage verification module is used to extract a set of key protocol paths from the unified protocol object model, generate test benchmark samples based on upstream interface evidence matching, construct a protocol coverage matrix that maps key protocol paths, test benchmark samples, and test cases one by one, generate and execute multiple types of test cases, calculate protocol path coverage and perform coverage verification. The candidate adapter version generation and review module is used to call a code generation agent with restricted write permissions to generate adapter implementation code or change patches based on a unified protocol object model, protocol coverage matrix and test benchmark samples. When the test fails, the failure reason is determined by the repair agent level and automatic repair is performed within the authorized scope. After the test passes, semantic compliance review is performed by a read-only review agent. After reviewing that there are no blocking items, a candidate adapter version is generated. The release admission and production route binding module is used to perform multi-dimensional joint admission verification on candidate adapter versions. If the verification is successful, an admitted adapter version is generated and gray release and production route binding are performed. If the verification fails, a default rejection policy is implemented and production traffic is not accessed. At the same time, operation observation data is continuously collected, and version rollback is automatically triggered when preset rollback conditions are met, and full-link audit records are retained.
[0026] As a further aspect of the present invention, the specification verification performed by the specification and evidence processing module includes structural verification and semantic verification; The structure verification is used to check the completeness and data type correctness of the required fields in the adapter specification. The required fields include adapter name, version, upstream address, request method, authentication method, capability declaration and publication constraint information. The semantic verification is used to verify the logical consistency between the capability declaration, upstream address, authentication method, field mapping and upstream calling specification; If the verification fails, the error reason and the items to be confirmed will be output, and the process will terminate and proceed to the candidate adapter version generation stage.
[0027] As a further aspect of the present invention, the upstream interface evidence includes upstream official documentation, software development kit examples, command line request examples, recorded response messages, existing adapter code, and manual confirmation samples; The upstream document summarization agent only has read permissions and outputs a list of interface feature items and an evidence index. The evidence index records the evidence source and confidence level corresponding to each interface feature item. Interface behaviors that cannot be confirmed from upstream interface evidence, as well as protocol paths where evidence from multiple sources conflicts, are marked as items pending confirmation. They are not included in stable specifications, nor are they included in the protocol coverage matrix or release access verification scope, until manual confirmation is completed.
[0028] As a further aspect of the present invention, the external interface specification is a unified interface commitment of the AI gateway platform to the client, and the upstream call specification is the native call rule of the target upstream service; The unified protocol object model includes six semantic domains: request domain, response domain, error domain, streaming event domain, task domain, and usage domain. It uniformly expresses the protocol semantics within the AI gateway, and all downstream processes are executed based on this unified protocol object model.
[0029] As a further aspect of the present invention, the set of key protocol paths includes six categories: request field mapping path, response field mapping path, error classification mapping path, streaming event processing path, task status synchronization path, and usage field extraction path. The test baseline samples include request samples, response samples, error samples, streaming event samples, task submission samples, and task query samples. The field values, event order, and expected results of the test baseline samples are all derived from upstream interface evidence or manually confirmed samples.
[0030] As a further aspect of the present invention, the test cases generated by the test benchmark sample generation and coverage verification module include three types: unit tests, simulated end-to-end tests, and replay end-to-end tests. The unit tests are used to verify the atomic mapping logic of a single critical protocol path; The simulated end-to-end test verifies the entire link protocol conversion process by simulating the return of test benchmark samples from upstream services. The playback end-to-end test verifies the adapter's compatibility with the actual return structure by playing real-recorded upstream responses, streaming events, and task status examples. Actual upstream service calls are used only as supplementary verification, not as the default and sole verification condition.
[0031] As a further aspect of the present invention, the scope of writing the code-generating intelligent agent is strictly limited to the target adapter-related files, and modification of test files, test benchmark samples, test cases, acceptance criteria, as well as the AI gateway platform's public modules, authentication modules, routing modules, log modules, release configurations, and key configurations is prohibited; For scenarios requiring changes to upstream calling specifications, the code generation agent only generates suggested changes, which can only be registered after verification by the deterministic flow control module.
[0032] As a further aspect of the present invention, the repair agent classifies the reasons for test failure into five categories: implementation defects, specification conflicts, test benchmark conflicts, test disputes, and unknown upstream behavior. Only when an implementation defect is identified can the repair agent generate a patch within the target adapter file and retest. If a defect is determined to be non-implementation type, or if automatic repair fails to pass the test after exceeding the preset maximum number of rounds, the system will switch to manual confirmation.
[0033] As a further aspect of the present invention, the read-only review agent only has full read permissions and no write permissions, and the review dimensions include: Does the adapter implementation deviate from the unified protocol object model? Does the test case contain false coverage or empty assertions? Whether to introduce upstream interface behaviors not recorded in the evidence index; Is there any unauthorized modification of unauthorized files? Should test cases be deleted or the strength of test assertions reduced? If any blocking item exists, the deterministic process control module records the reason for the blocking, the task is transferred to a failure rework or manual confirmation state, and no candidate adapter version is generated.
[0034] As a further aspect of the present invention, the default rejection policy is as follows: when a production routing request does not match the corresponding admitted adapter version, the platform standard error code is returned directly, without reverting to the unverified version, the default adaptation logic, or the original pass-through mode. When binding production routes, the system accurately resolves the approved adapter versions based on the channel, interface range, and adapter version identifier. If a version is not matched, the system does not automatically fall back to other unverified versions.
[0035] As a further aspect of the present invention, the canary release supports traffic allocation by channel, user group, token identifier, model matching rule, and routing dimension; The operational observation data shall include at least the unique identifier of the request, the version of the hit adapter, the interface range, the error classification, and the response time; The preset rollback conditions include error rate threshold, timeout rate threshold, number of readiness check failures, and number of binding exceptions. When a rollback is triggered, the system restores the system to the previous stable and approved version according to the pre-registered rollback target, and records the rollback time, rollback reason, original adapter version, and target adapter version.
[0036] As a further aspect of the present invention, the task status maintained by the deterministic process control module includes at least the following: pending specification verification, protocol model generated, test generated, test failed, test passed, pending review, review blocked, access denied, access granted, published, and rollback. All state transitions are triggered solely by deterministic rules; no AI agent has the right to proactively change the task state.
[0037] As a further aspect of the present invention, the adapter version is only responsible for handling protocol differences of upstream services, including generating upstream request plans, transforming request bodies, interpreting response bodies, processing streaming events, submitting or querying tasks, extracting usage fields, and classifying error responses. The core of the AI gateway platform is still responsible for client authentication, routing selection, retry policies, log tracking, platform-level security control, and billing processing. The adapter only extracts usage data and does not perform billing operations such as deduction, refund, or closing of billing status.
[0038] Compared with existing technologies, the AI gateway upstream adapter automatic generation verification and release method and system provided in this application have the following advantages: This invention employs a three-layer architecture—external interface specifications, upstream call specifications, and a unified protocol object model—to completely decouple client interface commitments, upstream native rules, and internal unified semantics. The adapter is solely responsible for protocol conversion; upstream differences do not intrude into the gateway's core logic, preventing the proliferation of dedicated adaptation code and significantly reducing the maintenance complexity and change risks associated with multiple upstream access points. Test expectations are generated using independent evidence such as official upstream documentation and actual recorded packets as the sole benchmark. Testing and implementation are decoupled, and combined with a read-only review mechanism, the "self-verification" defects generated by AI are fundamentally avoided, significantly improving the consistency between adaptation logic and actual upstream interface behavior. Through five-dimensional joint admission verification and a default rejection strategy, adapters that fail complete verification are absolutely prohibited from accessing production traffic. Combined with canary releases and conditional automatic rollback capabilities, deployment risks are minimized, significantly improving the operational stability and access boundary security of the AI gateway. Attached Figure Description
[0039] Figure 1 This invention provides an automatic generation, verification, and release method for upstream adapters of an AI gateway, as well as a schematic diagram of the overall closed loop of automatic adapter generation, verification, and release in the system.
[0040] Figure 2 This invention provides an automatic generation, verification, and release method for an AI gateway upstream adapter, as well as a schematic diagram of test benchmark sample generation and protocol path coverage in the system.
[0041] Figure 3 This invention provides a method for automatically generating, verifying, and publishing upstream adapters for AI gateways, as well as a schematic diagram of adapter version publishing access and production route binding control in the system. Detailed Implementation
[0042] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs; the terminology used herein in the specification of the application is for the purpose of describing particular embodiments only and is not intended to limit the application; the terms "comprising" and "having," and any variations thereof, in the specification, claims, and foregoing drawings of this application are intended to cover non-exclusive inclusion. The terms "first," "second," etc., in the specification, claims, or foregoing drawings of this application are used to distinguish different objects, not to describe a particular order.
[0043] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0044] To address the problems in existing technologies, such as upstream service protocol differences easily intruding into the core processing chain of AI gateways, scattered adaptation code and high maintenance costs, lack of independent evidence constraints when AI-assisted adapter generation leading to verification loop failures, poor consistency between adaptation logic and actual upstream behavior, and lack of auditable admission mechanisms for adapter releases resulting in uncontrollable deployment risks and difficulties in anomaly rollback localization, this invention provides an automatic generation, verification, and release method and system for AI gateway upstream adapters. This system clarifies client commitments, upstream call methods, and internal protocol semantics through external interface specifications, upstream call specifications, and a unified protocol object model. It transforms protocol behavior into repeatable verifiable evidence through test benchmark examples, protocol coverage matrices, simulated end-to-end testing, and replay end-to-end testing. A controlled AI agent participates in stages in document summarization, protocol model draft generation, protocol coverage matrix generation, adapter change patch generation, failure log interpretation, and semantic review. Finally, a deterministic process control module controls state progression, generation quality verification, read-only review, failure rework, and release admission verification, ensuring that candidate adapter versions have verifiable, auditable, and rollbackable evidence before entering production access.
[0045] See Figures 1 to 3 As shown, this invention provides an automatic generation, verification, and release method for upstream adapters of AI gateways. For upstream service access scenarios on AI gateway platforms, it constructs a full-link system of "specification definition—evidence-driven—controlled generation—closed-loop verification—access release—operational governance." Architecturally, it decouples upstream protocol differences from the core gateway link; mechanistically, it solves the verification distortion problem of AI-generated adapters; and procedurally, it achieves auditability and rollbackability throughout the entire release lifecycle. The overall closed-loop system is as follows: Figure 1As shown, starting with upstream interface evidence, a three-layer protocol object is generated through standardized access. This object then enters a closed-loop generation and verification process to complete test construction, code generation, multiple rounds of testing, and read-only review. Failure triggers rework or manual confirmation. Successful verification proceeds to release access verification. Successful verification generates an approved version and binds it to the production route; failure executes a default rejection policy, prohibiting access to production traffic. This embodiment of the AI gateway upstream adapter automatic generation and verification release method includes the following steps: S1. Standardized access and construction of a unified protocol object model.
[0046] After receiving the adapter's basic specifications and upstream interface evidence, and performing specification verification, the system extracts interface feature items and establishes an evidence index through a controlled upstream document summarization agent. It then generates external interface specifications and upstream call specifications, and compiles them into a unified protocol object model.
[0047] This embodiment receives the adapter's basic specifications and upstream interface evidence, performs structural and semantic verification; if verification fails, it outputs errors and items to be confirmed, and terminates the process; if verification passes, it calls the upstream document summarizing agent, which only has read permissions, to extract eight categories of interface features and generate an evidence index table; features without evidence or with conflicting evidence are marked as to be confirmed; then it generates external interface specifications and upstream call specifications, compiles them into a unified protocol object model containing six semantic domains, and uses it as the sole benchmark for the entire process.
[0048] In this embodiment, the external interface specification is the unified interface commitment of the AI gateway platform to the client, the upstream call specification is the native call rule of the target upstream service, and the unified protocol object model is the unified protocol semantic benchmark within the gateway, serving as a unified basis for testing, generation, review, and release. The specification verification includes structural verification and semantic verification: structural verification is used to check the integrity of fields and the correctness of data types; semantic verification is used to verify the logical consistency of capability declarations, upstream addresses, authentication methods, and field mappings; when verification fails, the error reason and the item to be confirmed are output, and the process terminates and enters the candidate adapter generation stage.
[0049] The upstream interface evidence includes upstream official documentation, software development kit examples, command line request examples, recorded response messages, existing adapter code, and manual confirmation examples; the evidence index records the evidence source and confidence level corresponding to each interface feature item; interface behaviors that cannot be confirmed from the upstream interface evidence are marked as items to be confirmed and are not included in the stable specification.
[0050] When upstream interface evidence from different sources conflicts, the corresponding protocol path is marked as pending confirmation and is not included in the protocol coverage matrix and release access verification scope until manual confirmation is completed.
[0051] S2. Test baseline generation and protocol path coverage verification.
[0052] Extract the set of key protocol paths from the unified protocol object model, match test benchmark samples for each key protocol path based on upstream interface evidence, establish a protocol coverage matrix that maps key protocol paths, test benchmark samples, and test cases one by one, generate and execute multiple types of test cases, and calculate protocol path coverage.
[0053] In this embodiment, the key protocol paths include six categories: request field mapping path, response field mapping path, error classification mapping path, streaming event processing path, task status synchronization path, and usage field extraction path; the test benchmark samples include request samples, response samples, error samples, streaming event samples, task submission samples, and task query samples.
[0054] Among them, generating and executing multiple types of test cases includes three categories: unit tests, simulated end-to-end tests, and replay end-to-end tests. Unit tests are used to verify the atomic mapping logic of a single critical protocol path; Simulated end-to-end testing verifies the entire protocol conversion process of the adapter by simulating the return of test baseline samples from upstream services. The end-to-end playback test verifies the adapter's compatibility with the actual upstream return structure by playing back the actual recorded upstream responses, streaming events, and task statuses.
[0055] In this embodiment, the formula for calculating protocol path coverage is: ; in, This is a set of key protocol paths that have been associated with valid test benchmarks and test cases and have independent evidence to support them. To extract the set of key protocol paths from the unified protocol object model; paths lacking test benchmarks, test cases, or sources of evidence are not included. Protocol paths marked as inapplicable after manual verification are not included. The preset threshold for protocol path coverage is 100%. The system must not proceed with the automatic deployment process if the threshold is not reached. Critical protocol paths that have been manually confirmed and marked as inapplicable are not included in the calculation. gather.
[0056] This embodiment extracts all key protocol paths from the unified protocol object model to form a set. Based on upstream interface evidence, construct test benchmark examples for each path and mark paths without evidence as pending confirmation; construct a protocol coverage matrix that maps "key protocol paths - test benchmark examples - test cases" one by one; generate and execute three types of test cases: unit tests, simulated end-to-end tests, and replay end-to-end tests; calculate the protocol path coverage rate according to the formula, and if the preset threshold is not reached, the automatic release process shall not be initiated.
[0057] S3. Controlled generation and read-only inspection of adapter iteration.
[0058] The code generation agent, which has restricted write permissions, generates adapter implementation code or change patches based on the unified protocol object model, protocol coverage matrix, and test benchmark examples. When a test fails, the repair agent determines the cause of failure in a hierarchical manner and performs automatic repair within the authorized scope. After all tests pass, the read-only review agent performs semantic compliance review and generates candidate adapter versions after reviewing for any blocking items.
[0059] In this embodiment, the scope of writing code to generate intelligent agents is strictly limited to the target adapter-related files. Modification of test files, test benchmark samples, test cases, acceptance criteria, AI gateway platform public modules, authentication modules, routing modules, log modules, release configurations, and key configurations is prohibited.
[0060] Among them, the repair agent when a test fails categorizes the reasons for failure into five types: implementation defects, specification conflicts, test benchmark conflicts, test disputes, and unknown upstream behavior. Only when an implementation defect is identified can the repair agent generate a fix patch within the target adapter file scope and automatically retest. If the defect is determined to be non-implementation type, or if the automatic repair fails after exceeding the preset maximum number of rounds, the task will be transferred to manual confirmation.
[0061] In this embodiment, the read-only review agent only has full read permissions and no write permissions. The review dimensions include: Does the adapter implementation deviate from the unified protocol object model? Does the test case contain false coverage or empty assertions? Whether to introduce upstream interface behaviors not recorded in the evidence index; Is there any unauthorized modification of unauthorized files? Should test cases be deleted or the strength of test assertions reduced? If any blocking item exists, the task will enter a failed rework or manual confirmation state, and no candidate adapter version may be generated.
[0062] In this embodiment, a code generation agent with limited write scope is invoked to generate adapter implementation code or change patches based on a unified protocol object model and testing system. When a test fails, the repair agent determines the cause of failure in a hierarchical manner. If there is an implementation defect, it is automatically repaired and retested within the permissions. If there is no implementation defect or the preset maximum automatic repair rounds are exceeded (preferably 3 rounds), it is transferred to manual confirmation. After all tests pass, a read-only review agent performs five semantic compliance reviews. If there are any blocking items, the work is reworked. If there are no blocking items, a candidate adapter version is generated.
[0063] S4. Release Admission Verification and Production Route Binding Governance. Perform multi-dimensional joint admission verification on candidate adapter versions. If the release admission judgment meets the requirements, an admitted adapter version is generated; otherwise, a default rejection policy is executed, and the adapter is not bound to any production route. Admitted adapter versions are released in a canary manner according to preset rules. During the process, operational observation data is continuously collected, and version rollback is automatically triggered when preset rollback conditions are met.
[0064] In this embodiment, the admission criteria are met if and only if the admission criteria are met. At that time, an approved adapter version is generated, and the five dimensions of the joint access verification are published as follows: The tests and verifications have passed, including at least specification verification, protocol path coverage verification, unit testing, simulated end-to-end testing, and replay end-to-end testing. Read-only review has no blocking items; The applicable interface scope and capability policy of the candidate adapter version meet the production route binding requirements; Version summary, readiness check evidence, and confirmed sample playback evidence are all complete; It complies with the platform's access control policy and gray-scale management rules.
[0065] The default rejection policy is as follows: when a production route request does not match the corresponding admitted adapter version, the platform standard error code is returned directly, without falling back to the unverified version, the default adaptation logic, or the original pass-through mode; when binding a production route, the admitted adapter version is accurately parsed according to the channel, interface range, and adapter version identifier, and if a match is not found, it does not automatically fall back to other unverified versions.
[0066] The canary release supports traffic allocation by channel, user group, token identifier, model matching rule, and routing dimension; the operation observation data includes at least the unique identifier of the request, the hit adapter version, the interface range, the error classification, and the response time; the preset rollback conditions include the error rate threshold, the timeout rate threshold, the number of readiness check failures, and the number of binding exceptions. When a rollback is triggered, it will restore to the previous stable and approved version according to the pre-registered rollback target, and record the rollback time, rollback reason, original adapter version, and target adapter version.
[0067] S5. The entire process is controlled by a deterministic process control module, which manages the task status transition, generation quality verification, and failure rework decisions. Each AI agent is restricted to performing operations within a specified range at the corresponding stage and is not allowed to change the acceptance criteria or release the version on its own.
[0068] This embodiment summarizes the full-link release evidence of candidate versions; determines the release admission result according to the five-dimensional joint verification formula; if it fails, the default rejection policy is executed and production traffic is not accessed; if the verification passes, an admitted adapter version is generated, and gray release and production routing are bound according to preset rules; during the operation, observation data is continuously collected, and version rollback is automatically triggered when the rollback conditions are met, and a full audit record is retained.
[0069] In this embodiment, the deterministic flow control module maintains a finite state machine. The task states include at least: pending specification verification, protocol model generated, test generated, test failed, test passed, pending review, review blocked, admission rejected, admitted, published, and rolled back. All state transitions are triggered only by deterministic rules, and each AI agent has no right to actively change the task state. This invention provides an AI gateway upstream adapter automatic generation, verification, and release system, including a deterministic process control module, a specification and evidence processing module, a test benchmark sample generation and coverage verification module, a candidate adapter version generation and review module, and a release admission and production route binding module.
[0070] The deterministic process control module maintains the end-to-end task state machine, manages the execution order and state transitions of each module, performs quality verification, failure rework, and manual confirmation scheduling, and restricts each AI agent to operate on designated objects only within specified stages, prohibiting them from unilaterally changing acceptance criteria or releasing candidate adapter versions. In this embodiment, the deterministic process control module achieves rigid process control through a finite state machine, while simultaneously constraining the operational permissions and boundaries of all AI agents, preventing agents from unilaterally releasing versions or modifying acceptance criteria.
[0071] In this embodiment, the core task states of the deterministic process control module include: pending specification verification, specification verification failed, pending protocol model generation, protocol model generated, pending test generation, test generated, pending code generation, test execution in progress, test failed, test passed, pending review, review blocked, review passed, pending admission, admission rejected, admitted, gray-scale release in progress, full release completed, and rollback completed. All state transitions are triggered only by deterministic rules, such as "all three types of tests passed" triggering a state transition to "pending review." The AI agent has no right to proactively initiate state changes. The deterministic process control module also carries global parameter configurations, including protocol path coverage threshold, maximum number of automatic repair rounds, gray-scale release tiered rules, rollback trigger threshold, and manual confirmation approval flow rules. All rules are globally effective and cannot be modified by the generation stage.
[0072] The specification and evidence processing module receives adapter specifications and upstream interface evidence. After performing specification verification, it extracts interface feature items and establishes an evidence index through a controlled upstream document summarization agent, generates external interface specifications and upstream call specifications, and compiles them into a unified protocol object model, serving as a unified benchmark for subsequent testing, generation, review, and release. The specification verification performed by the specification and evidence processing module includes structural verification and semantic verification. The structural verification checks the completeness and data type correctness of the required fields in the adapter specification. Required fields include adapter name, version, upstream address, request method, authentication method, capability declaration, and release constraint information. The semantic verification verifies the logical consistency between the capability declaration, upstream address, authentication method, field mapping, and upstream call specifications. If verification fails, the error reason and pending confirmation items are output, terminating the process of entering the candidate adapter version generation stage.
[0073] In this embodiment, the specification and evidence processing module is responsible for transforming fragmented upstream access information into structured, traceable protocol benchmarks, thus isolating protocol differences from intrusion into the core link at the source. The specification and evidence processing module receives two types of input: first, basic adapter specifications, including adapter name, version number, upstream service address, request method, authentication method, capability declaration, and publication constraint information; second, upstream interface evidence, covering six categories: official upstream API documentation, SDK sample code, command-line request examples, production or test environment recorded messages, existing adapter code, and manually verified samples.
[0074] In this embodiment, the specification verification of the specification and evidence processing module is divided into two levels: Structure validation: Check whether required fields are missing, whether data types are valid, and whether enumerated values are within the allowed range; Semantic validation: Validate the matching between the capability declaration and the upstream interface capability, the consistency between the authentication method and the upstream support system, and the self-consistency of the field mapping logic.
[0075] If the verification passes, a standardized specification object is output; if the verification fails, the error reason and a list of items to be confirmed are output, and the process of generating candidate versions is terminated.
[0076] After specification verification is passed, the upstream document summarization agent is invoked to extract interface features. This agent only has read permissions and no code writing or configuration modification permissions, outputting a list of interface feature items and an evidence index table. The interface features cover eight dimensions: interface address and path rules, authentication methods and parameters, request structure and field rules, response structure and field rules, error code and error format definitions, streaming event protocols and event order, asynchronous task submission and status query interfaces, and usage statistics fields and units of measurement. The evidence index table associates each feature item with a corresponding evidence source, recording the evidence ID, evidence type, evidence fragment location, and confidence level. Behaviors that cannot be confirmed from evidence and features where multiple sources of evidence conflict are uniformly marked as "pending confirmation," not included in stable specifications, and not entered into subsequent automatic release chains until manual confirmation is performed and a complete record of the confirming entity, confirmation time, confirmation reason, and corresponding protocol path is retained.
[0077] In this embodiment, the specification and evidence processing module generates a three-layer structured protocol object sequentially based on standardized specifications and evidentiary features: External Interface Specification: Defines a unified interface commitment from the AI gateway to the client, independent of specific upstream services, to ensure a consistent client access experience; Upstream Invocation Specification: Fully restore the original invocation rules of the target upstream service and record all differences in the upstream protocol; Unified Protocol Object Model: The external interface specification and the upstream call specification are bidirectionally mapped and compiled to form a unified semantic benchmark within the gateway, which is divided into six semantic domains: request mapping domain, response mapping domain, error classification domain, streaming event processing domain, task status synchronization domain, and usage field extraction domain.
[0078] The unified protocol object model is stored in a structured format. Subsequent test generation, code generation, read-only review, and release access are all strictly based on this model to ensure that upstream protocol differences only converge at the adapter layer and do not spread to the gateway core link.
[0079] The test baseline sample generation and coverage verification module is used to extract a set of key protocol paths from the unified protocol object model, generate test baseline samples based on upstream interface evidence matching, construct a protocol coverage matrix that maps key protocol paths, test baseline samples, and test cases one-to-one, generate and execute multiple types of test cases, calculate protocol path coverage, and perform coverage verification. The upstream interface evidence includes upstream official documentation, software development kit examples, command-line request examples, recorded response messages, existing adapter code, and manually confirmed examples. The upstream document summarizing agent only has read permissions and outputs a list of interface feature items and an evidence index. The evidence index records the evidence source and confidence level corresponding to each interface feature item. Interface behaviors that cannot be confirmed from upstream interface evidence, and protocol paths where evidence from multiple sources conflicts, are marked as pending confirmation items, excluded from stable specifications, and not included in the protocol coverage matrix or release access verification scope until manual confirmation is completed. The external interface specification is the unified interface commitment of the AI gateway platform to the client, and the upstream call specification is the native call rule of the target upstream service; the unified protocol object model includes six semantic domains: request domain, response domain, error domain, streaming event domain, task domain, and usage domain, which uniformly express the protocol semantics inside the AI gateway, and all downstream links are executed based on this unified protocol object model.
[0080] In this embodiment, the test benchmark sample generation and coverage verification module constructs an independent verification system based solely on upstream interface evidence, thereby decoupling test expectations from code implementation and resolving the verification distortion problem of "self-proving correctness" in AI-generated scenarios. The overall process is as follows: Figure 2 As shown. The test benchmark sample generation and coverage verification module performs the following steps: Step 1. Extraction of critical protocol paths: Traverse the six semantic domains of the unified protocol object model, decompose them into atomic-level critical protocol paths, and form a set of critical protocol paths. For example, in the error classification domain, the mapping rule from each upstream error code to the platform's unified error code is an independent critical path.
[0081] Step 2. Evidence-Driven Test Baseline Generation: For each critical protocol path, match or construct corresponding test baseline samples from upstream interface evidence. Sample types include: normal request samples, normal response samples, hierarchical error samples, streaming event sequence samples, task submission samples, task query samples, and usage statistics samples. The field values, event order, and expected results of the test baseline samples must be 100% derived from official documentation, official examples, actual recorded messages, or manual confirmation records. Paths without valid evidence support will not generate test cases with pass / fail assertions; they will only be marked as pending confirmation.
[0082] Step 3. Protocol Coverage Matrix Construction: Establish a protocol coverage matrix that maps "key protocol paths - test benchmark examples - test cases" one by one. Each row of the matrix corresponds to a protocol path, and the columns include path ID, semantic domain, path description, associated evidence ID, benchmark example ID, corresponding test case ID, coverage status, and manual confirmation record to achieve full path traceability.
[0083] Step 4. Generation and Execution of Three Types of Test Cases: Generate a three-layer test system based on the test baseline samples, and verify the adaptation logic layer by layer: (1) Unit testing: Verify the atomic mapping logic of a single protocol path, covering basic logic such as field conversion, error code mapping, and usage extraction; (2) Simulate end-to-end testing: Return test baseline samples through the Mock service to verify the adapter's protocol conversion, exception handling, and streaming output capabilities in the complete gateway link; (3) Playback end-to-end test: Play the real recorded upstream response, streaming events, and task status examples to verify the adapter's compatibility with the real upstream return structure and avoid the deviation between the Mock scenario and the real scenario.
[0084] Real upstream service calls are used only as a supplementary verification method and not as a default verification condition to avoid blocking the access process due to upstream unavailability.
[0085] Step 5. Protocol path coverage verification: The formula for calculating protocol path coverage is as follows: ; in, This is a set of key protocol paths that have been associated with valid test benchmarks and test cases and have independent evidence to support them. To extract the set of key protocol paths from the unified protocol object model; paths lacking test benchmarks, test cases, or sources of evidence are not included. Protocol paths marked as inapplicable after manual verification are not included. The preset threshold for protocol path coverage is 100%. The system must not proceed with the automatic deployment process if the threshold is not reached. Critical protocol paths that have been manually confirmed and marked as inapplicable are not included in the calculation. gather.
[0086] The candidate adapter version generation and review module is used to call a code generation agent with restricted write permissions to generate adapter implementation code or change patches based on a unified protocol object model, protocol coverage matrix, and test benchmark samples. When the test fails, the failure reason is determined by the repair agent's hierarchical classification and automatic repair is performed within the authorized scope. After the test passes, semantic compliance review is performed by a read-only review agent, and candidate adapter versions are generated after reviewing for no blocking items.
[0087] In this embodiment, the candidate adapter version generation and review module uses three types of AI agents with controlled permissions to complete adapter generation, failure repair, and compliance review within strict boundaries, ensuring that the generation process is controllable and auditable. When writing restricted code generation agents, the code generation agent is invoked, taking the unified protocol object model, protocol coverage matrix, test benchmark examples, and existing adapter interface constraints as inputs to generate adapter change patches or complete implementation files. For scenarios requiring changes to upstream calling specifications, the agent can only generate draft suggestions, which can only be registered after being verified by the deterministic process control module and manually confirmed.
[0088] The write scope of the intelligent agent is strictly limited to the target adapter's dedicated directory by the sandbox. Modification of test files, benchmark samples, test cases, and acceptance criteria is prohibited. Modification of gateway public modules, authentication modules, routing modules, logging modules, release configurations, and key configurations is also prohibited. This mechanism prevents intelligent agents from weakening verification rules to pass tests and also prevents upstream protocol differences from intruding into the core link. After generation, the system automatically retains candidate version snapshots, code difference reports, associated test results, and generates audit logs for subsequent review and access verification.
[0089] When a test fails, the repair agent is invoked to parse the failure log and categorize the reasons for failure into five types: implementation defects, specification conflicts, test benchmark conflicts, test disputes, and unknown upstream behavior. If the failure is determined to be an implementation defect, the repair agent can generate a repair patch within the target adapter file's permissions and automatically trigger a retest. If the failure is determined to be a non-implementation defect, or if the number of automatic repair attempts exceeds the preset maximum number of rounds, the task automatically transitions to manual confirmation and stops automatic iteration.
[0090] When a read-only review agent is used, after all tests pass, the read-only review agent is called to perform semantic compliance review. This agent only has full read permissions and no write permissions. Based on the unified protocol object model, protocol coverage matrix, and evidence index table, it focuses on checking five items: (1) whether the adapter implementation logic deviates from the definition of the unified protocol object model; (2) whether the test cases have false coverage, empty assertions, or weakened verification; (3) whether upstream interface behaviors not recorded in the evidence index have been introduced; (4) whether there is unauthorized modification of unauthorized files; and (5) whether there are operations such as deleting test cases or lowering acceptance standards. If any blocking item exists during the review, the reason for the blocking is recorded, and the task is transferred to failure rework or manual confirmation; if there is no blocking item, a formal candidate adapter version is generated and enters the release admission stage.
[0091] The release admission and production route binding module is used to perform multi-dimensional joint admission verification on candidate adapter versions. If the verification is successful, an admitted adapter version is generated and gray release and production route binding are performed. If the verification fails, a default rejection policy is implemented and production traffic is not accessed. At the same time, operation observation data is continuously collected, and version rollback is automatically triggered when preset rollback conditions are met, and full-link audit records are retained.
[0092] In this embodiment, the release admission and production route binding module achieves rigid control of the access boundary through multi-dimensional joint verification, a default rejection mechanism, canary release, and automatic rollback capabilities. The overall process is as follows: Figure 3 As shown. First, the release evidence is summarized. After a candidate version enters the admission stage, the module automatically summarizes the release evidence across the entire chain, including version summary, protocol version number, applicable interface scope, capability policy declaration, full test report, read-only review report, evidence index table, and rollback target version. Among these: Version Summary: Based on the adapter implementation file, upstream call specification, unified protocol object model, and protocol version number, a hash value is jointly calculated to generate a unique version fingerprint for consistency verification before release and version location in case of anomalies; Capability Policy: Declares the network permissions, file access permissions, credential access permissions, and platform capabilities that the adapter can use for permission verification when binding production routes.
[0093] Then, a five-dimensional joint release admission verification is performed. The five-dimensional joint verification is applied to the candidate adapter versions, and the release admission determination formula is as follows: ; When all five checks are true If true, generate an admitted adapter version; if any one of the conditions is not met, execute the default rejection policy and do not connect the adapter to any production route. The five checks are defined as follows: The tests and verifications have passed, including at least specification verification, protocol path coverage verification, unit testing, simulated end-to-end testing, and replay end-to-end testing. Read-only review has no blocking items; The applicable interface scope and capability policy of the candidate adapter version meet the production route binding requirements; Version summary, readiness check evidence, and confirmed sample playback evidence are all complete; It complies with the platform's access control policy and gray-scale management rules.
[0094] When binding production routes and running rules, the approved adapter versions are canary-scale bound according to channel, user group, token identifier, model matching rules, and route priority, supporting tiered volume release based on traffic ratio. During production route binding, precise parsing is performed based on channel, interface range, and version identifier. If a valid approved version is not matched, it does not fall back to an unverified version or default adaptation logic, but directly returns a platform standard error code, strictly enforcing the default rejection policy. During runtime, the AI gateway core remains responsible for client authentication, route selection, retry policies, log tracking, platform-level security control, and accounting processing; the adapter only handles upstream protocol differences, including generating upstream request plans, converting request bodies, interpreting response bodies, processing streaming events, submitting or querying tasks, extracting usage fields, and classifying error responses. Usage field extraction only generates a unified usage object and does not perform core accounting operations such as deduction, refund, or closing of accounting status. When an adapter fails the readiness check, or experiences a timeout, abnormal exit, or connection interruption during operation, the gateway will no longer forward new requests to that version. For requests that have not yet started outputting, they can be forwarded to other approved versions or a standard error can be returned according to the platform policy. For requests that have already started streaming outputting, automatic retries will not be performed to avoid duplicate output. During runtime observation and automatic rollback, after the canary release, the system continuously collects runtime observation data and generates audit logs. The data includes at least the unique identifier of the request, the version of the matching adapter, the interface range, the error classification, the response time, usage statistics, and the readiness status. Preset rollback trigger conditions include error rate thresholds, timeout rate thresholds, the number of readiness check failures, and the number of binding exceptions. When the observation data meets the rollback conditions, the system automatically triggers a rollback judgment and restores the system to the previous stable approved version according to the pre-registered rollback target version. After the rollback is executed, the rollback time, rollback reason, original version, and target version are automatically recorded to form a complete audit chain.
[0095] The release admission and production routing binding module in this embodiment can be integrated with the internal adapter repository, configuration center, and service registry, but it must retain core metadata such as protocol version, version summary, capability declaration, admission record, grayscale range, and rollback target to ensure that the governance chain is complete and traceable.
[0096] In this embodiment, the set of key protocol paths includes six categories: request field mapping path, response field mapping path, error classification mapping path, streaming event processing path, task status synchronization path, and usage field extraction path. The test benchmark samples include request samples, response samples, error samples, streaming event samples, task submission samples, and task query samples. The field values, event order, and expected results of the test benchmark samples are all derived from upstream interface evidence or manually confirmed samples.
[0097] In this embodiment, the test cases generated by the test benchmark sample generation and coverage verification module include three types: unit tests, simulated end-to-end tests, and replay end-to-end tests. The unit tests are used to verify the atomic mapping logic of a single critical protocol path; The simulated end-to-end test verifies the entire link protocol conversion process by simulating the return of test benchmark samples from upstream services. The playback end-to-end test verifies the adapter's compatibility with the actual return structure by playing real-recorded upstream responses, streaming events, and task status examples. Actual upstream service calls are used only as supplementary verification, not as the default and sole verification condition.
[0098] In this embodiment, the writing scope of the code generation agent is strictly limited to the target adapter-related files. Modification of test files, test benchmark samples, test cases, acceptance criteria, as well as the AI gateway platform's public modules, authentication modules, routing modules, log modules, release configurations, and key configurations is prohibited. For scenarios that require changes to the upstream calling specifications, the code generation agent only generates suggested changes, which can only be registered after verification by the deterministic flow control module.
[0099] In this embodiment, the repair agent classifies test failure reasons into five categories: implementation defects, specification conflicts, test benchmark conflicts, test disputes, and unknown upstream behavior. Only when the defect is determined to be an implementation defect can the repair agent generate a repair patch within the target adapter file and retest. If the defect is determined to be a non-implementation defect, or if the automatic repair fails to pass the test after exceeding the preset maximum number of rounds, the system switches to manual confirmation.
[0100] In this embodiment, the read-only review agent only has full read permissions and no write permissions. The review dimensions include: Does the adapter implementation deviate from the unified protocol object model? Does the test case contain false coverage or empty assertions? Whether to introduce upstream interface behaviors not recorded in the evidence index; Is there any unauthorized modification of unauthorized files? Should test cases be deleted or the strength of test assertions reduced? If any blocking item exists, the deterministic process control module records the reason for the blocking, the task is transferred to a failure rework or manual confirmation state, and no candidate adapter version is generated.
[0101] In this embodiment, the default rejection policy is as follows: when a production route request does not match the corresponding admitted adapter version, the platform standard error code is returned directly, without falling back to the unverified version, the default adaptation logic, or the original pass-through mode; when binding the production route, the admitted adapter version is accurately parsed according to the channel, interface range, and adapter version identifier, and if a match is not found, it does not automatically fall back to other unverified versions.
[0102] In this embodiment, the canary release supports traffic allocation by channel, user group, token identifier, model matching rule, and routing dimension; the operation observation data includes at least the unique identifier of the request, the hit adapter version, the interface range, the error classification, and the response time; the preset rollback conditions include the error rate threshold, the timeout rate threshold, the number of readiness check failures, and the number of binding exceptions. When a rollback is triggered, the system restores to the previous stable and approved version according to the pre-registered rollback target, and records the rollback time, rollback reason, original adapter version, and target adapter version.
[0103] In this embodiment, the task states maintained by the deterministic process control module include at least the following: pending specification verification, protocol model generated, test generated, test failed, test passed, pending review, review blocked, admission rejected, admitted, published, and rolled back. All state transitions are triggered only by deterministic rules, and each AI agent has no right to actively change the task state.
[0104] In this embodiment, the adapter version is only responsible for handling protocol differences of upstream services, including generating upstream request plans, transforming request bodies, interpreting response bodies, processing streaming events, submitting or querying tasks, extracting usage fields, and classifying error responses; the core of the AI gateway platform is still responsible for client authentication, routing selection, retry strategies, log tracking, platform-level security control, and billing processing. The adapter only extracts usage data and does not perform billing operations such as deduction, refund, or closing of billing status.
[0105] In summary, the AI gateway upstream adapter automatic generation, verification, and release method and system provided by this invention completely decouples client interface commitments, upstream native rules, and internal unified semantics through a three-layer architecture of external interface specifications, upstream call specifications, and a unified protocol object model. The adapter is only responsible for protocol conversion, and upstream differences will not intrude into the core logic of the gateway, avoiding the spread of dedicated adaptation code and significantly reducing the maintenance complexity and change risks of multiple upstream accesses. Test expectations are generated based solely on independent evidence such as upstream official documentation and real recorded messages, with decoupling of testing and implementation. Combined with a read-only review mechanism, the "self-verification" defect of AI generation is avoided from the root, significantly improving the consistency between adaptation logic and the real interface behavior of upstreams. Through five-dimensional joint admission verification and default rejection strategies, adapters that fail complete verification can never access production traffic. Combined with canary release and conditional automatic rollback capabilities, the risk of going live is controlled to a minimum, significantly improving the operational stability and access boundary security of the AI gateway.
[0106] The above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit the scope of protection of the invention. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on these embodiments, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art can still combine, add, delete, or otherwise adjust the features of the various embodiments of the present invention according to the circumstances without conflict or creative effort, thereby obtaining different technical solutions that do not fundamentally depart from the concept of the present invention. These technical solutions also fall within the scope of protection of the present invention.
Claims
1. A method for automatically generating verification and publishing an upstream adapter for an AI gateway, characterized in that, Includes the following steps: Receive the adapter basic specifications and upstream interface evidence. After the specifications are verified, extract interface feature items and establish evidence index through the controlled upstream document summarization agent. Generate external interface specifications and upstream call specifications respectively, and compile them into a unified protocol object model. Extract the set of key protocol paths from the unified protocol object model, match test benchmark samples for each key protocol path based on upstream interface evidence, establish a protocol coverage matrix that maps key protocol paths, test benchmark samples, and test cases one by one, generate and execute multiple types of test cases, and calculate protocol path coverage. The code generation agent, which has restricted write permissions, generates adapter implementation code or change patches based on the unified protocol object model, protocol coverage matrix, and test benchmark samples. When a test fails, the repair agent determines the cause of failure in a hierarchical manner and performs automatic repair within the authorized scope. After all tests pass, the read-only review agent performs semantic compliance review and generates candidate adapter versions after reviewing for no blocking items. Perform multi-dimensional joint admission verification on candidate adapter versions, and generate an admitted adapter version if and only if the release admission judgment meets the requirements; Otherwise, the default rejection policy will be applied, and the adapter will not be bound to any production route; The approved adapter version will be released in a grayscale according to the preset rules. During the operation, the running observation data will be continuously collected, and the version rollback will be automatically triggered when the preset rollback conditions are met. The entire process is managed by a deterministic process control module, which controls the flow of task status, generation quality verification, and failure rework decisions. This restricts each AI agent to perform operations within a specified scope at its corresponding stage and prohibits it from changing acceptance criteria or releasing versions on its own.
2. The method for automatically generating verification and publishing an AI gateway upstream adapter as described in claim 1, characterized in that, The external interface specification is the unified interface commitment of the AI gateway platform to the client; the upstream call specification is the native call rule of the target upstream service; the unified protocol object model is the unified protocol semantic benchmark within the gateway, serving as a unified basis for testing, generation, review, and release; the specification verification includes structural verification and semantic verification: structural verification is used to check the integrity of fields and the correctness of data types. Semantic validation is used to verify the logical consistency of capability declarations, upstream addresses, authentication methods, and field mappings; when validation fails, the error reason and items to be confirmed are output, and the process terminates and proceeds to the candidate adapter generation stage.
3. The method for automatically generating verification and publishing an AI gateway upstream adapter as described in claim 1, characterized in that, The upstream interface evidence includes upstream official documentation, software development kit examples, command line request examples, recorded response messages, existing adapter code, and manual confirmation examples; the evidence index records the evidence source and confidence level corresponding to each interface feature item; interface behaviors that cannot be confirmed from the upstream interface evidence are marked as items to be confirmed and are not included in the stable specification.
4. The method for automatically generating verification and publishing an AI gateway upstream adapter as described in claim 1, characterized in that, The key protocol paths include six categories: request field mapping path, response field mapping path, error classification mapping path, streaming event processing path, task status synchronization path, and usage field extraction path; the test benchmark samples include request samples, response samples, error samples, streaming event samples, task submission samples, and task query samples.
5. The method for automatically generating verification and publishing an AI gateway upstream adapter as described in claim 1, characterized in that, Generate and execute multiple types of test cases, including three categories: unit tests, simulated end-to-end tests, and replay end-to-end tests. Unit tests are used to verify the atomic mapping logic of a single critical protocol path; Simulated end-to-end testing verifies the entire protocol conversion process of the adapter by simulating the return of test baseline samples from upstream services. The replay end-to-end test verifies the adapter's compatibility with the actual upstream return structure by playing back the actual recorded upstream responses, streaming events, and task statuses.
6. The method for automatically generating verification and publishing an AI gateway upstream adapter as described in claim 5, characterized in that, The formula for calculating protocol path coverage is: ; in, This is a set of key protocol paths that have been associated with valid test benchmarks and test cases and have independent evidence to support them. To extract the set of key protocol paths from the unified protocol object model; paths lacking test benchmarks, test cases, or sources of evidence are not included. Protocol paths marked as inapplicable after manual verification are not included. The preset threshold for protocol path coverage is 100%. The system must not proceed with the automatic deployment process if the threshold is not reached. Critical protocol paths that have been manually confirmed and marked as inapplicable are not included in the calculation. gather.
7. The method for automatically generating verification and publishing an AI gateway upstream adapter as described in claim 5, characterized in that, The scope of code generation for intelligent agents is strictly limited to files related to the target adapter. Modification of test files, test benchmarks, test cases, acceptance criteria, AI gateway platform public modules, authentication modules, routing modules, logging modules, release configurations, and key configurations is prohibited. When a test fails, the repair agent categorizes the reasons for the failure into five types: implementation defects, specification conflicts, test benchmark conflicts, test disputes, and unknown upstream behavior. Only when an implementation defect is identified can the repair agent generate a fix patch within the target adapter file scope and automatically retest. If the defect is determined to be non-implementation type, or if the automatic repair fails after exceeding the preset maximum number of rounds, the task will be transferred to manual confirmation.
8. The method for automatically generating verification and publishing an AI gateway upstream adapter as described in claim 5, characterized in that, The read-only review agent has only full read permissions and no write permissions. The review dimensions include: Does the adapter implementation deviate from the unified protocol object model? Does the test case contain false coverage or empty assertions? Whether to introduce upstream interface behaviors not recorded in the evidence index; Is there any unauthorized modification of unauthorized files? Should test cases be deleted or the strength of test assertions reduced? If any blocking item exists, the task will enter a failed rework or manual confirmation state, and no candidate adapter version may be generated.
9. The method for automatically generating verification and publishing an AI gateway upstream adapter as described in claim 1, characterized in that, If and only if the issuance of the access determination meets the requirements At that time, an approved adapter version is generated, and the five dimensions of the joint access verification are published as follows: The tests and verifications have passed, including at least specification verification, protocol path coverage verification, unit testing, simulated end-to-end testing, and replay end-to-end testing. Read-only review has no blocking items; The applicable interface scope and capability policy of the candidate adapter version meet the production route binding requirements; Version summary, readiness check evidence, and confirmed sample playback evidence are all complete; It complies with the platform's access control policy and gray-scale management rules.
10. An AI gateway upstream adapter automatic generation verification and release system, characterized in that, For implementing an AI gateway upstream adapter automatic generation, verification and release method as described in any one of claims 1-9, the system includes a deterministic process control module, a specification and evidence processing module, a test benchmark sample generation and coverage verification module, a candidate adapter version generation and review module, and a release admission and production route binding module. The deterministic process control module is used to maintain the full-link task state machine, manage the execution order and state transition of each module, perform generation quality verification, failure rework and manual confirmation scheduling, restrict each AI agent to operate on the specified object only in the specified stage, and shall not change the acceptance criteria or release the candidate adapter version on its own. The specification and evidence processing module is used to receive adapter specifications and upstream interface evidence, perform specification verification, extract interface feature items through a controlled upstream document summarization agent and establish an evidence index, generate external interface specifications and upstream call specifications, and compile them into a unified protocol object model, which serves as a unified benchmark for subsequent testing, generation, review and release. The test benchmark sample generation and coverage verification module is used to extract a set of key protocol paths from the unified protocol object model, generate test benchmark samples based on upstream interface evidence matching, construct a protocol coverage matrix that maps key protocol paths, test benchmark samples, and test cases one by one, generate and execute multiple types of test cases, calculate protocol path coverage and perform coverage verification. The candidate adapter version generation and review module is used to call a code generation agent with restricted write permissions to generate adapter implementation code or change patches based on a unified protocol object model, protocol coverage matrix and test benchmark samples; when the test fails, the failure reason is determined by the repair agent level and automatic repair is performed within the authorized scope; after the test passes, semantic compliance review is performed by a read-only review agent, and candidate adapter versions are generated after reviewing no blocking items. The release admission and production route binding module is used to perform multi-dimensional joint admission verification on candidate adapter versions. If the verification is successful, an admitted adapter version is generated and canary release and production route binding are performed. If the verification fails, the default rejection policy is executed, and production traffic is not connected; at the same time, operational observation data is continuously collected, and version rollback is automatically triggered when the preset rollback conditions are met, while retaining full-link audit records.