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.
npx skills add microsoft/skills --skill azure-ai-agents-persistent-java -a claude-codeWhat 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
PersistentAgentsClientto my Java project in Azure. - Create an agent, add a message to its thread, and read the response.
- Handle
RequiresAction,Failed, andCancelledwhen 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-code2Manually: put the files in place
~/.claude/skills/azure-ai-agents-persistent-java/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/azure-ai-agents-persistent-java/
Manually: put the files in place
.agents/skills/azure-ai-agents-persistent-java/SKILL.mdFor all projects use ~/.agents/skills/
Manually: put the files in place
.cursor/skills/azure-ai-agents-persistent-java/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install microsoft/skills azure-ai-agents-persistent-java2Manually: put the files in place
.github/skills/azure-ai-agents-persistent-java/SKILL.mdPlatform CLI
gemini skills install https://github.com/microsoft/skills --path .github/plugins/azure-sdk-java/skills/azure-ai-agents-persistent-javaManually: put the files in place
.devin/skills/azure-ai-agents-persistent-java/SKILL.mdThe legacy .windsurf/skills/ path still works
Claude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
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