Agno 2.x : エージェント – コンテキスト・エンジニアリング

エージェントに対するプロンプトの作成方法やその他のコンテキスト・エンジニアリング技術を学習します。
コンテキスト・エンジニアリングは、言語モデルの動作や出力をガイドするために (言語モデルに) 送信される情報 (コンテキスト) の設計や制御のプロセスです。実際には、コンテキストの構築は一つの質問に集約されます: 「どの情報が最も望ましい結果を獲得しやすいか?」

Agno 2.x : Learn : エージェント – コンテキスト・エンジニアリング

作成 : クラスキャット・セールスインフォメーション
作成日時 : 10/27/2025
バージョン : Agno 2.2.1

* 本記事は docs.agno.com の以下のページを独自に翻訳した上で、補足説明を加えてまとめ直しています。スニペットはできる限り日本語を使用しています :

* サンプルコードの動作確認はしておりますが、必要な場合には適宜、追加改変しています。
* ご自由にリンクを張って頂いてかまいませんが、sales-info@classcat.com までご一報いただけると嬉しいです。

 

 

Agno 2.x : Learn : エージェント – コンテキスト・エンジニアリング

エージェントに対するプロンプトの作成方法やその他のコンテキスト・エンジニアリング技術を学習します。

コンテキスト・エンジニアリングは、言語モデルの動作や出力をガイドするために (言語モデルに) 送信される情報 (コンテキスト) の設計や制御のプロセスです。実際には、コンテキストの構築は一つの質問に集約されます: 「どの情報が最も望ましい結果を獲得しやすいか?」

Agno では、これは、エージェントの説明、指示やその他の関連設定を含む、システムメッセージを注意深く作成することを意味します。このコンテキストを思慮深く構築することにより、以下を行うことができます :

  • エージェントを特定の動作や役割りに向けて誘導する。

  • エージェントの機能を制限、または拡張する。

  • 出力が一貫性があり、関連性があり、そしてアプリケーションのニーズに合致していることを保証します。

  • マルチステップ推論、ツール使用や構造化出力のような高度なユースケースを可能にする。

効果的なコンテキスト・エンジニアリングは、反復的なプロセスです : システムメッセージを洗練し、さまざまな説明や指示を試行錯誤し、スキーマ・委任やツール統合のような機能を使用します。

Agno のコンテキストは以下から構成されます :

  • システム・メッセージ : システムメッセージは、エージェントに送信される主要コンテキストで、すべての追加コンテキストも含みます。

  • ユーザ・メッセージ : ユーザメッセージはエージェントに送信されるメッセージです。

  • チャット履歴 : チャット履歴は、エージェントとユーザ間の会話の履歴です。

  • 追加入力 : コンテキストに追加される、任意の few-shot サンプルやその他の追加入力です。

 

システムメッセージ・コンテキスト

以下は、システムメッセージを作成するために使用される主要パラメータの一部です :

  1. Description (説明) : エージェントの全体的な動作をガイドする説明。

  2. Instructions (指示) : 目標を達成する方法についての正確でタスク固有の指示のリスト。

  3. Expected Output (期待される出力) : エージェントからの期待される出力の説明。

システムメッセージはエージェントの説明、指示やその他の設定から構築されます。

from agno.agent import Agent
from agno.models.openai import OpenAIChat

agent = Agent(
    model=OpenAIChat(id="gpt-4.1"),
    description="あなたは有名な短編小説家で、ある雑誌に執筆を依頼されました。",
    instructions=["常に2行構成の物語を書いてください。"],
    markdown=True,
    debug_mode=True,  # Set to True to view the detailed logs and see the compiled system message
)
agent.print_response("ホラーストーリーを話してください。", stream=True)

出力例

┏━ Message ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃                                                                                                                                                 ┃
┃ ホラーストーリーを話してください。                                                                                                              ┃
┃                                                                                                                                                 ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
┏━ Response (2.8s) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃                                                                                                                                                 ┃
┃ 誰もいないはずの暗い部屋の隅から、絞り出すような声で自分の名前が呼ばれた。                                                                      ┃
┃ 振り返ると、鏡の中の自分がゆっくりと笑い始めていた。                                                                                            ┃
┃                                                                                                                                                 ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

これは以下のシステムメッセージを生成します :

DEBUG あなたは有名な短編小説家で、ある雑誌に執筆を依頼されました。                                                                                 
      <instructions>                                                                                                                               
      常に2行構成の物語を書いてください。                                                                                                          
      </instructions>                                                                                                                              
                                                                                                                                                   
      <additional_information>                                                                                                                     
      - Use markdown to format your answers.                                                                                                       
      </additional_information>                                                                                                                    

See the full Agent reference for more information.

 

システムメッセージがどのように構築されるか

次のエージェントの例を見てみましょう :

from agno.agent import Agent

agent = Agent(
    name="役に立つアシスタント",
    role="アシスタント",
    description="あなたは役に立つアシスタントです",
    instructions=["ユーザーの質問に対応してください"],
    additional_context="""
    ここに、ユーザーの質問に答える方法の例があります:
      Request:フランスの首都は何ですか?
      Response:フランスの首都はパリです。
    """,
    expected_output="あなたは応答を `Response: ` という形式でフォーマットする必要があります",
    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,
)

出力例

DEBUG ***************************************************** Agent ID: 役に立つアシスタント ****************************************************    
DEBUG Creating new AgentSession: a9efd7b8-6090-4d6d-b7fd-ebcb67a380fe                                                                              
WARNING  Database not provided. Memories will not be stored.                                                                                       
WARNING  Memory Db not provided.                                                                                                                   
DEBUG ************************************ Agent Run Start: f72610c7-1c5e-4cca-8c21-5e60f269ae9f ************************************              
DEBUG ------------------------------------------------- OpenAI Response Stream Start ------------------------------------------------              
DEBUG -------------------------------------------------------- Model: gpt-4.1 -------------------------------------------------------              
DEBUG ============================================================ system ===========================================================              
DEBUG あなたは役に立つアシスタントです                                                                                                             
                                                                                                                                                   
                                                                                                                                        
      アシスタント                                                                                                                                 
                                                                                                                                       
                                                                                                                                                   
                                                                                                                                     
      ユーザーの質問に対応してください                                                                                                             
                                                                                                                                    
                                                                                                                                                   
                                                                                                                           
      - Use markdown to format your answers.                                                                                                       
      - The current time is 2025-10-27 15:45:10.844852.                                                                                            
      - Your approximate location is: Roppongi, 13, Japan.                                                                                         
      - Your name is: 役に立つアシスタント.                                                                                                        
                                                                                                                          
                                                                                                                                                   
                                                                                                                                  
      あなたは応答を `Response: ` という形式でフォーマットする必要があります                                                             
                                                                                                                                 
                                                                                                                                                   
                                                                                                                                                   
          ここに、ユーザーの質問に答える方法の例があります:                                                                                       
              Request:フランスの首都は何ですか?                                                                                                  
              Response:フランスの首都はパリです。                                                                                                 
                                                                                                                                                   
      You have the capability to retain memories from previous interactions with the user, but have not had any interactions with the user yet.    
                                                                                                                                                   
                                                                                                                                    
      {'current_session_id': 'a9efd7b8-6090-4d6d-b7fd-ebcb67a380fe', 'current_run_id': 'f72610c7-1c5e-4cca-8c21-5e60f269ae9f'}                     
                                                                                                                                   
DEBUG ============================================================= user ============================================================              
DEBUG 次回のサッカーW杯はどこで開催されますか?                                                                                                    
DEBUG ========================================================== assistant ==========================================================              
DEBUG Response: 次回のサッカーW杯(2026年 FIFAワールドカップ)は、アメリカ、カナダ、メキシコの3か国で共同開催されます。                            
DEBUG **********************************************************  METRICS  **********************************************************              
DEBUG * Tokens:                      input=307, output=43, total=350                                                                               
DEBUG * Duration:                    2.3154s                                                                                                       
DEBUG * Tokens per second:           18.5709 tokens/s                                                                                              
DEBUG **********************************************************  METRICS  **********************************************************              
DEBUG -------------------------------------------------- OpenAI Response Stream End -------------------------------------------------              
DEBUG Added RunOutput to Agent Session                                                                                                             
DEBUG ************************************* Agent Run End: f72610c7-1c5e-4cca-8c21-5e60f269ae9f *************************************              
┏━ Message ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃                                                                                                                                                 ┃
┃ 次回のサッカーW杯はどこで開催されますか?                                                                                                       ┃
┃                                                                                                                                                 ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
┏━ Response (4.3s) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃                                                                                                                                                 ┃
┃ Response: 次回のサッカーW杯(2026年 FIFAワールドカップ)は、アメリカ、カナダ、メキシコの3か国で共同開催されます。                               ┃
┃                                                                                                                                                 ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

 

追加のコンテキスト

additional_context パラメータを使用して、システムメッセージの最後にコンテキストを追加できます。

ここでは、additional_context は、エージェントが特定のデータベース・テーブルにアクセスできることを示す、システムメッセージへのノート (注釈) を追加しています。

from textwrap import dedent

from agno.agent import Agent
from agno.models.openai import OpenAIChat
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",
)

agent = Agent(
    model=OpenAIChat(id="gpt-4.1"),
    debug_mode=True,
    tools=[duckdb_tools],
    markdown=True,
    additional_context=dedent("""\
    あなたは以下のテーブルにアクセスできます :
    - movies: IMDB の映画に関する情報を含む。
    """),
)
agent.print_response("映画の平均評価 (rating) はどれくらいですか?", stream=True)

出力例

INFO Running: CREATE TABLE IF NOT EXISTS movies AS SELECT * FROM read_csv('https://phidata-public.s3.amazonaws.com/demo_data/IMDB-Movie-Data.csv', 
     ignore_errors=false, auto_detect=true)                                                                                                        
DEBUG **************************************** Agent ID: 4783dd06-1109-43ab-8eb3-484b0f7c055d ***************************************              
DEBUG Creating new AgentSession: 6f0d241b-a364-4d36-9474-0a1736f484ec                                                                              
DEBUG Processing tools for model                                                                                                                   
DEBUG Added tool show_tables from duckdb_tools                                                                                                     
DEBUG Added tool describe_table from duckdb_tools                                                                                                  
DEBUG Added tool inspect_query from duckdb_tools                                                                                                   
DEBUG Added tool run_query from duckdb_tools                                                                                                       
DEBUG Added tool create_table_from_path from duckdb_tools                                                                                          
DEBUG Added tool summarize_table from duckdb_tools                                                                                                 
DEBUG Added tool export_table_to_path from duckdb_tools                                                                                            
DEBUG Added tool load_local_path_to_table from duckdb_tools                                                                                        
DEBUG Added tool load_local_csv_to_table from duckdb_tools                                                                                         
DEBUG Added tool load_s3_path_to_table from duckdb_tools                                                                                           
DEBUG Added tool load_s3_csv_to_table from duckdb_tools                                                                                            
DEBUG Added tool create_fts_index from duckdb_tools                                                                                                
DEBUG Added tool full_text_search from duckdb_tools                                                                                                
DEBUG ************************************ Agent Run Start: 0e262d4b-cbea-4c79-915a-91222fabe539 ************************************              
DEBUG ------------------------------------------------- OpenAI Response Stream Start ------------------------------------------------              
DEBUG -------------------------------------------------------- Model: gpt-4.1 -------------------------------------------------------              
DEBUG ============================================================ system ===========================================================              
DEBUG <additional_information>                                                                                                                     
      - Use markdown to format your answers.                                                                                                       
      </additional_information>                                                                                                                    
                                                                                                                                                   
      あなたは以下のテーブルにアクセスできます :                                                                                                   
      - movies: IMDB の映画に関する情報を含む。                                                                                                    
DEBUG ============================================================= user ============================================================              
DEBUG 映画の平均評価 (rating) はどれくらいですか?                                                                                                 
DEBUG ========================================================== assistant ==========================================================              
DEBUG Tool Calls:                                                                                                                                  
        - ID: 'call_P7H9QrY0bP9LJwwt1E6iB0pZ'                                                                                                      
          Name: 'summarize_table'                                                                                                                  
          Arguments: 'table: movies'                                                                                                               
DEBUG **********************************************************  METRICS  **********************************************************              
DEBUG * Tokens:                      input=781, output=16, total=797                                                                               
DEBUG * Duration:                    1.3008s                                                                                                       
DEBUG * Tokens per second:           12.3005 tokens/s                                                                                              
DEBUG **********************************************************  METRICS  **********************************************************              
DEBUG Running: summarize_table(table=movies)                                                                                                       
INFO Running: SUMMARIZE movies                                                                                                                     
DEBUG Query result: column_name,column_type,min,max,approx_unique,avg,std,q25,q50,q75,count,null_percentage                                        
      Rank,BIGINT,1,1000,1232,500.5,288.8194360957494,250,500,750,1000,0.00                                                                        
      Title,VARCHAR,(500) Days of Summer,Zootopia,1080,None,None,None,None,None,1000,0.00                                                          
      Genre,VARCHAR,Action,Thriller,War,215,None,None,None,None,None,1000,0.00                                                                     
      Description,VARCHAR,"21" is the fact-based story about six MIT students who were trained to become experts in card counting and subsequently 
      took Vegas casinos for millions in winnings.,Young, up-and-coming martial artist, Bruce Lee, challenges legendary kung fu master Wong Jack   
      Man to a no-holds-barred fight in Northern California.,691,None,None,None,None,None,1000,0.00                                                
      Director,VARCHAR,Aamir Khan,Zackary Adler,541,None,None,None,None,None,1000,0.00                                                             
      Actors,VARCHAR,Aamir Khan, Anushka Sharma, Sanjay Dutt,Boman Irani,Zooey Deschanel, Joseph Gordon-Levitt, Geoffrey Arend, Chloë Grace        
      Moretz,1116,None,None,None,None,None,1000,0.00                                                                                               
      Year,BIGINT,2006,2016,12,2012.783,3.2059615077522667,2010,2014,2016,1000,0.00                                                                
      Runtime (Minutes),BIGINT,66,191,110,113.172,18.810908172288404,100,111,123,1000,0.00                                                         
      Rating,DOUBLE,1.9,9.0,53,6.723200000000003,0.945428789277963,6.190384615384616,6.8,7.4,1000,0.00                                             
      Votes,BIGINT,61,1791916,903,169808.255,188762.6475182208,36703,110488,239967,1000,0.00                                                       
      Revenue                                                                                                                                      
      (Millions),DOUBLE,0.0,936.63,825,82.95637614678897,103.25354047492468,13.14705627705628,48.27991124260355,113.60702479338843,1000,12.80      
      Metascore,BIGINT,11,100,77,58.98504273504273,17.194757023263847,47,59,72,1000,6.40                                                           
DEBUG Table description: column_name,column_type,min,max,approx_unique,avg,std,q25,q50,q75,count,null_percentage                                   
      Rank,BIGINT,1,1000,1232,500.5,288.8194360957494,250,500,750,1000,0.00                                                                        
      Title,VARCHAR,(500) Days of Summer,Zootopia,1080,None,None,None,None,None,1000,0.00                                                          
      Genre,VARCHAR,Action,Thriller,War,215,None,None,None,None,None,1000,0.00                                                                     
      Description,VARCHAR,"21" is the fact-based story about six MIT students who were trained to become experts in card counting and subsequently 
      took Vegas casinos for millions in winnings.,Young, up-and-coming martial artist, Bruce Lee, challenges legendary kung fu master Wong Jack   
      Man to a no-holds-barred fight in Northern California.,691,None,None,None,None,None,1000,0.00                                                
      Director,VARCHAR,Aamir Khan,Zackary Adler,541,None,None,None,None,None,1000,0.00                                                             
      Actors,VARCHAR,Aamir Khan, Anushka Sharma, Sanjay Dutt,Boman Irani,Zooey Deschanel, Joseph Gordon-Levitt, Geoffrey Arend, Chloë Grace        
      Moretz,1116,None,None,None,None,None,1000,0.00                                                                                               
      Year,BIGINT,2006,2016,12,2012.783,3.2059615077522667,2010,2014,2016,1000,0.00                                                                
      Runtime (Minutes),BIGINT,66,191,110,113.172,18.810908172288404,100,111,123,1000,0.00                                                         
      Rating,DOUBLE,1.9,9.0,53,6.723200000000003,0.945428789277963,6.190384615384616,6.8,7.4,1000,0.00                                             
      Votes,BIGINT,61,1791916,903,169808.255,188762.6475182208,36703,110488,239967,1000,0.00                                                       
      Revenue                                                                                                                                      
      (Millions),DOUBLE,0.0,936.63,825,82.95637614678897,103.25354047492468,13.14705627705628,48.27991124260355,113.60702479338843,1000,12.80      
      Metascore,BIGINT,11,100,77,58.98504273504273,17.194757023263847,47,59,72,1000,6.40                                                           
DEBUG ============================================================= tool ============================================================              
DEBUG Tool call Id: call_P7H9QrY0bP9LJwwt1E6iB0pZ                                                                                                  
DEBUG column_name,column_type,min,max,approx_unique,avg,std,q25,q50,q75,count,null_percentage                                                      
      Rank,BIGINT,1,1000,1232,500.5,288.8194360957494,250,500,750,1000,0.00                                                                        
      Title,VARCHAR,(500) Days of Summer,Zootopia,1080,None,None,None,None,None,1000,0.00                                                          
      Genre,VARCHAR,Action,Thriller,War,215,None,None,None,None,None,1000,0.00                                                                     
      Description,VARCHAR,"21" is the fact-based story about six MIT students who were trained to become experts in card counting and subsequently 
      took Vegas casinos for millions in winnings.,Young, up-and-coming martial artist, Bruce Lee, challenges legendary kung fu master Wong Jack   
      Man to a no-holds-barred fight in Northern California.,691,None,None,None,None,None,1000,0.00                                                
      Director,VARCHAR,Aamir Khan,Zackary Adler,541,None,None,None,None,None,1000,0.00                                                             
      Actors,VARCHAR,Aamir Khan, Anushka Sharma, Sanjay Dutt,Boman Irani,Zooey Deschanel, Joseph Gordon-Levitt, Geoffrey Arend, Chloë Grace        
      Moretz,1116,None,None,None,None,None,1000,0.00                                                                                               
      Year,BIGINT,2006,2016,12,2012.783,3.2059615077522667,2010,2014,2016,1000,0.00                                                                
      Runtime (Minutes),BIGINT,66,191,110,113.172,18.810908172288404,100,111,123,1000,0.00                                                         
      Rating,DOUBLE,1.9,9.0,53,6.723200000000003,0.945428789277963,6.190384615384616,6.8,7.4,1000,0.00                                             
      Votes,BIGINT,61,1791916,903,169808.255,188762.6475182208,36703,110488,239967,1000,0.00                                                       
      Revenue                                                                                                                                      
      (Millions),DOUBLE,0.0,936.63,825,82.95637614678897,103.25354047492468,13.14705627705628,48.27991124260355,113.60702479338843,1000,12.80      
      Metascore,BIGINT,11,100,77,58.98504273504273,17.194757023263847,47,59,72,1000,6.40                                                           
DEBUG ********************************************************  TOOL METRICS  *******************************************************              
DEBUG * Duration:                    0.0309s                                                                                                       
DEBUG ********************************************************  TOOL METRICS  *******************************************************              
DEBUG ========================================================== assistant ==========================================================              
DEBUG 映画の平均評価(rating)は **6.72** です。                                                                                                   
DEBUG **********************************************************  METRICS  **********************************************************              
DEBUG * Tokens:                      input=1363, output=16, total=1379                                                                             
DEBUG * Duration:                    1.2552s                                                                                                       
DEBUG * Tokens per second:           12.7468 tokens/s                                                                                              
DEBUG **********************************************************  METRICS  **********************************************************              
DEBUG -------------------------------------------------- OpenAI Response Stream End -------------------------------------------------              
DEBUG Added RunOutput to Agent Session                                                                                                             
DEBUG ************************************* Agent Run End: 0e262d4b-cbea-4c79-915a-91222fabe539 *************************************              
┏━ Message ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃                                                                                                                                                 ┃
┃ 映画の平均評価 (rating) はどれくらいですか?                                                                                                    ┃
┃                                                                                                                                                 ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
┏━ Response (2.6s) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃                                                                                                                                                 ┃
┃ 映画の平均評価(rating)は 6.72 です。                                                                                                          ┃
┃                                                                                                                                                 ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

 

ツール指示

エージェントで 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,
)
agent = Agent(
    tools=[slack_tools],
)

これらの指示は <additional_information> タグの後にシステムメッセージに注入されます。

 

エージェント型メモリ

エージェントで enable_agentic_memory を True に設定すると、エージェントはツールを使用してユーザメモリを create/update できるようになります。これは以下をシステムメッセージに追加します :

<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>

 

エージェント型知識フィルタ

エージェントで知識 (knowledge) 機能を有効にしている場合、enable_agentic_knowledge_filters パラメータを使用して、エージェントに知識フィルタを選択させることができます。これは以下をシステムメッセージに追加します :

The knowledge base contains documents with these metadata filters: [filter1, filter2, filter3].
Always use filters when the user query indicates specific metadata.

Examples:
1. If the user asks about a specific person like "Jordan Mitchell", you MUST use the search_knowledge_base tool with the filters parameter set to {{'<valid key like user_id>': '<valid value based on the user query>'}}.
2. If the user asks about a specific document type like "contracts", you MUST use the search_knowledge_base tool with the filters parameter set to {{'document_type': 'contract'}}.
4. If the user asks about a specific location like "documents from New York", you MUST use the search_knowledge_base tool with the filters parameter set to {{'<valid key like location>': 'New York'}}.

General Guidelines:
- Always analyze the user query to identify relevant metadata.
- Use the most specific filter(s) possible to narrow down results.
- If multiple filters are relevant, combine them in the filters parameter (e.g., {{'name': 'Jordan Mitchell', 'document_type': 'contract'}}).
- Ensure the filter keys match the valid metadata filters: [filter1, filter2, filter3].

You can use the search_knowledge_base tool to search the knowledge base and get the most relevant documents. Make sure to pass the filters as [Dict[str: Any]] to the tool. FOLLOW THIS STRUCTURE STRICTLY.

Learn about agentic knowledge filters in more detail in the knowledge filters section.

 

システムメッセージを直接設定する

system_message パラメータを使用してシステムメッセージを手動で設定できます。これはすべての他の設定を無視して、提供したシステムメッセージを使用します。

from agno.agent import Agent
agent.print_response("What is the capital of France?")

agent = Agent(system_message="Share a 2 sentence story about")
agent.print_response("Love in the year 12000.")

 

ユーザメッセージ・コンテキスト

Agent.run() や Agent.print_response() に送信される入力はユーザメッセージとして使用されます。

 

追加のユーザメッセージ・コンテキスト

以下のエージェントのパラメータを使用して、コンテキストをユーザメッセージに追加できます :

以下のエージェント・パラメータはユーザメッセージを構築する方法を設定します :

  • add_knowledge_to_context
  • add_dependencies_to_context
from agno.agent import Agent
agent = Agent(add_knowledge_to_context=True, add_dependencies_to_context=True)
agent.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>

See dependencies for how to do dependency injection for your user message.

 

以上