跳转到内容

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 schema
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 schema 和字段类型。

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",
});