@@ -590,7 +590,7 @@ public List<ZtatAsessment> analyzeAtatRequests(AgentExecution execution, List<At
590590 exampleJson = "{ \" context\" : \" Notify when a new user is added\" }"
591591 )
592592 public AgentContextDTO createAgentContext (AgentExecution execution , AgentExecutionContextDTO context )
593- throws ZtatException , JsonProcessingException {
593+ throws ZtatException , Exception {
594594 log .info ("Creating agent context" );
595595 var contextArgs = context .getExecutionArgs ();
596596 if (contextArgs == null || contextArgs .isEmpty ()) {
@@ -655,7 +655,19 @@ public AgentContextDTO createAgentContext(AgentExecution execution, AgentExecuti
655655 }
656656 var arrayNode = (ArrayNode ) node .get ("endpoints_like" );
657657 for (JsonNode localNode : arrayNode ) {
658- endpointsLikeList .add (localNode .asText ());
658+ if (localNode .isNull () || localNode .asText ().isEmpty ()) {
659+ continue ;
660+ }
661+ if (localNode .has ("method" ) && localNode .has ("endpoint" )) {
662+
663+ if (localNode .get ("endpoint" ).asText ().isEmpty () || localNode .get ("method" ).asText ().isEmpty ()) {
664+ log .info ("Skipping empty endpoint or method" );
665+ continue ;
666+ }
667+
668+ endpointsLikeList .add (localNode .asText ());
669+ }
670+
659671 }
660672
661673 }
@@ -817,11 +829,12 @@ public ObjectNode getAgentStatus(AgentExecution execution, AgentExecutionContext
817829 @ Verb (name = "get_endpoints_like" , returnType = AgentExecutionContextDTO .class , description = "Queries for endpoints in " +
818830 "the system that match the input text." ,
819831 returnName = "endpoints" ,
820- exampleJson = "{ \" endpoints_like\" : [ \" listing users\" , \" deleting users\" ] }" ,
832+ argName = "endpoints_like" ,
833+ exampleJson = "[ \" listing users\" , \" deleting users\" ]" ,
821834 requiresTokenManagement = true )
822835 public ObjectNode getEndpointsLike (AgentExecution execution ,
823836 AgentExecutionContextDTO executionContextDTO )
824- throws ZtatException , JsonProcessingException {
837+ throws ZtatException , Exception {
825838
826839 var queryInput = executionContextDTO .getExecutionArgs ();
827840 log .info ("Querying for endpoints like: {}" , queryInput );
@@ -848,97 +861,11 @@ public ObjectNode getEndpointsLike(AgentExecution execution,
848861 }
849862 contextNode .put ("endpoints" , endpoints );
850863
851- /*
852- var endpoints = verbRegistry.getEndpoints();
853- ArrayNode endpointArray = JsonUtil.MAPPER.createArrayNode();
854- for (var verb : endpoints) {
855- if (verb.getPath() == null || verb.getPath().isEmpty()) {
856- log.warn("Skipping verb {} with empty path", verb.getName());
857- continue;
858- }
859- ObjectNode endpoint = JsonUtil.MAPPER.createObjectNode();
860- endpoint.put("name", verb.getName());
861- endpoint.put("description", verb.getDescription());
862- endpoint.put("method", verb.getHttpMethod());
863- ArrayNode parameters = JsonUtil.MAPPER.createArrayNode();
864- if (verb.getParameters() != null) {
865- for (var param : verb.getParameters()) {
866- ObjectNode parameter = JsonUtil.MAPPER.createObjectNode();
867- parameter.put("name", param.getName());
868- parameter.put("description", param.getDescription());
869- parameter.put("required", param.isRequired());
870- parameter.put("type", param.getType());
871- parameters.add(parameter);
872- }
873- }
874- endpoint.put("parameters", parameters);
875- var path = verb.getPath();
876- if (verb.getServiceUrl() != null && !verb.getServiceUrl().isEmpty()) {
877- if (path.startsWith("/")) {
878- path = path.substring(1);
879- }
880- path = verb.getServiceUrl() + "/" + path;
881- }
882- endpoint.put("endpoint", path);
883- endpointArray.add(endpoint);
884- }
885- */
886- /*
887- var listedEndpoints = Message.builder().role("system").content("These are a list of available endpoints, " +
888- "description," +
889- " their " +
890- "name. The user will provide a description of necessary actions. return endpoints that meet the " +
891- "criteria with the name and endpoint in a json array. Endpoint may or may not contain a server url (ex : " +
892- "[ { \"name\": " +
893- "\"listUsers\", \"method\": \"GET\", \"endpoint\": \"https://server-url:8080/api/v1/users/list\" } ]:" + endpointArray).build();
894-
895- contextNode.put("agentId", "agent1234");
896- contextNode.put("status", "Running");
897- List<Message> messages = new ArrayList<>();
898- messages.add( listedEndpoints);
899-
900- messages.add(Message.builder().role("user").content(queryInput.toString()).build());
901- LLMRequest chatRequest = LLMRequest.builder().model("gpt-4o-mini").messages(messages).build();
902- var resp = llmService.askQuestion(execution, chatRequest);
903-
904- Response response = JsonUtil.MAPPER.readValue(resp, Response.class);
905- // log.info("Response is {}", resp);
906- for (Response.Choice choice : response.getChoices()) {
907- var content = choice.getMessage().getContent();
908- if (content.startsWith("```json")) {
909- content = content.substring(7, content.length() - 3);
910- } else if (content.startsWith("```")) {
911- content = content.substring(3, content.length() - 3);
912- }
913- log.info("content is {}", content);
914- if (null != content && !content.isEmpty()) {
915- executionContextDTO.addMessages(choice.getMessage());
916- try {
917-
918- ObjectNode newResponse = JsonUtil.MAPPER.createObjectNode();
919- JsonNode node = JsonUtil.MAPPER.readTree(content);
920-
921- if (node.isArray()) {
922- ArrayNode arrayNode = (ArrayNode) node;
923- newResponse.put("endpoints", arrayNode);
924- return newResponse;
925- } else {
926- log.warn("Expected JSON array but got: {}", node.getNodeType());
927- }
928-
929- return newResponse;
930- }catch (JsonParseException e) {
931- log.error("Failed to parse terminal response: {}", e.getMessage());
932- throw e;
933- }
934- }
935- }
936- */
937864 return contextNode ;
938865 }
939866
940867 @ Verb (name = "call_endpoint" , returnType = AgentExecutionContextDTO .class , description = "Executes an endpoint at the " +
941- "service. Input " , exampleJson = "{ \" endpoint\" : \" url\" , \" method\" : \" httpMethod\" , \" params\" : { " +
868+ "service. Input " , exampleJson = "{ \" endpoint\" : \" < url> \" , \" method\" : \" httpMethod\" , \" params\" : { " +
942869 "\" param1\" : " +
943870 "\" param1Value\" , " +
944871 "\" param2\" : " +
@@ -1029,12 +956,23 @@ public ObjectNode callEndpoint(AgentExecution execution, AgentExecutionContextDT
1029956 throw new IllegalArgumentException ("Unsupported method: " + method );
1030957 }
1031958
1032- queryInput .addMessages (Message .builder ().role ("system" ).content ("response from endpoint call: " + response ).build ());
959+ if (!isHtml (response )) {
960+
1033961
1034- contextNode .put ("response" , response );
962+ queryInput .addMessages (
963+ Message .builder ().role ("system" ).content ("response from endpoint call: " + response ).build ());
964+
965+ contextNode .put ("response" , response );
966+ } else {
967+ throw new RuntimeException ("Received HTML response, likely an error page from " + endpoint );
968+ }
1035969 return contextNode ;
1036970 }
1037971
972+ private boolean isHtml (String response ){
973+ return response != null && (response .trim ().startsWith ("<!DOCTYPE html>" ) || response .trim ().startsWith ("<html" ));
974+ }
975+
1038976 public String savePolicy (TokenDTO token , boolean includeDefault , ATPLPolicy policy ) throws ZtatException {
1039977 try {
1040978
0 commit comments