Chuyển đến nội dung

AI Agent

client.aiAgent (TypeScript) / client.ai_agent (Python) cung cấp chat streaming, quản lý embedding, sinh parquet, và distributed tracing cho AI agents.

Để xem hướng dẫn chi tiết, tham khảo AI Agent trong SDK guide.


Schema

StreamChatBody

Tham số để khởi tạo một phiên chat streaming.

FieldTypeRequiredMô tả
assistant_idstringID của AI agent để chat
messagesarrayLịch sử hội thoại (cặp role + content)
idstringID phiên chat có sẵn để tiếp tục
model_idstringGhi đè mô hình LLM mặc định của agent
provider_idstringGhi đè nhà cung cấp LLM mặc định của agent
user_idstringĐịnh danh người dùng bên ngoài

StreamSubAgentChatBody

FieldTypeRequiredMô tả
assistant_idstringID của AI agent
session_idstringID phiên cha
chat_idstringID chat trong phiên
messagesarrayTin nhắn hội thoại

Methods

MethodTypeScriptPythonMô tả
Stream chatstreamChatstream_chatBắt đầu phiên chat streaming với AI agent
Stream sub-agent chatstreamSubAgentChatstream_sub_agent_chatStreaming chat trong phạm vi phiên sub-agent
Get sub-agent historygetSubAgentHistoryget_sub_agent_historyLấy lịch sử tin nhắn của sub-agent chat
List chatslistChatslist_chatsDanh sách phiên chat của tổ chức
Get chatgetChatget_chatLấy một phiên chat
Delete chatdeleteChatdelete_chatXóa một phiên chat
Prompt suggestionsgetAgentPromptSuggestionget_agent_prompt_suggestionLấy gợi ý prompt cho agent
Classify fileclassifyFileclassify_filePhân loại file vào danh mục
Suggest field typessuggestFieldTypessuggest_field_typesGợi ý JSON schema từ tài liệu mẫu
Process embeddingprocessEmbeddingprocess_embeddingNhúng file vào kho tri thức
List embedding fileslistEmbeddingFileslist_embedding_filesDanh sách các file đã nhúng
Get embedding filegetEmbeddingFileget_embedding_fileLấy một file đã nhúng
Preview embedding filepreviewEmbeddingFilepreview_embedding_fileXem trước nội dung đã nhúng
Update embedding statusupdateEmbeddingFileStatusupdate_embedding_file_statusCập nhật trạng thái nhúng file
Delete embedding filedeleteEmbeddingFiledelete_embedding_fileXóa file khỏi kho tri thức
Generate parquetgenerateParquetgenerate_parquetChuyển đổi mảng dữ liệu thành file parquet
List parquet fileslistParquetFileslist_parquet_filesDanh sách file parquet đã sinh
Delete parquet filedeleteParquetFiledelete_parquet_fileXóa file parquet theo tên
Get tracesgetTracesget_tracesTruy vấn distributed traces
Get tracegetTraceget_traceLấy một trace theo ID
Get trace servicesgetTraceServicesget_trace_servicesDanh sách dịch vụ phát ra traces

streamChat / stream_chat

Bắt đầu chat streaming với AI agent. Trả về HTTP response thô — lặp qua stream để đọc các SSE chunks.

const response = await client.aiAgent.streamChat({
assistant_id: "agent_id",
messages: [{ role: "user", content: "Hello" }],
user_id: "user_123",
});
const reader = response.body?.getReader();
const decoder = new TextDecoder();
while (reader) {
const { done, value } = await reader.read();
if (done) break;
console.log(decoder.decode(value));
}

streamSubAgentChat / stream_sub_agent_chat

Stream chat trong phạm vi sub-agent trong một phiên cha.

const response = await client.aiAgent.streamSubAgentChat({
assistant_id: "agent_id",
session_id: "session_id",
chat_id: "chat_id",
messages: [{ role: "user", content: "Follow-up question" }],
});

listChats / list_chats

const { data: chats } = await client.aiAgent.listChats({
organization_id: "org_id",
user_id: "user_123",
limit: 20,
});

getSubAgentHistory / get_sub_agent_history

const history = await client.aiAgent.getSubAgentHistory({
session_id: "session_id",
chat_id: "chat_id",
});

processEmbedding / process_embedding

Nhúng file vào kho tri thức của agent.

const result = await client.aiAgent.processEmbedding({
fileId: "file_id",
options: { chunk_size: 512 },
});

classifyFile / classify_file

Phân loại file vào danh mục định sẵn dựa trên nội dung.

const result = await client.aiAgent.classifyFile({ fileId: "file_id" });
console.log(result.category);

suggestFieldTypes / suggest_field_types

Phân tích tài liệu mẫu và gợi ý JSON schema với kiểu dữ liệu cho trích xuất tài liệu.

const schema = await client.aiAgent.suggestFieldTypes({
fileUrls: ["https://example.com/invoice.pdf"],
});
console.log(schema);

previewEmbeddingFile / preview_embedding_file

Xem trước nội dung của file đã nhúng trước khi xử lý.

const preview = await client.aiAgent.previewEmbeddingFile({ fileId: "file_id" });
console.log(preview);

updateEmbeddingFileStatus / update_embedding_file_status

Cập nhật trạng thái xử lý của một file nhúng.

const result = await client.aiAgent.updateEmbeddingFileStatus("file_id", "completed");
console.log(result);

generateParquet / generate_parquet

Chuyển đổi mảng bản ghi thành file parquet để nhập dữ liệu có cấu trúc.

const result = await client.aiAgent.generateParquet({
data: [{ name: "Alice", score: 95 }, { name: "Bob", score: 87 }],
fileName: "scores",
folderName: "results",
});

getTraces / get_traces

Truy vấn distributed traces để debug và quan sát.

const traces = await client.aiAgent.getTraces({
service: "ai-agent",
limit: 50,
timeRange: 3600,
orgId: "org_id",
});