google_search instruction = ''' You are a friendly AI assistant that answers user's queries. Use google_search to give answers based on the latest and objective information. ''' search_agent = LlmAgent( name='search_agent', model='gemini-2.0-flash-001', description='Agent to answer questions using Google Search.', instruction=instruction, tools=[google_search] )
google_search instruction = ''' You are a friendly AI assistant that answers user's queries. Use google_search to give answers based on the latest and objective information. ''' search_agent = LlmAgent( name='search_agent', model='gemini-2.0-flash-001', description='Agent to answer questions using Google Search.', instruction=instruction, tools=[google_search] ) LLM モデル 使用可能なツール( の例では、 Grounding with Google Search を使用) LLM に渡 プロンプトに description と instruction 追加 れる LLM に渡 プロンプトに description と instruction 追加 れる
user_id): self._remote_agent = remote_agent self._user_id = user_id self._session = remote_agent.create_session(user_id=self._user_id) def _stream(self, query): events = self._remote_agent.stream_query( user_id=self._user_id, session_id=self._session['id'], message=query, ) result = [] for event in events: if ('content' in event and 'parts' in event['content']): response = '\n'.join( [p['text'] for p in event['content']['parts'] if 'text' in p] ) if response: print(response) result.append(response) return result def stream(self, query): # Retry 4 times in case of resource exhaustion for c in range(4): if c > 0: time.sleep(2**(c-1)) result = self._stream(query) if result: return result if DEBUG: print('----\nRetrying...\n----') return None # Permanent error User ID / Session ID / Message を Remote Runner に送信
オプションに追加 れま 。 def evaluate_plan(goal:str, plan:str) -> dict: """ Generate an evaluation for the plan against the goal. Args: goal (str): The goal of the event plan (str): Current plan Returns: dict: A dictionary containing the evaluation comment with the following keys: evaluation: evaluation comment improvements: list of ideas for improvements """ response = _evaluate_plan(goal, plan) return json.loads(response) ツール関数の定義 42
the goal. Args: goal (str): The goal of the event plan (str): Current plan Returns: dict: A dictionary containing the evaluation comment with the following keys: evaluation: evaluation comment improvements: list of ideas for improvements [parameters] - goal: STRING - plan: STRING [response] - OBJECT def evaluate_plan(goal:str, plan:str) -> dict: """ Generate an evaluation for the plan against the goal. Args: goal (str): The goal of the event plan (str): Current plan Returns: dict: A dictionary containing the evaluation comment with the following keys: evaluation: evaluation comment improvements: list of ideas for improvements """ response = _evaluate_plan(goal, plan) return json.loads(response) tools_config にセット れる情報 ツール関数の定義
of the coffee shop "夜 帳". Before giving an answer, say "と りちゃんが答えるよ! ". [task] Give an answer to the query based on the [shop information]. [shop information] {coffee_shop_info} [format instruction] In Japanese. No markdowns. ''' tobariChan_agent = LlmAgent( model='gemini-2.0-flash-001', name='TobariChan_agent', description=( 'A friendly guide of the coffee shop "夜 帳".' ), instruction=instruction, ) global_instruction = ''' * Name of the guide of "夜 帳" is "と りちゃん ". * Name of the guide of "新宿スターライトテラス " is "テラスガイド ". ''' instruction = f''' You are a formal guide of the shopping mall "新宿スターライトテラス ". Before giving an answer, say "テラスガイドがお答えいたします。 ". [Tasks] * Give an answer to the query based on the [mall information]. [mall information] {shopping_mall_info} ''' terraceGuide_agent = LlmAgent( model='gemini-2.0-flash-001', name='TerraceGuide_agent', description=( ''' A formal guide of the shopping mall "新宿スターライトテラス ". This agent can also answer general questions that any other agents cannot answer. ''' ), global_instruction=global_instruction, instruction=instruction, sub_agents=[ copy.deepcopy(tobariChan_agent), ], ) べてのエージェントに共 通のインストラクション サブエージェント と て登録 サブエージェント ルートエージェント 46
りちゃん ". * Name of the guide of "新宿スターライトテラス " is "テラスガイド ". You are a formal guide of the shopping mall "新宿スターライトテラス ". Before giving an answer, say "テラスガイドがお答えいたします。 ". [Tasks] * Give an answer to the query based on the [mall information]. [mall information] {mall_information} You are an agent. Your internal name is "TerraceGuide_agent". The description about you is " A formal guide of the shopping mall "新宿スターライトテラス ". This agent can also answer general questions that any other agents cannot answer. " You have a list of other agents to transfer to: Agent name: TobariChan_agent Agent description: A friendly guide of the coffee shop "夜 帳". If you are the best to answer the question according to your description, you can answer it. If another agent is better for answering the question according to its description, call `transfer_to_agent` function to transfer the question to that agent. When transfering, do not generate any text other than the function call. • ルートエージェントは、内部的に右 図のようなシステムインストラク ションを受 取りま 。 • 他のエージェントの 'description' を 見て、他のエージェントに切り替え た方 よい を判断 ま 。 • 内部的に transfer_to_agent 関数を FC で呼び出 て担当 るエージェン トを切り替えま 。 • ユーザーの入力に最後に応答 た エージェント 、次の入力も続 て 応答 ま 。 47
a friendly and energetic guide of the coffee shop "夜 帳". Before giving an answer, say "と りちゃんが答えるよ! ". [task] Give an answer to the query based on the [shop information]. [shop information] {coffee_shop_info} [format instruction] In Japanese. No markdowns. ''' tobariChan_agent = LlmAgent( model='gemini-2.0-flash-001', name='TobariChan_agent', description=( 'A friendly guide of the coffee shop "夜 帳".' ), instruction=instruction, ) instruction = f''' You are a formal guide of the shopping mall "新宿スターライトテラス ". Before giving an answer, say "テラスガイドがお答えいたします。 ". [Tasks] * Give an answer to the query based on the [mall information]. [mall information] {shopping_mall_info} ''' terraceGuide_agent_with_tool = LlmAgent( model='gemini-2.0-flash-001', name='TerraceGuide_agent', description=( 'A formal guide of the shopping mall "新宿スターライトテラス ".' ), global_instruction=global_instruction, instruction=instruction, tools=[ AgentTool(tobariChan_agent), ], ) ツールと て登録 サブエージェント ルートエージェント 50