azure-ai-agents-persistent-java

SDK persistente de Azure AI Agents para Java. SDK de bajo nivel para crear y gestionar agentes de IA con hilos, mensajes, ejecuciones y herramientas. Disparadores: "PersistentAgentsClient", "persistent agents java", "agent threads java", "agent runs java", "streaming agents java".

npx skills add https://github.com/microsoft/skills --skill azure-ai-agents-persistent-java

Azure AI Agents Persistent SDK for Java

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

Installation

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

Environment Variables

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

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

ClientPurpose
PersistentAgentsClientSync client for agent operations
PersistentAgentsAsyncClientAsync client for agent operations

Core Workflow

1. Create Agent

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

2. Create Thread

PersistentAgentThread thread = client.createThread();

3. Add Message

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

4. Run Agent

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

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

6. Cleanup

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

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

ResourceURL
Maven Packagehttps://central.sonatype.com/artifact/com.azure/azure-ai-agents-persistent
GitHub Sourcehttps://github.com/Azure/azure-sdk-for-java/tree/main/sdk/ai/azure-ai-agents-persistent

Más skills de microsoft

a365-code-validator
microsoft
Valida y opcionalmente corrige el código de observabilidad de Agent 365 para que un agente emita realmente telemetría de Actividad MAC. Úsalo cuando la telemetría de un agente de Agent 365 no esté…
a365-setup
microsoft
Punto de entrada para el registro general de Agent 365 (A365) y la configuración de CLI — usa esta habilidad cada vez que el usuario quiera "configurar A365", "registrar agente", "crear…
aca-sandboxes
microsoft
Use when the user wants to create, manage, or operate Azure Container Apps sandboxes — hardware-isolated microVMs driven by the `aca` CLI. USE FOR: create…
accessibility
microsoft
Habilidad principal de accesibilidad para VS Code. REQUERIDA para trabajo en nuevas funciones y contribuciones, y también aplica a actualizaciones de la interfaz de usuario existente. Cubre ayuda de accesibilidad…
accessibility
microsoft
Punto de entrada consolidado de habilidades de accesibilidad para WCAG 2.2, Prácticas de Autoría ARIA, accesibilidad cognitiva, Sección 508, EN 301 549 y la Accesibilidad…
accessibility-aria-expert
microsoft
Detecta y corrige problemas de accesibilidad en vistas web de React/Fluent UI. Úsalo al revisar código para compatibilidad con lectores de pantalla, corregir etiquetas ARIA, garantizar…
action-item-extractor
microsoft
Extraer elementos de acción con responsables, fechas límite y prioridades del contenido de la reunión
activate-site
microsoft
Verificación del plugin: Ejecuta node "${CLAUDE_PLUGIN_ROOT}/scripts/check-version.js" — si genera un mensaje, muéstralo al usuario antes de continuar.