This document demonstrates how Palantir Foundry (the data and ontology backbone) seamlessly feeds structured context into Palantir AIP (the LLM orchestration and agent harness layer) using visual workflows and deterministic TypeScript functions.
In the AIP Logic user interface, developers construct a visual, deterministic tree of operational steps called an Agent Framework rather than writing raw, unguided prompt chains.
Use code with caution.[ Input Node ] ──> [ Context Node (OAG) ] ──> [ LLM Engine Block ] ──> [ Ontology Action ](Ticket ID) (Binds Foundry Object) (Claude 3.5 Sonnet) (Secure Write-back)
Flight). AIP automatically binds the incoming ID to its respective object properties and relationships in Foundry.rebookPassenger()). The LLM cannot write custom database code; it can only trigger this pre-validated, secure execution block.When a workflow requires advanced conditional logic, dynamic memory manipulation, or programmatic tools, developers implement Palantir Functions using TypeScript. This code runs securely inside the platform infrastructure.
The following script illustrates how an AIP-managed function queries the Foundry Ontology to perform Ontology-Augmented Generation (OAG) while keeping the LLM strictly within deterministic enterprise guardrails.
import { Function } from "@link/functions-api";
import { Objects, Flight } from "@link/ontology";
import { GenerativeAI, ModelIdentifier } from "@link/aip-api";
export class FlightAssistantFunctions {
/**
* Orchestrates an LLM invocation by wrapping it inside a deterministic
* Foundry data harness to evaluate flight impacts and recommend actions.
*
* @param flightId The unique primary key of the Flight object in the Ontology.
* @returns The structured remediation assessment from the harnessed LLM.
*/
@Function()
public async analyzeFlightDelayAndSuggestAction(flightId: string): Promise<string> {
// 1. Resolve the concrete business object compiled inside Palantir Foundry
const flightObject: Flight | undefined = Objects.Flight.get(flightId);
if (!flightObject) {
throw new Error(`Flight with ID ${flightId} does not exist in the Enterprise Ontology.`);
}
// 2. Accumulate relational graph context from the semantic layer
const linkedPassengers = flightObject.passengers.all();
const delayMinutes = flightObject.delayMinutes ?? 0;
// 3. Assemble a highly structured, deterministic prompt environment (The Harness)
const promptContext = `
You are an automated operations assistant analyzing Flight ${flightObject.flightNumber}.
Current Operational Context:
- Delay Duration: ${delayMinutes} minutes.
- Impacted Passenger Count: ${linkedPassengers.length}.
Strict Operational Rules:
1. Only suggest passenger rebooking procedures if the Delay Duration exceeds 120 minutes.
2. Do NOT invent alternative flights or hallucinate connection windows.
3. Rely exclusively on the data provided above.
`;
// 4. Dispatch the payload to the LLM via AIP's managed gateway
// This abstracts token constraints, handles API retries, and enforces system security
const aiResponse = await GenerativeAI.getLLM(ModelIdentifier.CLAUDE_3_5_SONNET)
.generateText({
prompt: promptContext,
temperature: 0.1, // Set intentionally low to maximize determinism
maxTokens: 500
});
return aiResponse.text;
}
}
When this code or its equivalent UI layout executes, Palantir handles the operational infrastructure through three built-in governance layers: