Skip to main content
skill

azure-ai-agents-persistent-java — Claude Code skill for Java agents

This skill guides Java projects using Azure AI Agents Persistent: create agents, manage message threads, and run agents. Useful when building persistent agents on Azure.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add microsoft/skills --skill azure-ai-agents-persistent-java -a claude-code
Open on GitHub

What azure-ai-agents-persistent-java does

The skill covers the low-level com.azure:azure-ai-agents-persistent SDK for managing agents that remain available across sessions. Its workflow creates an agent and thread, adds a message, starts a run, checks its status, and reads the response. Threads and agents can be deleted when the work is done.

Set PROJECT_ENDPOINT and MODEL_DEPLOYMENT_NAME to connect and choose the agent model. Production use of DefaultAzureCredential also requires AZURE_TOKEN_CREDENTIALS. The SDK offers synchronous and asynchronous clients. Runs can end with RequiresAction, Failed, or Cancelled, so account for those states when handling results. The client needs a configured endpoint and credentials to connect to an Azure project.

What it helps with

  • create a persistent AI agent in a Java project
  • send a message to an agent thread
  • start a run and inspect its status
  • read messages returned by an agent
  • remove an agent and thread after use

Example prompts for the agent

  • Show me how to connect PersistentAgentsClient to my Java project in Azure.
  • Create an agent, add a message to its thread, and read the response.
  • Handle RequiresAction, Failed, and Cancelled when an agent run finishes.

How to install azure-ai-agents-persistent-java

1Skills CLI (Vercel)

npx skills add microsoft/skills --skill azure-ai-agents-persistent-java -a claude-code

2Manually: put the files in place

~/.claude/skills/azure-ai-agents-persistent-java/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/azure-ai-agents-persistent-java/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about azure-ai-agents-persistent-java

How do I install azure-ai-agents-persistent-java in Claude Code?

Run npx skills add microsoft/skills --skill azure-ai-agents-persistent-java -a claude-code. The skill file is at ~/.claude/skills/azure-ai-agents-persistent-java/SKILL.md.

What does azure-ai-agents-persistent-java do?

It guides Java development with the Azure AI Agents Persistent SDK, including agent creation, message threads, runs, and responses.

Which environment variables are needed to connect to Azure?

Set PROJECT_ENDPOINT and MODEL_DEPLOYMENT_NAME. When production authentication uses DefaultAzureCredential, set AZURE_TOKEN_CREDENTIALS as well.

Source text

SKILL.md · MIT
---
name: azure-ai-agents-persistent-java
description: |
  Azure AI Agents Persistent SDK for Java. Low-level SDK for creating and managing AI agents with threads, messages, runs, and tools.
  Triggers: "PersistentAgentsClient", "persistent agents java", "agent threads java", "agent runs java", "streaming agents java".
license: MIT
metadata:
  author: Microsoft
  version: "1.0.0"
  package: com.azure:azure-ai-agents-persistent
---

# Azure AI Agents Persistent SDK for Java

Low-level SDK for creating and managing persistent AI agents with threads, messages, runs, and tools.

## Installation

```xml
<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-ai-agents-persistent</artifactId>
    <version>1.0.0-beta.1</version>
</dependency>
```

## Environment Variables

```bash
PROJECT_ENDPOINT=https://<resource>.services.ai.azure.com/api/projects/<project> # Required for project configuration
MODEL_DEPLOYMENT_NAME=gpt-4o-mini # Required for agent model selection
AZURE_TOKEN_CREDENTIALS=prod  # Required only if DefaultAzureCredential is used in production
```

## Authentication

```java
import com.azure.ai.agents.persistent.PersistentAgentsClient;
import com.azure.ai.agents.persistent.PersistentAgentsClientBuilder;
import com.azure.core.credential.TokenCredential;
import com.azure.identity.AzureIdentityEnvVars;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.identity.ManagedIdentityCredentialBuilder;

String endpoint = System.getenv("PROJECT_ENDPOINT");
TokenCredential credential = new DefaultAzureCredentialBuilder()
    .requireEnvVars(AzureIdentityEnvVars.AZURE_TOKEN_CREDENTIALS)
    .build();
// Or use a specific credential directly in production:
// See https://learn.microsoft.com/java/api/overview/azure/identity-readme?view=azure-java-stable#credential-classes
// TokenCredential credential = new ManagedIdentityCredentialBuilder().build();

PersistentAgentsClient client = new PersistentAgentsClientBuilder()
    .endpoint(endpoint)
    .credential(credential)
    .buildClient();
```

## Key Concepts

The Azure AI Agents Persistent SDK provides a low-level API for managing persistent agents that can be reused across sessions.

### Client Hierarchy

| Client | Purpose |
|--------|---------|
| `PersistentAgentsClient` | Sync client for agent operations |
| `PersistentAgentsAsyncClient` | Async client for agent operations |

## Core Workflow

### 1. Create Agent

```java
// Create agent with tools
PersistentAgent agent = client.createAgent(
    modelDeploymentName,
    "Math Tutor",
    "You are a personal math tutor."
);
```

### 2. Create Thread

```java
PersistentAgentThread thread = client.createThread();
```

### 3. Add Message

```java
client.createMessage(
    thread.getId(),
    MessageRole.USER,
    "I need help with equations."
);
```

### 4. Run Agent

```java
ThreadRun run = client.createRun(thread.getId(), agent.getId());

// Poll for completion
while (run.getStatus() == RunStatus.QUEUED || run.getStatus() == RunStatus.IN_PROGRESS) {
    Thread.sleep(500);
    run = client.getRun(thread.getId(), run.getId());
}
```

### 5. Get Response

```java
PagedIterable<PersistentThreadMessage> messages = client.listMessages(thread.getId());
for (PersistentThreadMessage message : messages) {
    System.out.println(message.getRole() + ": " + message.getContent());
}
```

### 6. Cleanup

```java
client.deleteThread(thread.getId());
client.deleteAgent(agent.getId());
```

## Best Practices

1. **Use DefaultAzureCredential** for production authentication
2. **Poll with appropriate delays** — 500ms recommended between status checks
3. **Clean up resources** — Delete threads and agents when done
4. **Handle all run statuses** — Check for RequiresAction, Failed, Cancelled
5. **Use async client** for better throughput in high-concurrency scenarios

## Error Handling

```java
import com.azure.core.exception.HttpResponseException;

try {
    PersistentAgent agent = client.createAgent(modelName, name, instructions);
} catch (HttpResponseException e) {
    System.err.println("Error: " + e.getResponse().getStatusCode() + " - " + e.getMessage());
}
```

## Reference Links

| Resource | URL |
|----------|-----|
| Maven Package | https://central.sonatype.com/artifact/com.azure/azure-ai-agents-persistent |
| GitHub Source | https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/ai/azure-ai-agents-persistent |

© Microsoft · MIT · microsoft/skills

Similar skills

All skills for Agent setup: memory, context, orchestration →

From the same set242

The whole set →
azure-ai-projects-java Equips your agent with Java SDK patterns for Azure AI Foundry, covering search index creation, connection listing, and model evaluations. ★ 3,149repo stars azure-ai-formrecognizer-java This skill guides Java work with Azure AI Document Intelligence, from extracting document text and tables to analyzing invoices and receipts. ★ 3,149repo stars azure-ai-contentsafety-java A skill that walks the agent through the Azure AI Content Safety SDK for Java: text and image analysis, blocklists, harm detection. ★ 3,149repo stars azure-ai-anomalydetector-java Guides assistants in writing Java code with the Azure AI Anomaly Detector SDK. Useful for streaming metric checks and multivariate time-series analysis. ★ 3,149repo stars azure-resource-manager-redis-dotnet A skill for provisioning and managing Azure Cache for Redis through Azure Resource Manager in .NET: caches, firewall rules, access keys, geo-replication. ★ 3,149repo stars azure-resource-manager-postgresql-dotnet Teaches AI agents to manage Azure PostgreSQL Flexible Server deployments in .NET. Generates C# code for server provisioning, firewall rules, and database setup. ★ 3,149repo stars azure-resource-manager-playwright-dotnet Manage Microsoft Playwright Testing workspaces through Azure Resource Manager. This skill covers resource operations, not running Playwright tests. ★ 3,149repo stars azure-resource-manager-durabletask-dotnet Guides the agent in provisioning Azure Durable Task Schedulers, Task Hubs, and retention rules via the .NET ARM SDK. Fits infrastructure automation workflows. ★ 3,149repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor