Chuyển đến nội dung
Skillpedia
Agent48k · #3878

azure-ai-agents-persistent-java

Skill này làm gì

Đây là bộ công cụ dành cho lập trình viên Java để tạo và quản lý agent AI có khả năng ghi nhớ các cuộc trò chuyện trước đó. Nó cho phép agent có “bộ nhớ” và tiếp tục các cuộc đối thoại.

Khi nào nên dùng

  • ✓Khi bạn muốn chatbot nhớ những gì đã nói trước đó.
  • ✓Khi bạn tạo trợ lý ảo cần duy trì ngữ cảnh hội thoại.
  • ✓Khi bạn phát triển ứng dụng mà AI cần tương tác liên tục.

Liên kết skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/azure-ai-agents-persistent-java/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/azure-ai-agents-persistent-java/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Làm thế nào để tạo một agent AI nhớ các cuộc trò chuyện trước đây của chúng ta bằng Java?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Bạn dùng mã đặc biệt (SDK) trong Java để chỉ cho hệ thống cách tạo agent, bắt đầu cuộc trò chuyện (thread), gửi tin nhắn và nhận phản hồi. Hệ thống quản lý “bộ nhớ” của agent cho bạn.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết 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.getRole() + ": " + message.getContent());
}

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

…

Câu hỏi thường gặp

“Threads”, “messages” và “runs” là gì?

“Threads” là các cuộc trò chuyện. “Messages” là những gì bạn và agent nói. “Runs” là các lần agent xử lý tin nhắn để tạo phản hồi.

Tôi có cần biết nhiều về AI để dùng công cụ này không?

Bộ công cụ này dành cho lập trình viên. Nó đơn giản hóa việc dùng AI, nhưng bạn vẫn cần biết lập trình Java.

Điều gì xảy ra nếu chương trình gặp lỗi?

Hệ thống có thể hiển thị thông báo lỗi. Quan trọng là kiểm tra trạng thái của từng thao tác và dọn dẹp các tài nguyên đã tạo để tránh chi phí không cần thiết.

Chi tiết

Mô tả gốc của tác giả

Azure AI Agents Persistent SDK for Java. Low-level SDK for creating and managing AI agents with threads, messages, runs, and tools.

repo: sickn33/agentic-awesome-skills

Độ phổ biến

Sao GitHub
48k
Vị trí xếp hạng
#3878
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự