DEV Community

tunan666
tunan666

Posted on

Building Multi-Agent AI Systems with CrewAI and Chinese LLMs

Building Multi-Agent AI Systems with CrewAI and Chinese LLMs

How to build powerful agentic workflows using CrewAI with DeepSeek, Qwen, and GLM via TunanAPI

Introduction

CrewAI is rapidly becoming the go-to framework for building multi-agent AI systems. Instead of single-LLM chatbots, CrewAI lets you orchestrate multiple specialized agents that collaborate to solve complex tasks.

But here's the problem: running CrewAI with GPT-4 or Claude gets expensive fast. A single agent task might cost $0.50-2.00 in API calls. Multiply by multiple agents, and you're looking at $10-50 per workflow.

The solution? Chinese AI models via TunanAPI. DeepSeek V4 Pro, Qwen 3.7-Max, and GLM-4-Plus offer comparable performance at 8-50x lower cost.

In this guide, I'll show you how to build production-ready multi-agent systems with CrewAI + TunanAPI.

What is CrewAI?

CrewAI is a framework for building AI agent crews — groups of agents that work together to accomplish tasks. Each agent has:

  • Role: A specific job (e.g., "Researcher", "Writer", "Coder")
  • Goal: What the agent is trying to achieve
  • Backstory: Context that shapes the agent's behavior

Agents communicate and delegate tasks to each other, creating sophisticated workflows without hard-coded logic.

Prerequisites

  • Python 3.9+
  • TunanAPI account (get your API key at https://tunanapi.com)
  • Basic understanding of AI agents

Installation

\bash
pip install crewai crewai-tools langchain-openai python-dotenv
\
\

Project Setup

Create a .env file:

\bash
TUNAN_API_KEY=your-api-key-here
\
\

Building a Research & Writing Crew

Let's build a crew that researches a topic and writes an article about it:

\`python
import os
from crewai import Agent, Task, Crew
from langchain_openai import ChatOpenAI
from dotenv import load_dotenv

load_dotenv()

Configure TunanAPI as the LLM

llm = ChatOpenAI(
base_url="https://api.tunanapi.com/v1",
api_key=os.getenv("TUNAN_API_KEY"),
model="deepseek-chat",
temperature=0.7
)

DeepSeek Reasoner for complex analysis

reasoner_llm = ChatOpenAI(
base_url="https://api.tunanapi.com/v1",
api_key=os.getenv("TUNAN_API_KEY"),
model="deepseek-reasoner",
temperature=0.3
)

Agent 1: Research Specialist

researcher = Agent(
role="Research Specialist",
goal="Find comprehensive information about the given topic",
backstory="You are an expert researcher with years of experience "
"gathering and analyzing information from various sources.",
llm=reasoner_llm,
verbose=True
)

Agent 2: Content Writer

writer = Agent(
role="Content Writer",
goal="Write engaging, well-structured content based on research",
backstory="You are a professional content writer known for creating "
"clear, engaging articles that readers love.",
llm=llm,
verbose=True
)

Agent 3: Editor

editor = Agent(
role="Editor",
goal="Review and polish content to publication quality",
backstory="You are a meticulous editor with an eye for detail. "
"You ensure all content is accurate, engaging, and error-free.",
llm=llm,
verbose=True
)

Define Tasks

research_task = Task(
description="Research the latest developments in {topic}. "
"Include key players, trends, and future predictions.",
agent=researcher,
expected_output="A comprehensive research summary with bullet points"
)

writing_task = Task(
description="Write a 500-word article about {topic} based on the research. "
"Make it engaging and informative.",
agent=writer,
expected_output="A well-structured article with introduction, body, and conclusion"
)

editing_task = Task(
description="Review the article and make it publication-ready. "
"Check for grammar, clarity, and flow.",
agent=editor,
expected_output="Final polished article ready for publication"
)

Create and run the crew

crew = Crew(
agents=[researcher, writer, editor],
tasks=[research_task, writing_task, editing_task],
verbose=2
)

result = crew.kickoff(inputs={"topic": "AI agents in healthcare"})
print(result)
`\

Building a Code Review Crew

Here's a more practical example — a code review crew:

\`python
from crewai import Agent, Task, Crew
from langchain_openai import ChatOpenAI
import os

llm = ChatOpenAI(
base_url="https://api.tunanapi.com/v1",
api_key=os.getenv("TUNAN_API_KEY"),
model="qwen3.7-max", # Qwen excels at code tasks
temperature=0.1
)

Code Analyzer

analyzer = Agent(
role="Code Analyzer",
goal="Understand and document the codebase",
backstory="Senior software engineer with 15 years of experience. "
"Expert in multiple programming languages and architectures.",
llm=llm
)

Bug Hunter

bug_hunter = Agent(
role="Bug Hunter",
goal="Find potential bugs and security vulnerabilities",
backstory="Security researcher and QA engineer. "
"Found vulnerabilities in major open source projects.",
llm=llm
)

Performance Expert

perf_expert = Agent(
role="Performance Expert",
goal="Identify optimization opportunities",
backstory="Systems architect specializing in high-performance computing. "
"Expert in profiling and optimization techniques.",
llm=llm
)

Review Task

code_review = Task(
description="Review the following code for quality, bugs, and performance:\n\n"
"{code_snippet}",
agent=analyzer,
expected_output="Detailed code review report"
)

Analyze Task

bug_analysis = Task(
description="Analyze the code for potential bugs and security issues:\n\n"
"{code_snippet}",
agent=bug_hunter,
expected_output="Bug and security report with severity levels"
)

Optimize Task

optimization = Task(
description="Suggest performance optimizations:\n\n"
"{code_snippet}",
agent=perf_expert,
expected_output="Optimization suggestions with expected impact"
)

crew = Crew(
agents=[analyzer, bug_hunter, perf_expert],
tasks=[code_review, bug_analysis, optimization],
process="parallel" # Run tasks in parallel
)

result = crew.kickoff(inputs={
"code_snippet": "def fibonacci(n): return fibonacci(n-1) + fibonacci(n-2) if n > 1 else n"
})
`\

Using GLM-4-Plus for Multilingual Crews

For multilingual tasks, GLM-4-Plus excels:

\`python
multilingual_llm = ChatOpenAI(
base_url="https://api.tunanapi.com/v1",
api_key=os.getenv("TUNAN_API_KEY"),
model="glm-4-plus",
temperature=0.7
)

Translation Agent

translator = Agent(
role="Professional Translator",
goal="Translate content while preserving meaning and tone",
backstory="Bilingual translator specializing in technical content. "
"Native-level fluency in multiple languages.",
llm=multilingual_llm
)

Cultural Adapter

adapter = Agent(
role="Cultural Adapter",
goal="Adapt content for the target audience",
backstory="Cross-cultural communication expert. "
"Helps localize content for different markets.",
llm=multilingual_llm
)
`\

Cost Comparison

Configuration Cost per 1M tokens 10 tasks (avg)
GPT-4o Crew $12.50 $25-50
Claude Sonnet Crew $6.00 $12-24
DeepSeek Crew $3.28 $6-13
Qwen 3.7-Max Crew $3.78 $7-15

CrewAI + TunanAPI saves 50-75% on multi-agent workflows.

Best Practices

1. Choose the Right Model per Agent

\`python

Use specialized models for specialized tasks

reasoning_llm = ChatOpenAI(
base_url="https://api.tunanapi.com/v1",
api_key=api_key,
model="deepseek-reasoner" # Best for analysis
)

creative_llm = ChatOpenAI(
base_url="https://api.tunanapi.com/v1",
api_key=api_key,
model="qwen3.7-plus" # Great for generation
)

code_llm = ChatOpenAI(
base_url="https://api.tunanapi.com/v1",
api_key=api_key,
model="qwen3.7-max" # Strong code understanding
)
`\

2. Set Clear Task Descriptions

Vague tasks = vague results. Be specific:

\`python

Bad

Task(description="Review the code")

Good

Task(
description="Review the Python code for: "
"1. Security vulnerabilities (SQL injection, XSS, etc.) "
"2. Performance bottlenecks "
"3. Code smell and maintainability issues "
"4. Compliance with PEP 8",
expected_output="Structured report with severity levels"
)
`\

3. Enable Verbose Mode for Debugging

\python
crew = Crew(
agents=[agent1, agent2],
tasks=[task1, task2],
verbose=True # See agent thoughts and actions
)
\
\

Real-World Use Cases

Customer Support Automation

\`python

Tiered support crew

triage = Agent(role="Triage Agent", goal="Route tickets correctly", llm=llm)
billing = Agent(role="Billing Specialist", goal="Resolve billing issues", llm=llm)
tech = Agent(role="Technical Support", goal="Solve technical problems", llm=llm)
`\

Market Research Pipeline

\`python

Research crew

scout = Agent(role="Data Scout", goal="Gather market data", llm=reasoner_llm)
analyst = Agent(role="Market Analyst", goal="Analyze trends", llm=reasoner_llm)
reporter = Agent(role="Report Writer", goal="Create insights report", llm=llm)
`\

Conclusion

CrewAI + TunanAPI gives you:

  • ✅ Production-ready multi-agent workflows
  • ✅ 8 Chinese AI models for different tasks
  • ✅ 50-75% cost savings vs. Western alternatives
  • ✅ Native multilingual support
  • ✅ Easy OpenAI SDK integration

Start building today: https://tunanapi.com

Resources


Published: July 2, 2026 | For TunanAPI V2.1+

Top comments (0)