跳到內容

AI Agent

client.aiAgent (TypeScript) / client.ai_agent (Python) 提供聊天串流、嵌入管理、parquet 生成與 AI 代理的分散式追蹤。

如需逐步指南,請參閱 SDK 指南中的 AI Agent


Schema

StreamChatBody

初始化串流聊天會話的參數。

FieldTypeRequired說明
assistant_idstring要聊天的 AI 代理 ID
messagesarray對話歷史記錄(role + content 成對)
idstring要繼續的現有聊天會話 ID
model_idstring覆寫代理的預設 LLM 模型
provider_idstring覆寫代理的預設 LLM 提供者
user_idstring外部使用者識別碼

StreamSubAgentChatBody

FieldTypeRequired說明
assistant_idstringAI 代理 ID
session_idstring父會話 ID
chat_idstring會話中的聊天 ID
messagesarray對話訊息

Methods

MethodTypeScriptPython說明
Stream chatstreamChatstream_chat與 AI 代理開始串流聊天會話
Stream sub-agent chatstreamSubAgentChatstream_sub_agent_chat在子代理會話範圍內進行串流聊天
Get sub-agent historygetSubAgentHistoryget_sub_agent_history擷取子代理聊天的訊息歷史
List chatslistChatslist_chats列出組織的聊天會話
Get chatgetChatget_chat取得單一聊天會話
Delete chatdeleteChatdelete_chat刪除聊天會話
Prompt suggestionsgetAgentPromptSuggestionget_agent_prompt_suggestion取得代理的建議提示
Classify fileclassifyFileclassify_file將檔案分類至類別
Suggest field typessuggestFieldTypessuggest_field_types從範例文件建議 JSON 結構
Process embeddingprocessEmbeddingprocess_embedding將檔案嵌入知識庫
List embedding fileslistEmbeddingFileslist_embedding_files列出所有已嵌入的檔案
Get embedding filegetEmbeddingFileget_embedding_file取得單一已嵌入的檔案
Preview embedding filepreviewEmbeddingFilepreview_embedding_file預覽已嵌入的內容
Update embedding statusupdateEmbeddingFileStatusupdate_embedding_file_status更新檔案嵌入狀態
Delete embedding filedeleteEmbeddingFiledelete_embedding_file從知識庫移除檔案
Generate parquetgenerateParquetgenerate_parquet將資料陣列轉換為 parquet 檔案
List parquet fileslistParquetFileslist_parquet_files列出已生成的 parquet 檔案
Delete parquet filedeleteParquetFiledelete_parquet_file依名稱刪除 parquet 檔案
Get tracesgetTracesget_traces查詢分散式追蹤
Get tracegetTraceget_trace依 ID 取得單一追蹤
Get trace servicesgetTraceServicesget_trace_services列出發出追蹤的服務

streamChat / stream_chat

與 AI 代理開始串流聊天。傳回原始 HTTP 回應 — 迭代串流以讀取 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

在父會話內對子代理進行範圍限定串流聊天。

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

將檔案嵌入代理的知識庫。

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

classifyFile / classify_file

根據檔案內容將其分類至預定義類別。

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

suggestFieldTypes / suggest_field_types

分析範例文件並建議用於文件擷取的 JSON 結構與欄位類型。

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

previewEmbeddingFile / preview_embedding_file

在處理前預覽已嵌入檔案的內容。

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

updateEmbeddingFileStatus / update_embedding_file_status

更新嵌入檔案的處理狀態。

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

generateParquet / generate_parquet

將記錄陣列轉換為 parquet 檔案以進行結構化資料導入。

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

getTraces / get_traces

查詢分散式追蹤以進行除錯和可觀測性。

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