| 11 | from integuru.models.agent_state import AgentState |
| 12 | |
| 13 | class IntegrationAgent: |
| 14 | ACTION_URL_KEY: str = "action_url" |
| 15 | IN_PROCESS_NODE_KEY: str = "in_process_node" |
| 16 | TO_BE_PROCESSED_NODES_KEY: str = "to_be_processed_nodes" |
| 17 | IN_PROCESS_NODE_DYNAMIC_PARTS_KEY: str = "in_process_node_dynamic_parts" |
| 18 | MASTER_NODE_KEY: str = "master_node" |
| 19 | INPUT_VARIABLES_KEY: str = "input_variables" |
| 20 | |
| 21 | def __init__( |
| 22 | self, |
| 23 | prompt: str, |
| 24 | har_file_path: str, |
| 25 | cookie_path: str, |
| 26 | ): |
| 27 | self.prompt: str = prompt |
| 28 | self.duplicate_part_set: Set[str] = set() |
| 29 | self.global_master_node: Optional[str] = None |
| 30 | self.req_to_res_map: Dict[Request, str] = parse_har_file(har_file_path) |
| 31 | self.url_to_res_req_dict: Dict[str, Dict[str, Any]] = build_url_to_req_res_map(self.req_to_res_map) |
| 32 | self.har_urls: List[Tuple[str, str, str, str]] = get_har_urls(har_file_path) |
| 33 | self.cookie_dict: Dict[str, Dict[str, Any]] = parse_cookie_file_to_dict(cookie_path) |
| 34 | self.curl_to_id_dict: Dict[str, str] = {} |
| 35 | self.cookie_to_id_dict: Dict[str, str] = {} |
| 36 | self.dag_manager: DAGManager = DAGManager() |
| 37 | |
| 38 | def end_url_identify_agent(self, state: AgentState) -> AgentState: |
| 39 | """ |
| 40 | Identify the URL responsible for a specific action |
| 41 | """ |
| 42 | function_def = { |
| 43 | "name": "identify_end_url", |
| 44 | "description": "Identify the URL responsible for a specific action", |
| 45 | "parameters": { |
| 46 | "type": "object", |
| 47 | "properties": { |
| 48 | "url": { |
| 49 | "type": "string", |
| 50 | "description": f"The URL responsible for {self.prompt}" |
| 51 | } |
| 52 | }, |
| 53 | "required": ["url"] |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | prompt = f""" |
| 58 | {self.har_urls} |
| 59 | Task: |
| 60 | Given the above list of URLs, request types, and response formats, find the URL responsible for the action below: |
| 61 | {self.prompt} |
| 62 | """ |
| 63 | |
| 64 | response = llm.get_instance().invoke( |
| 65 | prompt, |
| 66 | functions=[function_def], |
| 67 | function_call={"name": "identify_end_url"} |
| 68 | ) |
| 69 | |
| 70 | function_call = response.additional_kwargs['function_call'] |
no outgoing calls