Why a Single AI Falls Short: Building a Multi‑Agent Expert Team for Superior Reports

The article demonstrates how a monolithic LLM struggles with multi‑dimensional market analysis and shows, through step‑by‑step code, how assembling specialized AI agents for news, technical and financial analysis yields clearer structure, deeper insight, and higher evaluation scores.

Data STUDIO
Data STUDIO
Data STUDIO
Why a Single AI Falls Short: Building a Multi‑Agent Expert Team for Superior Reports

Imagine being asked to produce a comprehensive market analysis for a hot company like NVIDIA, covering news sentiment, technical trends, and financial performance. The author contrasts two approaches: a single "jack‑of‑all‑trades" AI versus a team of specialized AI agents.

What Is a Multi‑Agent System?

A multi‑agent system (MAS) breaks a complex task into subtasks handled by multiple AI agents, each with a predefined expertise (e.g., news analyst, technical analyst, financial analyst). A "commander" or user issues the high‑level request, the system assigns roles, agents execute in parallel or sequentially, and a "composer" agent synthesizes the final report.

How It Works

Task Decomposition : The user provides a request such as “Create a market analysis report for NVIDIA.”

Role Assignment : The system maps the request to expert roles (news, technical, finance).

Collaborative Execution : Each expert agent works on its slice, possibly exchanging information.

Result Synthesis : A final‑report agent merges the outputs into a coherent document.

Strengths

Professional depth – each agent can be optimized for its domain.

Modular extensibility – add a new expert by plugging in another agent.

Parallel processing – reduces overall latency.

Limitations

Increased coordination complexity.

Higher API cost and longer runtime due to multiple LLM calls.

Hands‑On Demo: From a Solo Agent to an Expert Team

The author walks through four stages using LangChain, LangGraph, and Nebius APIs.

Stage 0 – Preparation

# Install dependencies
# !pip install -q -U langchain-nebius langchain langgraph rich python-dotenv langchain-tavily
import os
from typing import List, Annotated, TypedDict, Optional
from dotenv import load_dotenv
from langchain_nebius import ChatNebius
from langchain_tavily import TavilySearch
from langchain_core.messages import BaseMessage, SystemMessage, HumanMessage
from pydantic import BaseModel, Field
from langchain_core.prompts import ChatPromptTemplate
from langgraph.graph import StateGraph, END
from langgraph.graph.message import AnyMessage, add_messages
from langgraph.prebuilt import ToolNode, tools_condition
from rich.console import Console
from rich.markdown import Markdown
load_dotenv()
os.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGCHAIN_PROJECT"] = "Agentic Architecture - Multi-Agent (Nebius)"
for key in ["NEBIUS_API_KEY", "LANGCHAIN_API_KEY", "TAVILY_API_KEY"]:
    if not os.environ.get(key):
        print(f"⚠️ Missing {key}, check .env")
    else:
        print(f"✅ {key} loaded")
console = Console()
print("
🚀 Environment ready!")

Stage 1 – Baseline: A Monolithic Agent

A single agent equipped with a web‑search tool attempts the full task. The code defines a shared AgentState, a tool, and a ReAct‑style graph that either calls the tool or returns a response.

class AgentState(TypedDict):
    messages: Annotated[list[AnyMessage], add_messages]
search_tool = TavilySearch(max_results=3, name="web_search")
llm = ChatNebius(model="meta-llama/Meta-Llama-3.1-8B-Instruct", temperature=0)
llm_with_tools = llm.bind_tools([search_tool])

def monolithic_agent_node(state: AgentState):
    console.print("--- 🤔 Single agent thinking ... ---")
    response = llm_with_tools.invoke(state["messages"])
    return {"messages": [response]}

# Build ReAct graph
tool_node = ToolNode([search_tool])
mono_graph_builder = StateGraph(AgentState)
mono_graph_builder.add_node("agent", monolithic_agent_node)
mono_graph_builder.add_node("tools", tool_node)
mono_graph_builder.set_entry_point("agent")
mono_graph_builder.add_conditional_edges(
    "agent", tools_condition, {"tools": "tools", "__end__": END}
)
mono_graph_builder.add_edge("tools", "agent")
monolithic_agent_app = mono_graph_builder.compile()
print("✅ Single 'jack‑of‑all‑trades' agent compiled.")

The author runs the agent on the query:

company = "英伟达 (NVIDIA, NVDA)"
monolithic_query = f"为 {company} 创建一份简洁但全面的市场分析报告。报告应包含三个部分:1. 近期新闻和市场情绪摘要。2. 对该股价格趋势的基础技术分析。3. 审视公司近期的财务表现。"
final_mono_output = monolithic_agent_app.invoke({
    "messages": [
        SystemMessage(content="你是一位资深的单一金融分析师。你必须创建一份全面的报告,涵盖用户请求的所有方面。"),
        HumanMessage(content=monolithic_query)
    ]
})
console.print("
--- [bold red]单一智能体最终报告[/bold red] ---")
console.print(Markdown(final_mono_output['messages'][-1].content))

The resulting report is usable but suffers from three hard‑coded flaws: vague structure, shallow analysis, and a generic tone.

Stage 2 – Building an AI Expert Team

The author defines a MultiAgentState to hold each specialist’s output and creates a factory function create_specialist_node that builds a node with a persona‑specific system prompt.

class MultiAgentState(TypedDict):
    user_request: str
    news_report: Optional[str]
    technical_report: Optional[str]
    financial_report: Optional[str]
    final_report: Optional[str]

def create_specialist_node(persona: str, output_key: str):
    """Factory to quickly create a specialist agent node."""
    system_prompt = persona + "

你可以使用网络搜索工具。你的输出必须是一份简洁的报告章节,使用 markdown 格式,并且只关注你自己的专业领域。"
    prompt_template = ChatPromptTemplate.from_messages([
        ("system", system_prompt),
        ("human", "{user_request}")
    ])
    agent = prompt_template | llm_with_tools
    def specialist_node(state: MultiAgentState):
        console.print(f"--- 📊 调用 {output_key.replace('_report','').upper()} 分析师 ---")
        result = agent.invoke({"user_request": state["user_request"]})
        content = result.content if result.content else f"无直接内容,工具调用: {result.tool_calls}"
        return {output_key: content}
    return specialist_node

news_analyst_node = create_specialist_node(
    "你是一位资深的新闻分析师。你的专长是搜索网络,寻找关于一家公司的最新新闻、文章和社交媒体情绪。",
    "news_report"
)
technical_analyst_node = create_specialist_node(
    "你是一位资深的技术分析师。你专门分析股票价格图表、趋势和技术指标。",
    "technical_report"
)
financial_analyst_node = create_specialist_node(
    "你是一位资深的财务分析师。你专门解读财务报表和业绩指标。",
    "financial_report"
)

def report_writer_node(state: MultiAgentState):
    """Composer node that merges the three expert sections into a final report."""
    console.print("--- 📝 调用报告撰写人 ---")
    prompt = f"""你是一位资深的金融编辑。你的任务是将以下专家报告合并成一份专业、连贯、完整的市场分析报告。请添加简短的开头和结尾段落。

新闻与情绪报告:
{state['news_report']}

技术分析报告:
{state['technical_report']}

财务表现报告:
{state['financial_report']}
"""
    final_report = llm.invoke(prompt).content
    return {"final_report": final_report}

print("✅ 专业智能体节点和报告撰写人节点定义完成。")

The workflow is assembled sequentially (news → technical → financial → composer) using StateGraph:

multi_agent_graph_builder = StateGraph(MultiAgentState)
multi_agent_graph_builder.add_node("news_analyst", news_analyst_node)
multi_agent_graph_builder.add_node("technical_analyst", technical_analyst_node)
multi_agent_graph_builder.add_node("financial_analyst", financial_analyst_node)
multi_agent_graph_builder.add_node("report_writer", report_writer_node)

multi_agent_graph_builder.set_entry_point("news_analyst")
multi_agent_graph_builder.add_edge("news_analyst", "technical_analyst")
multi_agent_graph_builder.add_edge("technical_analyst", "financial_analyst")
multi_agent_graph_builder.add_edge("financial_analyst", "report_writer")
multi_agent_graph_builder.add_edge("report_writer", END)

multi_agent_app = multi_agent_graph_builder.compile()
print("✅ 多智能体专家团队编译成功。")

Stage 3 – Comparative Test

The same market‑analysis query is fed to both the monolithic agent and the expert team. The author prints both final reports.

final_multi_agent_output = multi_agent_app.invoke({"user_request": multi_agent_query})
console.print("
--- [bold green]多智能体团队最终报告[/bold green] ---")
console.print(Markdown(final_multi_agent_output['final_report']))

Visually, the team’s report shows clear sections, domain‑specific terminology (e.g., moving averages, revenue, gross margin), and a polished introduction and conclusion.

Stage 4 – LLM‑Based Evaluation

A structured ReportEvaluation model captures three scores (clarity, depth, completeness) and justification. The same LLM judges both reports.

class ReportEvaluation(BaseModel):
    clarity_and_structure_score: int = Field(description="报告的组织、结构和清晰度,1-10分。")
    analytical_depth_score: int = Field(description="每个部分的分析深度和质量,1-10分。")
    completeness_score: int = Field(description="报告满足用户所有需求的程度,1-10分。")
    justification: str = Field(description="打分理由。")

judge_llm = llm.with_structured_output(ReportEvaluation)

def evaluate_report(query: str, report: str):
    prompt = f"""你是一位金融分析报告评审专家。请根据结构、深度和完整性,对以下报告进行1-10分的评估。

**原始用户请求:**
{query}

**待评估报告:**
{report}
"""
    return judge_llm.invoke(prompt)

mono_agent_evaluation = evaluate_report(monolithic_query, final_mono_output['messages'][-1].content)
console.print(mono_agent_evaluation.model_dump())

multi_agent_evaluation = evaluate_report(multi_agent_query, final_multi_agent_output['final_report'])
console.print(multi_agent_evaluation.model_dump())

The evaluation shows the multi‑agent team scoring markedly higher on structure and analytical depth, confirming the benefit of expert specialization.

Take‑aways

Core Recap Principle: MAS applies divide‑and‑conquer, mirroring human expert collaboration. Practice: The author built a four‑member AI team (news, technical, financial analysts + editor) and demonstrated superior output. Pitfalls: Higher design complexity and API cost, but worthwhile for tasks demanding depth and rigor.

When a task spans multiple professional domains and demands authoritative analysis, assembling a specialized AI team is a pragmatic alternative to a single, generic model.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonLangChainAI architectureMulti-Agent SystemLLM evaluation
Data STUDIO
Written by

Data STUDIO

Click to receive the "Python Study Handbook"; reply "benefit" in the chat to get it. Data STUDIO focuses on original data science articles, centered on Python, covering machine learning, data analysis, visualization, MySQL and other practical knowledge and project case studies.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.