When building advanced AI applications, real-time networked search is a key feature for synchronizing information. However, using the platform's official search plugin directly may run into network limitations or high API fees.
This paper offers a cost-effective alternative: by Dify
's HTTP request functionality, combined with the Tencent MetaWare platform, to build a privatized, free, networked search tool. This approach not only bypasses dependency restrictions, but also allows you to Agent
Strong access to real-time information.Dify
is an open source LLMOps platform designed to help developers rapidly build and operate AI applications based on large language models.
Architecture Analysis
The principle of this scheme can be understood as a "service broker".
We use Tencent MetaWare as a provider of external search services. Tencent MetaWare is an AI application development platform that can encapsulate complex search logic into a standard API interface through its workflow feature.
afterwards Dify
in which the HTTP request node is used as a client to invoke this interface. Eventually, publish the entire HTTP call flow as a Dify
tool so that it can be used by any Agent
or workflow modularly invoked.
The advantages of the architecture are clear:
- decoupled: Implementation of search services with
Dify
The application logic is separated to facilitate independent maintenance and upgrades. - cost control: Leverage the resources of a free platform to achieve zero API cost.
- privatization: The tools are built and controlled by yourself, with clear data links and higher security.
What do I need to prepare?
Before you begin, please prepare the following environment and credentials:
- Tencent Yuanqi Platform Access: Register and Login at
https://yuanqi.tencent.com/
The - Dify Operating Environment: Either the Community Edition or the Cloud Service Edition is available.
- Large Model API Key (optional): Tencent MetaWare's workflows use its built-in model by default, but some advanced features or custom configurations may require the user to provide their own model API Key (such as the
DeepSeek
etc.). They are not covered in this basic search tutorial and can be left unprepared for now.
Action steps: from service build to tool integration
Follow the steps below to complete the entire build process in stages.
Stage 1: Build and Publish Search Service in Tencent MetaWare
- Creating Workflows
Login to Tencent MetaWare, create a new Intelligence, and select "Workflow" as the creation mode.
- Add Search Plugin
In the workflow canvas, find and add the official "Search" plugin from the plugin library on the left.
- Configuration parameters
Configure the plugin's input parameters to ensure that it receives external incoming query variables (Query).
- Test and Release
Perform a trial run in the workflow interface to verify that the search function is working correctly. After verifying that there are no errors, publish the workflow and associate it to the smart body, and finally publish the smart body.
- Getting API Credentials
Go to the Intelligent Body management page, find the "Interface Call" section in "Publishing Information", and get the URL of the API,Authorization
and the Headers information required for signing. These are the information needed to connect theDify
with the key to the meta-artifacts.
Stage 2: Creating and Wrapping HTTP Tools in Dify
- Initializing a workflow
existDify
in a file, create a file containing the Start -> HTTP Request -> End node's workflow.
- Configuring the HTTP Request Node
This is the core aspect of integration.- Method:
POST
- Request URL: Fill in the API URL obtained from Tencent MetaTool.
- Headers: Accurately fill in all authentication headers obtained from the meta ware, such as
Authorization
,X-TC-Timestamp
etc. - Body: Select
raw-text
The format isapplication/json
and construct the request body as{"query": "{{query}}"}
. Here.{{query}}
beDify
The variable placeholders for the
- Method:
- unit test
Within the HTTP node, use the "Run This Step" function to enter a test query to verify that the interface is able to return thestatus 200
of the success status code. - Publish as a tool
Once validated, save and publish the workflow. The most critical step is to click on "Publish as Tool" in the upper right corner and give it a clear name, such asInternal_Search_Engine
The
Stage 3: Validating the tool in the Agent
- Creating a Test Agent
Create a newAgent
The application is used for testing. - loading tool
existAgent
in the "Tools" configuration item, add the just createdInternal_Search_Engine
Tools. - End-to-end testing
In the Debug and Preview screen, send a message to theAgent
Ask a question that requires real-time information. Observe whether it is able to call the tool correctly and generate an answer using the returned search results.
Troubleshooting and Optimization
- commonly seen
400 Bad Request
incorrect
This issue is usually a construction error in the HTTP request. Please focus on checking this:Headers
whether the authentication information in it is complete and error-free, in particularAuthorization
and timestamp related fields. Note that some signature credentials are time-sensitive, so you can try to regenerate them if the call fails.Body
The JSON formatting in theContent-Type
Is the header set toapplication/json
The
- performance optimization
Tencent MetaWare's search plugin supportlimit
parameter, which allows you to control the number of results returned (default is 10). You can set this parameter to a variable in the meta ware workflow as well, and then set it in theDify
is dynamically passed into the HTTP request body to adjust the information density according to different scenarios and optimize the processing efficiency.