How to Use RAG Tool Calls in FastGPT for Real-Time Train Ticket Queries
This article walks through integrating RAG‑based tool calling into a FastGPT workflow to enable AI‑driven customer service that can fetch real‑time train ticket information by invoking external APIs, configuring HTTP nodes, and handling parameters step by step.
In AI customer service, tool calling becomes a fundamental node for handling queries that require up‑to‑date data rather than static FAQs. By letting a large language model (LLM) invoke external APIs, the system can both answer and perform actions, greatly improving automation and closed‑loop processing.
The example focuses on a travel scenario where users ask for train tickets. The workflow adds a tool‑calling node to FastGPT, enabling the AI to request real‑time data from the 同程旅行 (Ly.com) platform.
Workflow overview
The existing FastGPT flow already performs question classification, coreference resolution, and a second round of classification that can serve as intent detection. Three product lines—train tickets, attractions, and membership—are integrated. The new goal is to let users provide departure city, destination city, and travel date, and receive relevant train information.
Requirement analysis
By inspecting the Ly.com train ticket page, the author identifies two key API endpoints:
GET station codes: https://www.ly.com/trainbffapi/getCodeByStationName Search trains: https://www.ly.com/trainsearchbffapi/trainSearch First, a request to getCodeByStationName returns station codes (e.g., {"code":200,"data":["BJP","SHH"]}). Then a second request to trainSearch with those codes and the travel date returns a list of train details.
Tool definition
tools = [{
"type": "function",
"name": "send_email",
"description": "向指定收件人发送包含主题和内容的邮件。",
"parameters": {
"type": "object",
"properties": {
"to": {"type": "string", "description": "收件人邮箱地址"},
"subject": {"type": "string", "description": "邮件主题"},
"body": {"type": "string", "description": "邮件正文内容"}
},
"required": ["to", "subject", "body"],
"additionalProperties": false
}
}]When the LLM decides a tool is needed, it returns a function‑call message such as:
[{
"type": "function_call",
"id": "fc_1xxxxxxx",
"call_id": "call_xxxxxx",
"name": "send_email",
"arguments": "{\"to\":\"[email protected]\",\"subject\":\"你好!\",\"body\":\"只想说声嗨~\"}"
}]Workflow configuration
Add a tool‑calling node to the FastGPT flow.
Link the second classification/intention node to the tool‑calling node, enabling the AI to request external data.
Define the prompt for the AI, specifying its role as a professional travel assistant and listing three tools: a train‑ticket FAQ, a real‑time train‑ticket query, and a system‑time query.
Insert a custom variable node to capture the three parameters (startCity, arrCity, startDate) that the AI will supply.
Create an HTTP node that POSTs to https://www.ly.com/trainbffapi/getCodeByStationName with JSON {"names":["${startCity}","${arrCity}"],"pid":1}. Use JSONPath to extract the first and second elements of the returned data array as the departure and destination codes.
Add a second HTTP node that POSTs to https://www.ly.com/trainsearchbffapi/trainSearch with the extracted codes, the travel date, and a traceId. The response’s trains list contains the full schedule and seat availability.
Testing shows the AI first asks for missing information (e.g., travel date), then calls the system‑time tool, followed by the train‑search tool, and finally returns structured train data such as departure/arrival times, seat classes, and pricing.
During testing, the author notes occasional response variations, highlighting the need for further RAG tuning.
Conclusion
The FastGPT workflow with tool calling demonstrates how AI agents can autonomously decide which external services to invoke, effectively turning the train‑ticket query sub‑flow into an AI Agent “brain.” Adding more tools will further enhance capability.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Ubiquitous Tech
A ubiquitous public account for pirate enthusiasts, regularly sharing curated experiences, tech learning, and growth insights. Currently publishing articles on AI RAG customer service, AI MCP technology, and open-source design. Personal free Knowledge Planet: Awakening New World Programmer.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
