44from typing import AsyncGenerator , override , Optional
55
66import jsonpickle
7+ import litellm
78from google .adk .agents import LlmAgent , SequentialAgent
89from google .adk .agents .invocation_context import InvocationContext
910from google .adk .events import Event , EventActions
10- from mcp .types import CallToolResult
1111from pydantic import Field , BaseModel
12- from yaml .scanner import ScannerError
1312
1413from agents .matmaster_agent .base_agents .callback import check_before_tool_callback_effect , default_before_tool_callback , \
1514 catch_before_tool_callback_error , check_job_create , inject_username_ticket , inject_ak_projectId , \
3332 get_BohriumStorage ,
3433 get_DFlowExecutor , OpenAPIJobAPI ,
3534)
36- from agents .matmaster_agent .llm_config import MatMasterLlmConfig
3735from agents .matmaster_agent .model import BohrJobInfo , DFlowJobInfo
3836from agents .matmaster_agent .prompt import (
3937 ResultCoreAgentDescription ,
4341)
4442from agents .matmaster_agent .utils .event_utils import is_function_call , is_function_response , send_error_event , is_text , \
4543 context_function_event , all_text_event , context_text_event , frontend_text_event , is_text_and_not_bohrium , \
46- get_function_call_indexes , context_multipart2function_event
44+ get_function_call_indexes , context_multipart2function_event , cherry_pick_events
4745from agents .matmaster_agent .utils .frontend import get_frontend_job_result_data
4846from agents .matmaster_agent .utils .helper_func import update_session_state , parse_result , get_session_state , \
4947 load_tool_response
@@ -528,7 +526,6 @@ async def _run_async_impl(self, ctx: InvocationContext) -> AsyncGenerator[Event,
528526class BaseAsyncJobAgent (LlmAgent ):
529527 submit_agent : SequentialAgent
530528 result_agent : SequentialAgent
531- params_check_completed_agent : LlmAgent
532529 params_check_info_agent : LlmAgent
533530 dflow_flag : bool = Field (False , description = 'Whether the agent is dflow related' , exclude = True )
534531 supervisor_agent : str
@@ -594,16 +591,6 @@ def __init__(
594591 sub_agents = [result_core_agent ]
595592 )
596593
597- params_check_completed_agent = ParamsCheckCompletedAgent (
598- model = MatMasterLlmConfig .gpt_4o ,
599- # model=model,
600- name = f"{ agent_prefix } _params_check_completed_agent" ,
601- instruction = gen_params_check_completed_agent_instruction (),
602- output_schema = ParamsCheckComplete ,
603- disallow_transfer_to_parent = True ,
604- disallow_transfer_to_peers = True
605- )
606-
607594 params_check_info_agent = ParamsCheckInfoAgent (
608595 model = model ,
609596 name = f"{ agent_prefix } _params_check_info_agent" ,
@@ -621,10 +608,9 @@ def __init__(
621608 description = agent_description ,
622609 submit_agent = submit_agent ,
623610 result_agent = result_agent ,
624- params_check_completed_agent = params_check_completed_agent ,
625611 params_check_info_agent = params_check_info_agent ,
626612 dflow_flag = dflow_flag ,
627- sub_agents = [submit_agent , result_agent , params_check_completed_agent , params_check_info_agent ],
613+ sub_agents = [submit_agent , result_agent , params_check_info_agent ],
628614 supervisor_agent = supervisor_agent ,
629615 sync_tools = sync_tools ,
630616 enable_tgz_unpack = enable_tgz_unpack
@@ -651,10 +637,14 @@ async def _run_async_impl(self, ctx: InvocationContext) -> AsyncGenerator[Event,
651637 ): # Only Query Job Result
652638 pass
653639 else :
654- last_params_check_completed_event = None
655- async for params_check_completed_event in self .params_check_completed_agent .run_async (ctx ):
656- last_params_check_completed_event = params_check_completed_event
657- params_check_completed_json = json .loads (last_params_check_completed_event .content .parts [0 ].text )
640+ cherry_pick_parts = cherry_pick_events (ctx )[:5 ]
641+ context_messages = '\n ' .join ([f'<{ item [0 ].title ()} > said: \n { item [1 ]} \n ' for item in cherry_pick_parts ])
642+ logger .info (f"[BaseAsyncJobAgent] context_messages = { context_messages } " )
643+
644+ prompt = gen_params_check_completed_agent_instruction ().format (context_messages = context_messages )
645+ response = litellm .completion (model = 'azure/gpt-4o' , messages = [{'role' : 'user' , 'content' : prompt }],
646+ response_format = ParamsCheckComplete )
647+ params_check_completed_json : dict = json .loads (response .choices [0 ].message .content )
658648 params_check_completed = params_check_completed_json ['flag' ]
659649 params_check_reason = params_check_completed_json ['reason' ]
660650 params_check_msg = params_check_completed_json ['analyzed_message' ]
0 commit comments