Get sessionRid from AIP Agent function

Hello,

I recently discovered that I can deploy an Agent created by me in Agent Studio as a function.

My approach is to use it in AIP Logic, but it requires two parameters, the first one, is the prompt and the second one is the sessionRID. My issue is that I don’t know how to obtain this parameter.

It would be great if someone could guide on how to fill in this parameter or how to use the Agents in AIP Logic as a function.

Thanks!

Hello!

If you omit the session rid in your first execution of the agent (that is, do not pass a value), you will receive a session rid to use in subsequent Agent function executions.

Here are the docs: https://www.palantir.com/docs/foundry/agent-studio/agents-as-functions/#function-inputs

As for how to use this in Logic, currently there is no way in Logic to omit optional fields on functions (like the session rid in this case). The workaround here would be to wrap your Agent function in a Typescript function, calling the Agent function without the session rid in that Typescript. We are tracking this limitation as product.

Hello! @jason

Thanks a lot for your reply, could you guide me how to import the agent into the code repository

I was trying to import it, but I can’t.

Thanks!

Sure!

Once you’ve published your Agent function, you’ll want to first import it into your code repository as a query function:

https://www.palantir.com/docs/foundry/functions/resource-imports-sidebar#import-resources-into-code-repositories

Then you use the query function syntax to call it:

https://www.palantir.com/docs/foundry/functions/query-functions/#call-a-query-function

This might end up looking something like

@Function()
public async wrapAgentInTs(userInput: string): Promise<string> {
   const result = await Queries.agentFunctionName({
      userInput: userInput
   })
   
   return result.markdownResponse;
}

To fully work around the AIP Logic optional limitation, you might need to create two of these wrapper functions, one of which takes in the session RID string, and the other does not!

Again, thanks for your reply and help!

I was trying to implement the code that you share with me and read the doc, but I have 2 doubts, the first, how I indicate to the code which Agent i want to use (In any place I put the agent rid or something), and the second, how I import “Queries” of the line 3 (This is not working for me)

Thanks!!

how I indicate to the code which Agent i want to use

Sure! My example was a notional one; I used agentFunctionName, but this should be the api name of your function. Once you import queries, it should be a method on that Queries object, so it should autocomplete for you! Each function you import as a query will show up on the Queries.

how I import “Queries” of the line 3

You need something like this at the top of your file

import { Queries } from "@foundry/ontology-api";

Sure! My example was a notional one; I used agentFunctionName , but this should be the api name of your function. Once you import queries, it should be a method on that Queries object, so it should autocomplete for you! Each function you import as a query will show up on the Queries.

Okey, done

You need something like this at the top of your file

Yes, I already doing this, but I have the error Module '"@foundry/ontology-api"' has no exported member 'Queries'.typescript(2305)

And I try to install it from the libraries Tab of the left side of the screen

Have you imported your Agent function as a query?

if so, in an edge case you might need to follow the docs and set "enableQueries": true in your functions.json file

https://www.palantir.com/docs/foundry/functions/query-functions#call-a-query-function:~:text=When%20using%20TypeScript%20v1%20functions%2C%20you%20may%20need%20to%20update%20the%20functions.json%20file%20in%20your%20repository%20to%20enable%20queries%20by%20setting%20the%20enableQueries%20property%20to%20true

Hello!

Yes, I have already imported the agent as a function and set the EnableQueries to TRUE, but the main issue is still there, I can’t import the “Queries” function

Thanks,
Mateo

Hello another time!

All it’s working fine for now, the problem is related with a conflict in the package.json, I fix the conflict and now allis good.

Thanks for your time and your support,
Mateo