チーム向けの、プロンプトの作成方法や他のコンテキスト・エンジニアリング技術を学習します。
コンテキスト・エンジニアリングは、言語モデルの動作や出力をガイドするために、モデルに送信される情報 (コンテキスト) を設計・制御するプロセスです。
実際には、コンテキストの構築は一つの質問に集約されます :「どの情報が最も望ましい結果を達成しやすいか?」
Agno 2.x : Learn : チーム – コンテキスト・エンジニアリング
作成 : クラスキャット・セールスインフォメーション
作成日時 : 11/15/2025
バージョン : Agno 2.2.10
* 本記事は docs.agno.com の以下のページを独自に翻訳した上で、補足説明を加えてまとめ直しています。スニペットはできる限り日本語を使用しています :
* サンプルコードの動作確認はしておりますが、必要な場合には適宜、追加改変しています。
* ご自由にリンクを張って頂いてかまいませんが、sales-info@classcat.com までご一報いただけると嬉しいです。

Agno 2.x : Learn : チーム – コンテキスト・エンジニアリング
チーム向けの、プロンプトの作成方法や他のコンテキスト・エンジニアリング技術を学習します。
コンテキスト・エンジニアリングは、言語モデルの動作や出力をガイドするために、モデルに送信される情報 (コンテキスト) を設計・制御するプロセスです。実際には、コンテキストの構築は一つの質問に集約されます :「どの情報が最も望ましい結果を達成しやすいか?」
Agno ではこれは、チームの説明、指示、メンバー情報、そしてその他の関連設定を含む、システムメッセージを注意深く精巧に作成することを意味します。このコンテキストを思慮深く構築することで、以下が可能になります :
- チームを特定の動作やロールに導く。
- チームの機能を制約、または拡張する。
- 出力に一貫性があり、関連性が高く、アプリケーションのニーズと整合性があることを保証します。
- マルチステップ推論、メンバー委任、ツール使用、構造化出力のような高度なユースケースを可能にします。
- 協調タスクのための効果的なチームメンバーの調整
システムメッセージのコンテキスト
以下はシステムメッセージを作成するために使用される主要なパラメータの一部です :
- Description: チームの全体的な動作をガイドする説明。
- Instructions: 目標をどのように達成するかについての正確で、タスク固有な指示のリスト。
- Expected Output: チームからの想定される出力の説明。
- Members: チームメンバー、ロールと機能についての情報。
システムメッセージは、チームの説明、指示、メンバー詳細、そしてその他の設定から構築されます。チームリーダーのシステムメッセージは委任ルールと調整ガイドラインも含みます。例えば :
instructions.py
from agno.agent import Agent
from agno.team import Team
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.tools.hackernews import HackerNewsTools
web_agent = Agent(
name="Web Researcher",
role="You are a web researcher that can find information on the web.",
instructions=[
"Use your web search tool to find information on the web.",
"Provide a summary of the information found.",
],
tools=[DuckDuckGoTools()],
markdown=True,
debug_mode=True, # Set to True to view the detailed logs
)
hackernews_agent = Agent(
name="HackerNews Researcher",
role="You are a hackernews researcher that can find information on hackernews.",
instructions=[
"Use your hackernews search tool to find information on hackernews.",
"Provide a summary of the information found.",
],
tools=[HackerNewsTools()],
markdown=True,
debug_mode=True, # Set to True to view the detailed logs
)
team = Team(
members=[web_agent, hackernews_agent],
instructions=[
"You are a team of researchers that can find information on the web and hackernews.",
"After finding information about the topic, compile a joint report."
],
markdown=True,
debug_mode=True, # Set to True to view the detailed logs and see the compiled system message
)
team.print_response("What is the latest news on the crypto market?", stream=True)
出力例
┏━ Response (42.1s) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ┃ ┃ 最新の暗号通貨市場に関するニュースを以下にまとめました。 ┃ ┃ ┃ ┃ 暗号通貨市場の最新ニュース ┃ ┃ ┃ ┃ 1 アルトコイン市場の動揺: ┃ ┃ • 暗号通貨市場は最近、大きな変動を経験しており、アルトコインの市場資本化が1.4兆ドルまで減少しました。この影響はビットコインの価格の下落が引 ┃ ┃ き金となっています。 ┃ ┃ • 詳細はこちら ┃ ┃ 2 ビットコインがベアマーケットに: ┃ ┃ • ビットコインの価格が95,000ドルを下回り、「ベアマーケットの状態」に入ったとされています。もし93,000ドルを下回ると、さらなる下落の可能性が ┃ ┃ あるとの警告が出ています。 ┃ ┃ • 詳細はこちら ┃ ┃ 3 ビットコイン、100Kドル割れ: ┃ ┃ • ビットコインは重要な100,000ドルの閾値を下回り、市場全体に衝撃を与え、多くのポジションの清算を引き起こしました。 ┃ ┃ • 詳細はこちら ┃ ┃ 4 ビットコインのベアマーケット: ┃ ┃ • ビットコインはリスクの高い資産からの投資家の撤退により、主要な技術的レベルを下回って取引されています。 ┃ ┃ • 詳細はこちら ┃ ┃ 5 停滞する暗号通貨市場: ┃ ┃ • ビットコインは週単位の時間枠でブル市場に留まることが難しく、50週移動平均を維持しようとしています。 ┃ ┃ • 詳細はこちら ┃ ┃ ┃ ┃ HackerNewsでの情報 ┃ ┃ ┃ ┃ HackerNewsでは、最近の投稿の中でビットコインや主要な暗号通貨に直接関連するトピックは見当たりませんでしたが、多くの投稿があるため、他のページや ┃ ┃ 関連する投稿が存在する可能性があります。具体的なトピックを知りたい場合は、以下の方法をお勧めします: ┃ ┃ ┃ ┃ 1 HackerNewsで直接「Bitcoin」または「Cryptocurrency」などのキーワードで検索してみる。 ┃ ┃ 2 暗号通貨関連の最新ニュースを提供している他のニュースサイトを参照する。 ┃ ┃ 3 専門家によるブログや暗号通貨に特化したフォーラムをチェックする。 ┃ ┃ ┃ ┃ これらの情報は、特にビットコインの価格動向が暗号市場全体に影響を与えている様子を示しています。ビットコインのボラティリティは市場全体に影響を与 ┃ ┃ え、多くのトレーダーや投資家が注目している状況です。また、さらに詳しい情報や追加のサポートが必要であれば、お知らせください。 ┃ ┃ ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
これは以下のシステムメッセージを生成します :
You are the leader of a team and sub-teams of AI Agents.
Your task is to coordinate the team to complete the user's request.
Here are the members in your team:
<team_members>
- Agent 1:
- ID: web-researcher
- Name: Web Researcher
- Role: You are a web researcher that can find information on the web.
- Member tools:
- duckduckgo_search
- duckduckgo_news
- Agent 2:
- ID: hacker-news-researcher
- Name: HackerNews Researcher
- Role: You are a hackernews researcher that can find information on hackernews.
- Member tools:
- get_top_hackernews_stories
- get_user_details
</team_members>
<how_to_respond>
- Your role is to forward tasks to members in your team with the highest likelihood of completing the user's request.
- Carefully analyze the tools available to the members and their roles before delegating tasks.
- You cannot use a member tool directly. You can only delegate tasks to members.
- When you delegate a task to another member, make sure to include:
- member_id (str): The ID of the member to delegate the task to. Use only the ID of the member, not the ID of the team followed by the ID of the
member.
- task_description (str): A clear description of the task.
- expected_output (str): The expected output.
- You can delegate tasks to multiple members at once.
- You must always analyze the responses from members before responding to the user.
- After analyzing the responses from the members, if you feel the task has been completed, you can stop and respond to the user.
- If you are not satisfied with the responses from the members, you should re-assign the task.
- For simple greetings, thanks, or questions about the team itself, you should respond directly.
- For all work requests, tasks, or questions requiring expertise, route to appropriate team members.
</how_to_respond>
<instructions>
- You are a team of researchers that can find information on the web and hackernews.
- After finding information about the topic, compile a joint report.
</instructions>
<additional_information>
- Use markdown to format your answers.
</additional_information>
システムメッセージの構築方法
以下のチームの例を考えてみましょう :
from agno.agent import Agent
from agno.team import Team
web_agent = Agent(
name="Web Researcher",
role="You are a web researcher that can find information on the web.",
description="You are a helpful web research assistant",
instructions=["Search for accurate information"],
markdown=True,
)
team = Team(
members=[web_agent],
name="Research Team",
role="Team Lead",
description="You are a research team lead",
instructions=["Coordinate the team to provide comprehensive research"],
expected_output="You should format your response with detailed findings",
markdown=True,
add_datetime_to_context=True,
add_location_to_context=True,
add_name_to_context=True,
add_session_summary_to_context=True,
add_memories_to_context=True,
add_session_state_to_context=True,
)
以下が構築されるシステムメッセージです :
You are the leader of a team and sub-teams of AI Agents.
Your task is to coordinate the team to complete the user's request.
Here are the members in your team:
<team_members>
- Agent 1:
- ID: web-researcher
- Name: Web Researcher
- Role: You are a web researcher that can find information on the web.
- Member tools:
(none)
</team_members>
<how_to_respond>
...
</how_to_respond>
You have access to memories from previous interactions with the user that you can use:
<memories_from_previous_interactions>
- User really likes Digimon and Japan.
- User really likes Japan.
- User likes coffee.
</memories_from_previous_interactions>
Note: this information is from previous interactions and may be updated in this conversation. You should always prefer information from this conversation over the past memories.
Here is a brief summary of your previous interactions:
<summary_of_previous_interactions>
The user asked about information about Digimon and Japan.
</summary_of_previous_interactions>
Note: this information is from previous interactions and may be outdated. You should ALWAYS prefer information from this conversation over the past summary.
<description>
You are a research team lead
</description>
<your_role>
Team Lead
</your_role>
<instructions>
- Coordinate the team to provide comprehensive research
</instructions>
<additional_information>
- Use markdown to format your answers.
- The current time is 2025-09-30 12:00:00.
- Your approximate location is: New York, NY, USA.
- Your name is: Research Team.
</additional_information>
<expected_output>
You should format your response with detailed findings
</expected_output>
<session_state> ... </session_state>
追加のコンテキスト
additional_context パラメータを使用して、システムメッセージの最後にコンテキストを追加できます。ここでは、additional_context は、チームが特定のデータベース・テーブルにアクセスできることを示す、メモをシステムメッセージに追加します。
from textwrap import dedent
from agno.agent import Agent
from agno.team import Team
from agno.models.langdb import LangDB
from agno.tools.duckdb import DuckDbTools
duckdb_tools = DuckDbTools(
create_tables=False, export_tables=False, summarize_tables=False
)
duckdb_tools.create_table_from_path(
path="https://phidata-public.s3.amazonaws.com/demo_data/IMDB-Movie-Data.csv",
table="movies",
)
web_researcher = Agent(
name="Web Researcher",
role="You are a web researcher that can find information on the web.",
tools=[DuckDbTools()],
instructions=[
"Use your web search tool to find information on the web.",
"Provide a summary of the information found.",
],
)
team = Team(
members=[web_researcher],
model=LangDB(id="llama3-1-70b-instruct-v1.0"),
tools=[duckdb_tools],
markdown=True,
additional_context=dedent("""\
You have access to the following tables:
- movies: contains information about movies from IMDB.
"""),
)
team.print_response("What is the average rating of movies?", stream=True)
チームメンバー情報
メンバー情報はシステムメッセージに自動的に注入されます。これはメンバー ID, 名前, ロールとツールを含みます。add_member_tools_to_context を Fale に設定して、システムメッセージからメンバーツールを削除して、これをオプションで最小化できます。
チームリーダーにチームメンバーについての情報を取得するためにツールを提供することもできます。
from agno.agent import Agent
from agno.team import Team
web_agent = Agent(
name="Web Researcher",
role="You are a web researcher that can find information on the web."
)
team = Team(
members=[web_agent],
get_member_information_tool=True, # Adds a tool to get information about team members
add_member_tools_to_context=False, # Removes the member tools from the system message
)
ツール指示
チームで Toolkit を使用している場合、instructions パラメータを使用してツール指示をシステムメッセージに追加することができます :
from agno.agent import Agent
from agno.tools.slack import SlackTools
slack_tools = SlackTools(
instructions=["Use `send_message` to send a message to the user. If the user specifies a thread, use `send_message_thread` to send a message to the thread."],
add_instructions=True,
)
team = Team(
members=[...],
tools=[slack_tools],
)
これらの指示は <additional_information> タグの後のシステムメッセージに注入されます。
エージェント型メモリ
チームで enable_agentic_memory を True に設定した場合、チームはツールを使用して、ユーザメモリを作成/更新する機能を取得します。
これは以下をシステムメッセージに追加します :
<updating_user_memories> - You have access to the `update_user_memory` tool that you can use to add new memories, update existing memories, delete memories, or clear all memories. - If the user's message includes information that should be captured as a memory, use the `update_user_memory` tool to update your memory database. - Memories should include details that could personalize ongoing interactions with the user. - Use this tool to add new memories or update existing memories that you identify in the conversation. - Use this tool if the user asks to update their memory, delete a memory, or clear all memories. - If you use the `update_user_memory` tool, remember to pass on the response to the user. </updating_user_memories>
システムメッセージを直接設定する
system_message パラメータを使用してシステムメッセージを手動で設定できます。これはすべての他の設定を無視して、ユーザが提供したシステムメッセージを使用します。
from agno.team import Team
team = Team(members=[], system_message="Share a 2 sentence story about")
team.print_response("Love in the year 12000.")
ユーザメッセージのコンテキスト
Team.run() または Team.print_response() に送信される入力はユーザメッセージとして使用されます。
ユーザメッセージへの依存関係の注入を行う方法については dependencies をご覧ください。
追加のユーザメッセージ・コンテキスト
デフォルトでは、ユーザメッセージは Team.run() or Team.print_response() 関数に送信される入力を使用して構築されます。
以下のチーム・パラメータはユーザメッセージが構築される方法を設定します :
- add_knowledge_to_context
- add_dependencies_to_context
from agno.agent import Agent
from agno.team import Team
web_agent = Agent(
name="Web Researcher",
role="You are a web researcher that can find information on the web."
)
team = Team(
members=[web_agent],
add_knowledge_to_context=True,
add_dependencies_to_context=True
)
team.print_response("What is the capital of France?", dependencies={"name": "John Doe"})
モデルに送信されるユーザメッセージはこのようになります :
What is the capital of France?
Use the following references from the knowledge base if it helps:
<references>
- Reference 1
- Reference 2
</references>
<additional context>
{"name": "John Doe"}
</additional context>
以上