Build a Chat & Poetry Creation Agent with Qwen3 and Alipay MCP Using Tongyi Lingma
This guide walks through installing Tongyi Lingma, generating a Qwen3‑based conversational and poetry‑creation agent with Chainlit, integrating Alipay MCP for payment requests, troubleshooting common issues, and providing useful resource links for a complete AI‑agent development workflow.
Prerequisites
Tongyi Lingma version 2.5 or higher installed
Ollama installed
Alipay MCP configuration completed (environment variables AP_APP_ID, AP_APP_KEY, AP_PUB_KEY)
Step 1 Generate the agent code
In an IDE (e.g., PyCharm) open the Tongyi Lingma panel, select the “Intelligent Conversation” mode, choose the qwen3‑coder model and provide a prompt that describes the required capabilities: daily chat, poetry creation, and payment request. The model references the Qwen‑Agent implementation, adapts it to the Chainlit framework and creates a Python project (e.g., tongyi_lm_demo_06).
Reference: https://github.com/QwenLM/Qwen-Agent
Prompt (Chinese):
“你是一个智能陪伴和创作助手,可以进行日常聊天和诗词创作,会使用温暖热情的语气与用户交流。实现的功能包括:
1、日常聊天:回答问题、进行对话;
2、诗词创作:根据用户给定的主题创作诗词,并提供简短解释。”Step 2 Run and test
Activate the virtual environment and launch Chainlit: .venv/bin/chainlit run app.py -w The web UI appears; interact with the agent to verify chat and poetry functions.
Step 3 Add Alipay MCP payment
Extend the system prompt to include a payment request after delivering poetry. The agent should call the tool create-web-page-alipay-payment to generate a payment link (amount 0.01‑0.03 CNY) and a random order ID based on the current timestamp. After the user confirms payment, the agent calls query-alipay-payment to check the status and respond accordingly.
Prompt addition (Chinese):
“3. 请求打赏:在提供诗词创作内容后,调用工具 create-web-page-alipay-payment 生成网页支付链接,金额在 0.01‑0.03 元之间,订单号根据当前时间戳随机生成,订单标题根据上下文生成,并向用户展示订单号、金额和支付链接。
4. 表达感谢:如果用户已打赏或已支付,调用工具 query-alipay-payment 查询订单状态;若已完成支付,输出至少三句夸奖;若未完成,提醒用户完成支付。
注意:每次都必须真实调用工具,禁止自行 mock。”MCP server configuration (JSON‑like snippet):
{
"alipay-server": {
"command": "npx",
"args": ["-y", "@alipay/mcp-server-alipay"],
"env": {
"AP_APP_ID": "${AP_APP_ID}",
"AP_APP_KEY": "${AP_APP_KEY}",
"AP_PUB_KEY": "${AP_PUB_KEY}"
}
}
}Troubleshooting
If the agent prints duplicated output, modify typewriter_print in output_beautify.py (see https://github.com/QwenLM/Qwen-Agent/blob/main/qwen_agent/utils/output_beautify.py) to emulate printer‑style non‑repeating text.
Appending /no_think to message.content suppresses the model’s internal “thinking” and speeds up responses.
When tool invocation format is incorrect, follow the example in assistant_mcp_sqlite_bot.py (see https://github.com/QwenLM/Qwen-Agent/blob/main/examples/assistant_mcp_sqlite_bot.py).
Ensure the tool’s return value is printed (use the adjusted typewriter_print) so the payment link appears complete.
Generate unique order IDs by adding a timestamp‑based random string utility.
Optional enhancements
After a successful payment, call query-alipay-payment to confirm the transaction and display a thank‑you message.
Reference resources
Qwen‑Agent repository: https://github.com/QwenLM/Qwen-Agent
Chainlit documentation (for running the UI)
Alipay Open API reference: https://opendocs.alipay.com/open/0h3he5?pathHash=87d45
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.
Alibaba Cloud Native
We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.
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.
