AgentContext not found/null

136 Views Asked by At

I want to run a Java agent from node.js via the proton interface. Sadly I can't get the Agent Context to work

Node.js Code

async function callEvalAgent(query) {
  const agent = await db.useAgent({ name: "search" });
  console.log("got the agent");

  const requestDocUNID = await db.createDocument({
      document: {
        Form: "searchRequest",
        query
      }
  });
  console.log("queryDoc created");
  console.log(requestDocUNID);

  await agent.run({
    selection: { search: { query: "Form = 'document'" } },
    context: { unid: requestDocUNID }
  });

  ...
}

Output:

got the agent
queryDoc created
B72CA8819EDA0691C1258592003BFBE5

...

Agent Code

public class JavaAgent extends AgentBase {

    public void NotesMain() {

      try {
          Session session = getSession();
          AgentContext agentContext = session.getAgentContext();
          Document requestDoc = agentContext.getDocumentContext();
          String query = requestDoc.getItemValueString("query");
          
         ...

      } catch(Exception e) {
          System.out.println("bla");
          e.printStackTrace();
      }
   }
}

When running the code I get a NullPointerException at

String query = requestDoc.getItemValueString("query");

on the Domino Server due to the agentContext being null. If I check on it afterwards by hand the document with the given UNID is present in my view.

What did I do wrong? Used the same approach as in the HCL Example here

1

There are 1 best solutions below

0
Steve Nikopoulos On BEST ANSWER

The documentation should be more clear.

The documentation should say that the optional document that is provided to the Agent is available to the agent using the ParameterDocID.

In a Java agent do something like this:

    final Session session = getSession();
    final Database db = session.getCurrentDatabase();
    final AgentContext agentContext = session.getAgentContext();
    final Agent agent = agentContext.getCurrentAgent();
    final String noteid = agent.getParameterDocID();
    final Document context = db.getDocumentByID(noteid);

In a LotusScript agent do something like this:

    Dim session As New NotesSession
    Dim agent As NotesAgent
    Dim db As NotesDatabase
    Dim context As NotesDocument

    Set agent = session.CurrentAgent
    Set db = session.CurrentDatabase

    Set context = db.GetDocumentByID(agent.ParameterDocID)