azure-ai-agents-persistent-java – skill Lập trình cho agent AI
SDK Azure AI Agents Persistent cho Java. SDK cấp thấp để tạo và quản lý AI agent với thread, message, run và tool.
Cài skill azure-ai-agents-persistent-java bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-ai-agents-persistent-java-e4177.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /azure-ai-agents-persistent-java – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-ai-agents-persistent-java-e4177.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $azure-ai-agents-persistent-java – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-ai-agents-persistent-java-e4177.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /azure-ai-agents-persistent-java – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-ai-agents-persistent-java-e4177.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /azure-ai-agents-persistent-java – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
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.2</version>
</dependency>Environment Variables
export PROJECT_ENDPOINT="https://<resource>.services.ai.azure.com/api/projects/<project>"
export MODEL_DEPLOYMENT_NAME="gpt-4o-mini"Authentication
import com.azure.ai.agents.persistent.PersistentAgentsClient;
import com.azure.ai.agents.persistent.PersistentAgentsClientBuilder;
import com.azure.ai.agents.persistent.*;
import com.azure.ai.agents.persistent.models.*;
import com.azure.core.http.rest.PagedIterable;
import com.azure.identity.DefaultAzureCredentialBuilder;
String endpoint = System.getenv("PROJECT_ENDPOINT");
PersistentAgentsClient client = new PersistentAgentsClientBuilder()
.endpoint(endpoint)
.credential(new DefaultAzureCredentialBuilder().build())
.buildClient();
String modelDeploymentName = System.getenv("MODEL_DEPLOYMENT_NAME");
PersistentAgentsAdministrationClient administration = client.getPersistentAgentsAdministrationClient();
ThreadsClient threads = client.getThreadsClient();
MessagesClient messageClient = client.getMessagesClient();
RunsClient runs = client.getRunsClient();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
// Create agent with tools
PersistentAgent agent = administration.createAgent(
new CreateAgentOptions(modelDeploymentName)
.setName("Math Tutor")
.setInstructions("You are a personal math tutor.")
);2. Create Thread
PersistentAgentThread thread = threads.createThread();3. Add Message
messageClient.createMessage(
thread.getId(),
MessageRole.USER,
"I need help with equations."
);4. Run Agent
ThreadRun run = runs.createRun(new CreateRunOptions(thread.getId(), agent.getId()));
// Bound polling; a terminal non-success state is not a completed answer.
long deadline = System.nanoTime() + java.util.concurrent.TimeUnit.SECONDS.toNanos(60);
while (run.getStatus() == RunStatus.QUEUED || run.getStatus() == RunStatus.IN_PROGRESS) {
if (System.nanoTime() > deadline) {
throw new IllegalStateException("Run polling timed out; inspect/cancel the owned run separately");
}
Thread.sleep(500);
run = runs.getRun(thread.getId(), run.getId());
}Check the resulting status before reading a final response: requires_action needs an authorized tool-output handler; failed, cancelled, expired or other non-success states must be reported explicitly. A polling timeout does not cancel the cloud run.
5. Get Response
PagedIterable<ThreadMessage> messages = messageClient.listMessages(thread.getId());
for (ThreadMessage message : messages) {
System.out.println("Message role: " + message.getRole()); // Do not log retained prompt/response payloads.
}6. Cleanup
threads.deleteThread(thread.getId());
administration.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 exampleAgent = administration.createAgent(
new CreateAgentOptions(modelDeploymentName).setName("Example").setInstructions("Answer briefly"));
} 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 |
When to Use
Use when implementing or maintaining Java persistent-agent threads, messages, runs and administration with the preview SDK. The reviewed example uses beta.2 subclients, not direct CRUD methods on PersistentAgentsClient.
Limitations
- Operations create billable cloud resources, send prompts and retain thread data. Use an authorized project/model and explicit budgets; delete only resources created for the current run, preserve IDs on failure, and redact message/credential logs.
- Snippets are sequential fragments inside application code, not a standalone compiled program. API shape was checked against [Microsoft’s beta.2 sample](https://github.com/Azure/azure-sdk-for-java/blob/azure-ai-agents-persistent_1.0.0-beta.2/sdk/ai/azure-ai-agents-persistent/src/samples/java/com/azure/ai/agents/persistent/AgentBasicSample.java) and preview reference; no cloud run was performed. Add compatible azure-identity and required dependencies using the project’s reviewed Azure BOM.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
Skill liên quan
- azure-ai-formrecognizer-java – Xây dựng ứng dụng phân tích tài liệu bằng SDK Azure AI Document Intelligence cho Java.
- javascript-testing-patterns – Triển khai chiến lược kiểm thử toàn diện với Jest, Vitest và Testing Library cho unit…
- winui-app – Khởi tạo, phát triển và thiết kế ứng dụng desktop WinUI 3 hiện đại bằng C# và Windows…
- github – GitHub qua CLI gh: PR, issue, review, repo, xác thực.
- literature-review – Thực hiện tổng quan tài liệu có hệ thống, phạm vi và tường thuật bằng PubMed, arXiv…
- azure-ai-projects-java – SDK Azure AI Projects cho Java. SDK cấp cao quản lý dự án Azure AI Foundry gồm…
- yeet – Chỉ dùng khi người dùng yêu cầu rõ ràng stage, commit, push và mở pull request trên…
- hunt-nodejs – Săn các lỗ hổng đặc thù Node.js — chuỗi Prototype Pollution → RCE (lodash/merge/assign)…