智能体

多智能体系统

VeADK 充分支持多智能体协作

使用 VeADK 可以构建多 Agent 协作, 主 Agent 通过 sub_agents 机制协调多个子 Agent 完成复杂任务。以下代码示例分别定义了三个 Agent:

  • weather_reporter:负责获取指定城市的天气信息(调用了 get_city_weather 工具)。
  • suggester:根据天气情况给出穿衣建议。
  • planner_agent:作为“调度员”,先调用 weather_reporter 获取天气,再调用 suggester 获取建议,最后将结果整合返回给用户。

该多智能体协作能更好的满足用户的需求。

from veadk import Agent, Runner
from veadk.memory.short_term_memory import ShortTermMemory
from veadk.tools.demo_tools import get_city_weather

session_id = "..."
prompt = "..."

# 定义三个智能体,分别为天气预报智能体、穿衣建议智能体以及一个Planner智能体
weather_reporter = Agent(
    name="weather_reporter",
    description="A weather reporter agent to report the weather.",
    tools=[get_city_weather],
)
suggester = Agent(
    name="suggester",
    description="A suggester agent that can give some clothing suggestions according to a city's weather.",
)

planner_agent = Agent(
    name="planner",
    description="A planner that can generate a suggestion according to a city's weather.",
    instruction="Invoke weather reporter agent first to get the weather, then invoke suggester agent to get the suggestion. Return the final response to user.",
    sub_agents=[weather_reporter, suggester],
)

runner = Runner(agent=planner_agent, short_term_memory=ShortTermMemory())
response = await runner.run(messages=prompt, session_id=session_id)