azure-ai-agents-persistent-java
microsoft/skills
Crea y gestiona agentes de IA persistentes con subprocesos, mensajes, ejecuciones y herramientas mediante el SDK de Azure para Java.
...Expandir todoSDK persistente de Azure AI Agents para Java
SDK de bajo nivel para crear y gestionar agentes de IA persistentes con subprocesos, mensajes, ejecuciones y herramientas.
Instalación
com.azure
azure-ai-agents-persistent
1.0.0-beta.1
Variables de entorno
PROJECT_ENDPOINT=https://.services.ai.azure.com/api/projects/ # Necesario para la configuración del proyecto
MODEL_DEPLOYMENT_NAME=gpt-4o-mini # Necesario para la selección del modelo del agente
AZURE_TOKEN_CREDENTIALS=prod # Solo es necesario si se utiliza DefaultAzureCredential en producción
Autenticación
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();
// O bien, utiliza una credencial específica directamente en producción:
// Consulta 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();
Conceptos clave
El SDK persistente de Azure AI Agents proporciona una API de bajo nivel para gestionar agentes persistentes que pueden reutilizarse en diferentes sesiones.
Jerarquía de clientes
| Cliente | Finalidad |
|---|---|
PersistentAgentsClient |
Cliente de sincronización para operaciones de agentes |
PersistentAgentsAsyncClient |
Cliente asíncrono para operaciones de agente |
Flujo de trabajo principal
1. Crear agente
// Crear agente con herramientas
PersistentAgent agent = client.createAgent(
modelDeploymentName,
"Tutor de matemáticas",
"Eres un tutor personal de matemáticas."
);
2. Crear un hilo
PersistentAgentThread thread = client.createThread();
3. Añadir mensaje
client.createMessage(
thread.getId(),
MessageRole.USER,
"Necesito ayuda con las ecuaciones."
);
4. Ejecutar el agente
ThreadRun run = client.createRun(thread.getId(), agent.getId());
// Comprobar si se ha completado
while (run.getStatus() == RunStatus.QUEUED || run.getStatus() == RunStatus.IN_PROGRESS) {
Thread.sleep(500);
run = client.getRun(thread.getId(), run.getId());
}
5. Obtener respuesta
PagedIterable messages = client.listMessages(thread.getId());
for (PersistentThreadMessage message : messages) {
System.out.println(message.getRole() + ": " + message.getContent());
}
6. Limpieza
client.deleteThread(thread.getId());
client.deleteAgent(agent.getId());
Prácticas recomendadas
- Utiliza DefaultAzureCredential para la autenticación en producción
- Realiza sondeos con los retrasos adecuados — se recomiendan 500 ms entre comprobaciones de estado
- Limpia los recursos: elimina los hilos y los agentes cuando hayas terminado
- Gestiona todos los estados de ejecución: comprueba si hay «RequiresAction», «Failed» o «Cancelled»
- Utilizar un cliente asíncrono para obtener un mejor rendimiento en escenarios de alta concurrencia
Gestión de errores
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());
}
Enlaces de referencia
| Recurso | URL |
|---|---|
| Paquete Maven | https://central.sonatype.com/artifact/com.azure/azure-ai-agents-persistent |
| Código fuente en GitHub | https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/ai/azure-ai-agents-persistent |
---
name: azure-ai-agents-persistent-java
description: Create and manage persistent AI agents with threads, messages, runs, and tools using the Azure SDK for Java.
license: MIT
---
# 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 |
Todos los archivos
0 archivosInstalar azure-ai-agents-persistent-java
Descarga y descomprime los archivos de las habilidades en tu directorio .claude/skills/.
Descargar ZIPClona el repositorio y copia los archivos de la habilidad a tu proyecto.
git clone https://github.com/microsoft/skills/tree/main/.github/plugins/azure-sdk-java/skills/azure-ai-agents-persistent-java # Copy SKILL.md to your .claude/skills/ directory
Copiar





Hogar
