AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

Building Custom AI Agents in Tongyi Qianwen: A Step-by-Step Guide to Instructions, Knowledge Bases, and Tool Plugins

365Finds Editorial
Indexed 11,430 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

Knowledge workers and cross-functional teams frequently encounter an efficiency bottleneck when using general-purpose artificial intelligence assistants: every new session requires pasting lengthy background prompts, tone guidelines, and corporate rules, only for the model to generate generic responses or hallucinate facts because it cannot access private internal files.

Tongyi Qianwen (powered by Alibaba Cloud's Qwen model ecosystem) addresses this problem directly through its custom agent architecture. By configuring three essential building blocks—system instructions, private knowledge bases (Retrieval-Augmented Generation, or RAG), and tool plugins—professionals can transform a generic conversational model into a persistent, domain-specific digital teammate.

Whether built through Tongyi Qianwen's web productivity interface or scaled via Alibaba Cloud Model Studio (Bailian), a well-designed custom agent retains memory of organizational requirements, grounds its answers in verified enterprise documents, and takes direct actions using live external tools.


The Three Core Pillars of a Tongyi Qianwen Custom Agent

A custom agent is more than a saved prompt; it is an integrated system where reasoning, proprietary memory, and dynamic actions work together seamlessly.

+-------------------------------------------------------------------+
|                     User Query / Task Trigger                    |
+---------------------------------+---------------------------------+
                                  |
                                  v
+-------------------------------------------------------------------+
|                  Tongyi Qianwen Agent Core (Qwen)                 |
|                                                                   |
|  +--------------------+  +--------------------+  +--------------+  |
|  | System Instruction |  | Knowledge Base RAG |  | Tool Plugins |  |
|  | Persona & Rules    |  | Private Docs & Data|  | APIs & Search|  |
|  +--------------------+  +--------------------+  +--------------+  |
+---------------------------------+---------------------------------+
                                  |
                                  v
+-------------------------------------------------------------------+
|           Grounded, Formatted, and Actionable Output             |
+-------------------------------------------------------------------+

1. System Instructions: The Behavioral Foundation

The system instruction (or system prompt) dictates identity, tone, task boundaries, and execution rules. Without clear instructions, models default to generic conversational patterns.

A production-ready instruction must specify:

2. Knowledge Bases: Private Document Retrieval via RAG

Large language models possess broad public knowledge but have no visibility into private product roadmaps, vendor contracts, or internal standard operating procedures (SOPs).

Attaching a knowledge base leverages Retrieval-Augmented Generation (RAG):

3. Tool Plugins: Giving the Agent Hands and Eyes

While text models reason and write, plugins enable interaction with external systems:


Architectural Comparison: General Chat vs. Custom Agent

DimensionStandard Chat SessionCustom Tongyi Qianwen Agent
Context RetentionVanishes after session ends; requires manual re-promptingPermanently stored in agent profile; reusable across teams
Access to Private DataLimited to manual file attachments per conversationConnected to centralized, indexable vector knowledge bases
Real-Time Tool ActionsText-only generation or default broad searchDeterministic tool calling via APIs, Python sandboxes, and MCP
Output ReliabilityVulnerable to generic reasoning and factual driftConstrained by strict guardrails and document-level citations
Team CollaborationFragmented across individual personal chat logsSharable via workspace permissions, links, or enterprise apps

Step-by-Step Guide: Creating a Custom Agent

Step 1: Initialize the Agent and Select the Foundation Model

  1. Access the agent creation interface via Tongyi Qianwen or the Alibaba Cloud Model Studio application management dashboard.
  2. Click Create Agent (or Create Application).
  3. Set your agent identity:
    • Name: Choose a functional title (such as IT Support Analyst or SaaS RFP Specialist).
    • Description: Provide a summary so teammates understand its purpose.
    • Avatar: Select an icon reflecting the agent's function.
  4. Choose the Model Engine:
    • Qwen-Max: Recommended for complex multi-step reasoning, intricate tool orchestration, and high-stakes document synthesis.
    • Qwen-Plus: An ideal balance of latency and cost efficiency for daily corporate office drafting, customer service, and standard FAQ lookups.
    • Qwen-Long: Optimized for processing massive context windows and scanning through extensive documentation archives.

Step 2: Formulate Production-Grade System Instructions

In the system prompt editor, avoid single-sentence requests. Use a structured template that clarifies the agent's operational logic:

# Role
You are the Senior Technical Sales Enablement Assistant for our cloud solutions division. Your primary goal is to help our enterprise sales representatives prepare accurate, technically sound RFP responses.

# Capabilities & Tools
1. You have direct access to our verified Product Whitepapers and Security Compliance Knowledge Base.
2. You can invoke Web Search to confirm public competitor specifications when requested.

# Operating Rules
- Source Grounding: Always query the Knowledge Base before answering product capability questions. Cite the document title and section when referencing specifications.
- Strict Honesty: If a requested feature or compliance certification is not explicitly documented in the knowledge base, state clearly: "This capability is not documented in our verified internal repository." Do not guess or extrapolate.
- Tone: Professional, precise, and concise. Avoid conversational filler.
- Output Format: Provide answers in structured bullet points, followed by a summary comparison table when comparing multiple product tiers.

Step 3: Configure and Attach Private Knowledge Bases

  1. Navigate to the Knowledge Base section within the agent configuration console.
  2. Select Add Knowledge Base and upload your private operational files. Tongyi supports formats including .pdf, .docx, .txt, .md, and .csv.
  3. Configure indexing and parsing settings:
    • Chunking Strategy: Choose standard semantic chunking for narrative guides and whitepapers. For structured data like product tables or FAQs, ensure distinct delimiters.
    • Retrieval Threshold: Adjust the similarity score threshold and top-k recall parameter to ensure only relevant document chunks enter the prompt window.
  4. Set explicit instructions in your prompt dictating how the agent handles retrieved knowledge (e.g., instructing it to cite document titles or quote exact figures).

Step 4: Configure Native Plugins and Custom Tool APIs

  1. Under the Tools & Plugins configuration tab, enable native capabilities required for the agent's workflow:
    • Web Search: Essential for queries involving dynamic market indices, software version changes, or competitor releases.
    • Code Interpreter (Python Sandbox): Necessary if the agent needs to parse uploaded spreadsheets, perform financial calculations, or generate statistical charts.
  2. Add Custom API Plugins (Optional):
    • Click Create Custom Plugin or Add Tool.
    • Input your service endpoint URL and authentication method (e.g., Bearer Token or Header API Key).
    • Define tool metadata: provide a clear, semantic description of the API's purpose and parameter schemas. The Qwen model uses these descriptions to determine when and how to execute function calls.
    • Run a test call in the configuration console to verify that returned JSON payloads match the expected schema.

Step 5: Test and Debug in the Interactive Playground

Before publishing, evaluate the agent using the side-by-side preview panel:

Step 6: Publish, Share, and Maintain

  1. Click Publish.
  2. Determine sharing permissions:
    • Private: Visible only to the creator for personal productivity.
    • Team / Organization Workspace: Shared across team members within your organization.
    • Public / Shared Link: Accessible via a web link for external stakeholders.
  3. For programmatic and omnichannel deployment, use the generated App ID and DashScope SDK to embed the agent into enterprise communication tools (such as DingTalk), intranet portals, or customer-facing web widgets.

Three Real-World Workplace Agent Blueprints

Blueprint 1: Enterprise RFP & Compliance Reviewer

Blueprint 2: Financial Operations Analyst

Blueprint 3: Brand Marketing & Campaign Strategist


Best Practices and Common Pitfalls

  1. Clean Your Documents Before Uploading: Raw PDF scans with messy OCR, complex merged tables, or watermarked headers degrade semantic chunking. Convert tabular data into clean Markdown tables or CSVs to ensure high retrieval fidelity.
  2. Avoid Vague Tool Descriptions: When defining custom API plugins, provide explicit natural language descriptions for every parameter. If an API expects an ISO date format (YYYY-MM-DD), state it directly in the parameter description so the model passes valid payloads.
  3. Establish Clear Fallback Behaviors: Always instruct the agent what to do when information cannot be found. A response stating "I cannot find documentation regarding this policy in our database" is far more valuable in an enterprise context than an eloquent hallucination.
  4. Implement Continuous Knowledge Lifecycle Management: Outdated documents lead to outdated answers. Assign an owner to refresh files within the agent's knowledge base whenever product pricing, policies, or workflows are updated.

References