33import java .lang .reflect .Method ;
44import java .util .Arrays ;
55import java .util .stream .Collectors ;
6+ import io .sentrius .agent .analysis .agents .verbs .ExampleFactory ;
7+ import io .sentrius .sso .core .utils .JsonUtil ;
68
79/**
810 * The `PromptBuilder` class is responsible for constructing a prompt string
@@ -61,21 +63,50 @@ public String buildPrompt(boolean applyInstructions)
6163 " }\n " +
6264 " ]\n " +
6365 "}\n " );
64-
66+ }
6567 // Append the list of available verbs
66- prompt .append ("Available Verbs :\n " );
68+ prompt .append ("Verb operations :\n " );
6769
6870 // Iterate through the verbs in the registry and append their details
6971 verbRegistry .getVerbs ().forEach ((name , verb ) -> {
7072 prompt .append ("- " ).append (name );
7173 prompt .append (" (" ).append (buildMethodSignature (verb .getMethod ())).append (") - " );
7274 prompt .append (verb .getDescription ()).append ("\n " );
75+ // Optionally generate example params based on arg1 class
76+ Class <?>[] paramTypes = verb .getMethod ().getParameterTypes ();
77+
78+ if (paramTypes .length > 1 && !paramTypes [1 ].equals (Void .class )) {
79+ var paramName = verb .getMethod ().getParameters ()[1 ].getName ();
80+ Object example = ExampleFactory .createExample (paramName , paramTypes [1 ]); // create a stub from
81+ // your DTO
82+ try {
83+ if (verb .getExampleJson () != null && !verb .getExampleJson ().isEmpty ()) {
84+ prompt .append (" Example arg1: " ).append (verb .getExampleJson ()).append ("\n " );
85+ } else if (example != null ) {
86+ // Serialize the example object to JSON
87+ String exampleJson = JsonUtil .MAPPER .writeValueAsString (example );
88+ prompt .append (" Example arg1: " ).append (exampleJson ).append ("\n " );
89+ }
90+
91+ } catch (Exception e ) {
92+ prompt .append (" Example params: [unavailable due to serialization error]\n " );
93+ }
94+ } else {
95+ prompt .append (" Example params: {}\n " );
96+ }
7397 });
74- }
7598
7699 return prompt .toString ();
77100 }
78101
102+ public static String indent (String input , int spaces ) {
103+ String indent = " " .repeat (spaces );
104+ return Arrays .stream (input .split ("\n " ))
105+ .map (line -> indent + line )
106+ .collect (Collectors .joining ("\n " ));
107+ }
108+
109+
79110 /**
80111 * Builds a method signature string for a given method.
81112 *
@@ -84,6 +115,8 @@ public String buildPrompt(boolean applyInstructions)
84115 */
85116 private String buildMethodSignature (Method method ) {
86117 return Arrays .stream (method .getParameters ())
118+ .filter ( p -> !p .getType ().getSimpleName ().equalsIgnoreCase ("TokenDTO" ) &&
119+ !p .getType ().getSimpleName ().equalsIgnoreCase ("AgentExecution" ))
87120 .map (p -> p .getName () + ": " + p .getType ().getSimpleName ())
88121 .collect (Collectors .joining (", " ));
89122 }
0 commit comments