Agno チームで自律型マルチエージェントシステムを構築します。チームは、タスクを達成するために連携する、エージェント (または他のサブチーム) のコレクションです。チームはタスクを解決するために、「調整 (coordinate)」「協力 (collaborate)」または「ルーティング」のいずれかを行うことができます。
Agno : ユーザガイド : コンセプト : チーム – 概要
作成 : クラスキャット・セールスインフォメーション
作成日時 : 07/25/2025
バージョン : Agno 1.7.5
* 本記事は docs.agno.com の以下のページを独自に翻訳した上で、補足説明を加えてまとめ直しています :
* サンプルコードの動作確認はしておりますが、必要な場合には適宜、追加改変しています。
* ご自由にリンクを張って頂いてかまいませんが、sales-info@classcat.com までご一報いただけると嬉しいです。
Agno ユーザガイド : コンセプト : チーム – 概要
Agno チームで自律型マルチエージェントシステムを構築します。
チームは、タスクを達成するために連携する、エージェント (または他のサブチーム) のコレクションです。チームはタスクを解決するために、「調整 (coordinate)」「協力 (collaborate)」または「ルーティング」のいずれかを行うことができます。
チームは、エージェントまたはチームのインスタンスとなれるメンバーのリストを持ちます。
from agno.team import Team
from agno.agent import Agent
team = Team(members=[
Agent(name="Agent 1", role="You answer questions in English"),
Agent(name="Agent 2", role="You answer questions in Chinese"),
Team(name="Team 1", role="You answer questions in French"),
])
チームは、チームの mode に依存して、タスクをメンバーに転送します (transfer)。
Info : It is recommended to specify the name and the role fields of the team member, for better identification by the team leader.
モード
ルート・モード
ルート (Route) モード では、チームリーダーはリクエストの内容に基づいて、ユーザのリクエストを最も適切なチームメンバーにルーティングします。メンバーの応答はユーザに直接返され、チームリーダーは応答を解釈/変換しません。
調整モード
調整 (Coordinate) モード では、チームリーダーはタスクをチームメンバー達に委任して、それらの出力を一貫性のある (cohesive) 応答に合成します。チームリーダーは、リクエストとモデルが決定した最適なものに依存して、複数のメンバーに一度に送信することも順番に送信することもできます。
協力モード
協力 (Collaborate) モード では、すべてのチームメンバーに同じタスクが与えられ、チームリーダーはそれらの出力を一貫性のある応答に合成します。
チーム・メモリと履歴
チームは以前のインタラクションの記憶を維持し、文脈認識 (contextual awareness) を可能にします :
from agno.team import Team
team_with_memory = Team(
name="Team with Memory",
members=[agent1, agent2],
add_history_to_messages=True,
num_history_runs=5,
)
# The team will remember previous interactions
team_with_memory.print_response("What are the key challenges in quantum computing?")
team_with_memory.print_response("Elaborate on the second challenge you mentioned")
チームはまたユーザメモリも管理できます :
from agno.team import Team
from agno.memory.v2.db.sqlite import SqliteMemoryDb
from agno.memory.v2.memory import Memory
# Create a memory instance with persistent storage
memory_db = SqliteMemoryDb(table_name="memory", db_file="memory.db")
memory = Memory(db=memory_db)
team_with_memory = Team(
name="Team with Memory",
members=[agent1, agent2],
memory=memory,
enable_agentic_memory=True,
)
team_with_memory.print_response("Hi! My name is John Doe.")
team_with_memory.print_response("What is my name?")
チーム知識
チームは知識ベースを使用して情報を保存して取得できます :
from pathlib import Path
from agno.agent import Agent
from agno.embedder.openai import OpenAIEmbedder
from agno.knowledge.url import UrlKnowledge
from agno.models.openai import OpenAIChat
from agno.team import Team
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.vectordb.lancedb import LanceDb, SearchType
# Setup paths
cwd = Path(__file__).parent
tmp_dir = cwd.joinpath("tmp")
tmp_dir.mkdir(parents=True, exist_ok=True)
# Initialize knowledge base
agno_docs_knowledge = UrlKnowledge(
urls=["https://docs.agno.com/llms-full.txt"],
vector_db=LanceDb(
uri=str(tmp_dir.joinpath("lancedb")),
table_name="agno_docs",
search_type=SearchType.hybrid,
embedder=OpenAIEmbedder(id="text-embedding-3-small"),
),
)
web_agent = Agent(
name="Web Search Agent",
role="Handle web search requests",
model=OpenAIChat(id="gpt-4o"),
tools=[DuckDuckGoTools()],
instructions=["Always include sources"],
)
team_with_knowledge = Team(
name="Team with Knowledge",
members=[web_agent],
model=OpenAIChat(id="gpt-4o"),
knowledge=agno_docs_knowledge,
show_members_responses=True,
markdown=True,
)
if __name__ == "__main__":
# Set to False after the knowledge base is loaded
load_knowledge = True
if load_knowledge:
agno_docs_knowledge.load()
team_with_knowledge.print_response("Tell me about the Agno framework", stream=True)
チームはユーザメモリも管理できます :
from agno.team import Team
from agno.memory.v2.db.sqlite import SqliteMemoryDb
from agno.memory.v2.memory import Memory
# Create a memory instance with persistent storage
memory_db = SqliteMemoryDb(table_name="memory", db_file="memory.db")
memory = Memory(db=memory_db)
team_with_memory = Team(
name="Team with Memory",
members=[agent1, agent2],
memory=memory,
enable_user_memories=True,
)
team_with_memory.print_response("Hi! My name is John Doe.")
team_with_memory.print_response("What is my name?")
セッション・サマリー
セッション・サマリーを有効にするには、チームで enable_session_summaries=True を設定します。
from agno.team import Team
from agno.memory.v2.db.sqlite import SqliteMemoryDb
from agno.memory.v2.memory import Memory
team_with_session_summaries = Team(
name="Team with Memory",
members=[agent1, agent2],
enable_session_summaries=True,
)
team_with_session_summaries.print_response("Hi! My name is John Doe and I live in New York City.")
session_summary = team_with_session_summaries.get_session_summary()
print("Session Summary: ", session_summary.summary)
例
多言語チーム
異なるモデルを使用して異なる言語で質問に答える、単純な例を順を追って説明します。チームは 3 人の専門エージェントで構成され、チームリーダーはユーザの質問を適した言語エージェントにルーティングします。
multilanguage_team.py
from agno.agent import Agent
from agno.models.deepseek import DeepSeek
from agno.models.mistral.mistral import MistralChat
from agno.models.openai import OpenAIChat
from agno.team.team import Team
english_agent = Agent(
name="English Agent",
role="You only answer in English",
model=OpenAIChat(id="gpt-4o"),
)
chinese_agent = Agent(
name="Chinese Agent",
role="You only answer in Chinese",
model=DeepSeek(id="deepseek-chat"),
)
french_agent = Agent(
name="French Agent",
role="You can only answer in French",
model=MistralChat(id="mistral-large-latest"),
)
multi_language_team = Team(
name="Multi Language Team",
mode="route",
model=OpenAIChat("gpt-4o"),
members=[english_agent, chinese_agent, french_agent],
show_tool_calls=True,
markdown=True,
description="You are a language router that directs questions to the appropriate language agent.",
instructions=[
"Identify the language of the user's question and direct it to the appropriate language agent.",
"If the user asks in a language whose agent is not a team member, respond in English with:",
"'I can only answer in the following languages: English, Chinese, French. Please ask your question in one of these languages.'",
"Always check the language of the user's input before routing to an agent.",
"For unsupported languages like Italian, respond in English with the above message.",
],
show_members_responses=True,
)
if __name__ == "__main__":
# Ask "How are you?" in all supported languages
multi_language_team.print_response("Comment allez-vous?", stream=True) # French
multi_language_team.print_response("How are you?", stream=True) # English
multi_language_team.print_response("你好吗?", stream=True) # Chinese
multi_language_team.print_response("Come stai?", stream=True) # Italian
コンテンツ・チーム
2 人の専門エージェントを使用してブログ記事を作成する、別の例を説明しましょう。チームリーダーはエージェントを調整して (cordinate) ブログ記事を作成します。
content_team.py
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.team import Team
from agno.tools.duckduckgo import DuckDuckGoTools
# Create individual specialized agents
researcher = Agent(
name="Researcher",
role="Expert at finding information",
tools=[DuckDuckGoTools()],
model=OpenAIChat("gpt-4o"),
)
writer = Agent(
name="Writer",
role="Expert at writing clear, engaging content",
model=OpenAIChat("gpt-4o"),
)
# Create a team with these agents
content_team = Team(
name="Content Team",
mode="coordinate",
members=[researcher, writer],
instructions="You are a team of researchers and writers that work together to create high-quality content.",
model=OpenAIChat("gpt-4o"),
markdown=True,
)
# Run the team with a task
content_team.print_response("Create a short article about quantum computing")
リサーチ・チーム
複数の専門エージェントを組み合わせるリサーチ・チームの例が以下です :
- HackerNews チームの作成
ファイル hackernews_team.py を作成します。
hackernews_team.py
from typing import List from agno.agent import Agent from agno.models.openai import OpenAIChat from agno.team import Team from agno.tools.duckduckgo import DuckDuckGoTools from agno.tools.hackernews import HackerNewsTools from agno.tools.newspaper4k import Newspaper4kTools from pydantic import BaseModel class Article(BaseModel): title: str summary: str reference_links: List[str] hn_researcher = Agent( name="HackerNews Researcher", model=OpenAIChat("gpt-4o"), role="Gets top stories from hackernews.", tools=[HackerNewsTools()], ) web_searcher = Agent( name="Web Searcher", model=OpenAIChat("gpt-4o"), role="Searches the web for information on a topic", tools=[DuckDuckGoTools()], add_datetime_to_instructions=True, ) article_reader = Agent( name="Article Reader", role="Reads articles from URLs.", tools=[Newspaper4kTools()], ) hackernews_team = Team( name="HackerNews Team", mode="coordinate", model=OpenAIChat("gpt-4o"), members=[hn_researcher, web_searcher, article_reader], instructions=[ "First, search hackernews for what the user is asking about.", "Then, ask the article reader to read the links for the stories to get more information.", "Important: you must provide the article reader with the links to read.", "Then, ask the web searcher to search for each story to get more information.", "Finally, provide a thoughtful and engaging summary.", ], response_model=Article, show_tool_calls=True, markdown=True, debug_mode=True, show_members_responses=True, ) # Run the team report = hackernews_team.run( "What are the top stories on hackernews?" ).content print(f"Title: {report.title}") print(f"Summary: {report.summary}") print(f"Reference Links: {report.reference_links}")
- チームの実行
ライブラリをインストールします。
pip install openai duckduckgo-search newspaper4k lxml_html_clean agno
チームを実行します。
python hackernews_team.py
以上