Agents are in the beta phase of development and may not be available on your enrollment. Functionality may change during active development.
When you create an agent, your code repository is generated from an agent template. The template ships with simplified configuration for Ontology MCP (OMCP), Palantir MCP, and the Ontology SDK (OSDK), with common setup provided by the agent library. The template keeps your repository focused on agent logic rather than platform plumbing.
Templates are available for the following agent frameworks:
query function, and tools are exposed through MCP servers.Agent and run primitives.Agent and InMemoryRunner primitives. Gemini is routed through the Foundry language model proxy, so no Google API key is required.These templates share the same project structure, argument schema, default MCP configurations, and publishing flow. They differ in how the agent loop and custom tools are defined. Select a template when you create your agent. Unless noted otherwise, the examples in this section use the Claude Agent SDK template.
An agent template code repository has the following structure:
Copied!1 2 3 4 5 6agent/ # Your agent code ├── index.ts # Agent entry point and argument schema ├── systemPrompt.ts # System prompt └── customTools.ts # Custom tools utils/ # Shared platform tooling scripts/ # Build scripts
| Path | Description |
|---|---|
agent/index.ts | The agent entry point. Defines the AgentArguments schema and the runAgent function that drives the agent loop. |
agent/systemPrompt.ts | The system prompt that defines how the model behaves. |
agent/customTools.ts | Custom tools the agent can call, exposed through an in-process MCP server. |
utils/ | Shared platform tooling used by the template, including OSDK client helpers and publishing commands. |
scripts/ | Build scripts used to package the agent for publishing. |
Default MCP configurations for Palantir MCP, Ontology MCP, and Python Transforms MCP are provided by the agent library. You retrieve them with the MCP configuration functions described below.
To add your own MCP configurations, create a new file under agent/, such as agent/mcps/custom.ts, and register it in your agent loop the same way as the MCP configuration functions. Keeping custom configurations in your own files avoids conflicts during repository upgrades.
Palantir MCP provides tools to interact with the platform. To reduce token usage, you can enable tool search for Palantir MCP so that tools are discovered on demand rather than loaded all at once.
Edit agent/systemPrompt.ts to change the instructions that define how the agent behaves.
Agents can accept arguments that are provided for each run. Define them in the AgentArguments schema in agent/index.ts using defineInputs:
Copied!1 2 3 4 5 6import { defineInputs, t } from "@palantir/agent-templates-bundle"; export const AgentArguments = defineInputs({ additionalAgentContext: t.string().optional(), // Add your own arguments here });
Arguments are automatically accepted when the agent is invoked and registered as input types when the agent is published to Foundry.
Edit agent/customTools.ts to define tools the agent can call.
For the Claude Agent SDK template, define tools with tool and expose them through an in-process MCP server created with createSdkMcpServer:
Copied!1 2 3 4 5 6 7 8 9 10 11import { createSdkMcpServer, tool } from "@anthropic-ai/claude-agent-sdk"; import { z } from "zod"; tool( "my_tool", "Description of what this tool does", z.object({ param: z.string() }), async (params) => { return mcpSuccessResponse("result"); }, );
For the OpenAI Agents SDK template, define tools with tool from @openai/agents:
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15import { tool } from "@openai/agents"; const myTool = tool({ name: "my_tool", description: "Description of what this tool does", parameters: { type: "object", properties: { param: { type: "string" } }, required: ["param"], }, strict: false, execute: async (input) => { return "result"; }, });
For the Google ADK template, define tools with FunctionTool from @google/adk:
Copied!1 2 3 4 5 6 7 8 9 10 11import { FunctionTool } from "@google/adk"; import { z } from "zod"; const myTool = new FunctionTool({ name: "my_tool", description: "Description of what this tool does", parameters: z.object({ param: z.string() }), execute: async (input) => { return "result"; }, });
Modify the runAgent function in agent/index.ts to change the prompt, model, MCP servers, or tools passed to the agent.
For the Claude Agent SDK template, retrieve the Ontology MCP configuration, pass it to the query function as an MCP server, and consume the agent's response stream:
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17import { query } from "@anthropic-ai/claude-agent-sdk"; import { getOntologyMcpConfiguration } from "@palantir/agent-templates-bundle/mcp/anthropic"; export async function runAgent(args: AgentArgs) { const omcpConfig = await getOntologyMcpConfiguration(); const iter = query({ prompt: "...", options: { mcpServers: { ["ontology_mcp"]: omcpConfig, }, }, }); // Consume the agent's response stream }
For the OpenAI Agents SDK template, construct an Agent, connect its MCP servers, run the agent, and consume the result stream:
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31import { Agent, run, MCPServer } from "@openai/agents"; export async function runAgent(args: AgentArgs) { const mcpServers: MCPServer[] = [ // Add MCP servers here ]; for (const server of mcpServers) { await server.connect(); } try { const agent = new Agent({ name: "MyAgent", instructions: "...", mcpServers, tools: [myTool], model: "gpt-5.4", }); const result = await run(agent, "...", { stream: true }); // Consume the agent's response stream await result.completed; } finally { for (const server of mcpServers) { await server.close(); } } }
For the Google ADK template, construct an Agent, run it with an InMemoryRunner, and consume the event stream. The template provides a FoundryGemini model wrapper, defined in a template-managed foundryGemini.ts file, that routes Gemini through the Foundry language model proxy, so no Google API key is required:
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32import { Agent, InMemoryRunner, MCPToolset, stringifyContent } from "@google/adk"; import { FoundryGemini } from "./foundryGemini"; export async function runAgent(args: AgentArgs) { const mcpToolsets: MCPToolset[] = [ // Add MCP toolsets here ]; try { const agent = new Agent({ name: "MyAgent", instruction: "...", tools: [...mcpToolsets], model: new FoundryGemini({ model: "gemini-2.5-flash" }), }); const runner = new InMemoryRunner({ agent }); for await (const event of runner.runEphemeral({ userId: "user", newMessage: { role: "user", parts: [{ text: "..." }] }, })) { if (event.content) { console.log(stringifyContent(event)); } } } finally { for (const toolset of mcpToolsets) { await toolset.close(); } } }
The template makes both OSDK and Ontology MCP available to your agent without client credentials, through the agent's scoped permissions.
To give your agent access to Ontology resources, add an Ontology SDK to the agent. As when creating an SDK in Code Workspaces, select the object types, action types, and query functions to include, then generate the SDK. For step-by-step guidance, review Create a new Ontology SDK.
To read and write Ontology data directly, construct an OSDK client bound to your selected Ontology. The Ontology resource identifier (RID) is exposed by the generated SDK:
Copied!1 2 3 4import { getOntologySdkClient } from "@palantir/agent-templates-bundle"; import { $ontologyRid } from "@ontology/sdk"; const client = await getOntologySdkClient($ontologyRid);
For guidance on using the OSDK in your agent, review the Ontology SDK documentation and the TypeScript OSDK reference.
When you add an Ontology SDK to your agent, an Ontology MCP is created based on the same SDK resources. The Ontology MCP exposes the object types, action types, and query functions in the SDK as MCP tools that your agent's model can call.
To use Ontology MCP, retrieve its configuration with the getOntologyMcpConfiguration function and pass it to your agent's MCP servers, as described in MCP configuration functions below. For more information on the tools Ontology MCP exposes, review the Ontology MCP documentation.
The agent library provides the default MCP server configurations through the following functions:
| Function | Connects to | Description |
|---|---|---|
getOntologyMcpConfiguration | Ontology MCP | Exposes the object types, action types, and query functions from your Ontology SDK as tools the model can call. An SDK must be added first, as described in Ontology SDK. |
getPalantirMcpConfiguration | Palantir MCP | Provides a wide range of tools to interact with the Palantir platform. |
getPythonTransformsMcpConfiguration | Python Transforms MCP | Provides tools to interact with Foundry Python transforms, such as previewing and discovering transforms. |
Each function is async and resolves the connection details at runtime. Because the URL, command, and authorization details are resolved through scoped permissions, no client ID, secret, or Foundry token is required.
The functions are framework-specific: each returns the MCP server type expected by your agent framework. Import them from the package path that matches your template:
| Framework | Import path | Return type |
|---|---|---|
| Claude Agent SDK | @palantir/agent-templates-bundle/mcp/anthropic | McpHttpServerConfig or McpStdioServerConfig |
| OpenAI Agents SDK | @palantir/agent-templates-bundle/mcp/openai | MCPServerStreamableHttp or MCPServerStdio |
| Google ADK | @palantir/agent-templates-bundle/mcp/google | MCPToolset |
Remember that each function is asynchronous: await it before registering the result in your agent loop.
For the Claude Agent SDK template, register the resolved configurations in the mcpServers map passed to query:
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16import { getOntologyMcpConfiguration, getPalantirMcpConfiguration } from "@palantir/agent-templates-bundle/mcp/anthropic"; const [omcpConfig, palantirConfig] = await Promise.all([ getOntologyMcpConfiguration(), getPalantirMcpConfiguration(), ]); const iter = query({ prompt: "...", options: { mcpServers: { ["ontology_mcp"]: omcpConfig, ["palantir_mcp"]: palantirConfig, }, }, });
For the OpenAI Agents SDK template, collect the resolved servers into the mcpServers array passed to new Agent:
Copied!1 2 3 4 5 6 7 8import { getOntologyMcpConfiguration, getPalantirMcpConfiguration } from "@palantir/agent-templates-bundle/mcp/openai"; import { MCPServer } from "@openai/agents"; const [ontologyMcp, palantirMcp] = await Promise.all([ getOntologyMcpConfiguration(), getPalantirMcpConfiguration(), ]); const mcpServers: MCPServer[] = [ontologyMcp, palantirMcp];
For the Google ADK template, add each resolved MCPToolset to the agent's tools array:
Copied!1 2 3 4 5 6 7 8import { getOntologyMcpConfiguration, getPalantirMcpConfiguration } from "@palantir/agent-templates-bundle/mcp/google"; import { MCPToolset } from "@google/adk"; const [ontologyMcp, palantirMcp] = await Promise.all([ getOntologyMcpConfiguration(), getPalantirMcpConfiguration(), ]); const mcpToolsets: MCPToolset[] = [ontologyMcp, palantirMcp];
Palantir MCP and Python Transforms MCP require your Foundry front-door host (FOUNDRY_EXTERNAL_HOST). This host is resolved for you at runtime from Control Panel using the agent's own credentials. It therefore remains correct even when the agent is installed on a different enrollment through Marketplace. If the host cannot be resolved, the configuration falls back to the host recorded when the repository was generated. To override the fallback, pass a fallbackHost option to getPalantirMcpConfiguration or getPythonTransformsMcpConfiguration.