pjs.askAgent()

This API interfaces with a Profound AI Agent to perform inference on an AI model and returns the model’s output. It's designed to seamlessly integrate AI capabilities into your applications, allowing for dynamic interaction with various AI models from batch processes, 5250 applications, etc.

Parameters

  • configuration object containing the following properties:

    • agent (string) - the name of the agent file (e.g. example.agent.json)

    • data (optional, object) - an object containing properties that match to variables defined within the agent

    • message (optional, string) - the custom message to send to the agent

Any additional properties passed on the configuration object will be used as parameters to the model provider’s API.

Return value

The API returns the response from the model. The response will either be a string or an object, if a formatted JSON response is requested.

To request a JSON response, adjust your agent instructions, and specify the appropriate response format as defined in the documentation of the model API. This can be specified within the additionalParams property of the model configuration in the config.js file, or by passing the appropriate property to pjs.askAgent().

Examples:

// Requesting a JSON object response for fraud detection const response = pjs.askAgent({ agent: "fraud_detection.agent.json", data: { orderNum: 12345 }, response_format: { type: "json_object" } }); // Checking the fraud probability and taking action if (response.fraudProbability > 0.6) { pjs.sendEMail({ from, to, subject: "Fraud alert", text: response.explanation }); }

Note: The response_format property above is a model-specific parameter, based on the OpenAI standard. Parameters for other model providers may vary. The property value ensures that the model returns a JSON object only with no other wording in the response.

The formatting of the JSON output must be specified in your agent instructions using natural language (e.g. Respond in JSON format by providing an object with the following properties: fraudProbability, explanation. fraudProbability is a number ranging from 0 to 1 and explanation is a string. Sample output: { fraudProbability: 0.08, explanation: "No evidence of fraud observed" }).

 

// Requesting a summary of yearly sales data const response = pjs.askAgent({ agent: "sales_data.agent.json", message: `Provide a summary of ${yearNumber} year sales by product`, }); // Displaying the response pjs.messageBox(response);

Â