Skip to content

AI Agent

client.aiAgent (TypeScript) / client.ai_agent (Python) provides chat streaming, embedding management, parquet generation, and distributed tracing for AI agents.

For a guided walkthrough, see AI Agent in the SDK guide.


Schema

StreamChatBody

Parameters for initiating a streaming chat session.

FieldTypeRequiredDescription
assistant_idstringID of the AI agent to chat with
messagesarrayConversation history (role + content pairs)
idstringExisting chat session ID to continue
model_idstringOverride the agent’s default LLM model
provider_idstringOverride the agent’s default LLM provider
user_idstringExternal user identifier

StreamSubAgentChatBody

FieldTypeRequiredDescription
assistant_idstringID of the AI agent
session_idstringParent session ID
chat_idstringChat ID within the session
messagesarrayConversation messages

Methods

MethodTypeScriptPythonDescription
Stream chatstreamChatstream_chatStart a streaming chat session with an AI agent
Stream sub-agent chatstreamSubAgentChatstream_sub_agent_chatStreaming chat scoped to a sub-agent session
Get sub-agent historygetSubAgentHistoryget_sub_agent_historyRetrieve message history for a sub-agent chat
List chatslistChatslist_chatsList chat sessions for an organization
Get chatgetChatget_chatGet a single chat session
Delete chatdeleteChatdelete_chatDelete a chat session
Prompt suggestionsgetAgentPromptSuggestionget_agent_prompt_suggestionGet suggested prompts for an agent
Classify fileclassifyFileclassify_fileClassify a file into a category
Suggest field typessuggestFieldTypessuggest_field_typesSuggest JSON schema from sample documents
Process embeddingprocessEmbeddingprocess_embeddingEmbed a file into the knowledge base
List embedding fileslistEmbeddingFileslist_embedding_filesList all embedded files
Get embedding filegetEmbeddingFileget_embedding_fileGet a single embedded file
Preview embedding filepreviewEmbeddingFilepreview_embedding_filePreview embedded content
Update embedding statusupdateEmbeddingFileStatusupdate_embedding_file_statusUpdate file embedding status
Delete embedding filedeleteEmbeddingFiledelete_embedding_fileRemove a file from the knowledge base
Generate parquetgenerateParquetgenerate_parquetConvert data array to a parquet file
List parquet fileslistParquetFileslist_parquet_filesList generated parquet files
Delete parquet filedeleteParquetFiledelete_parquet_fileDelete a parquet file by name
Get tracesgetTracesget_tracesQuery distributed traces
Get tracegetTraceget_traceGet a single trace by ID
Get trace servicesgetTraceServicesget_trace_servicesList services emitting traces

streamChat / stream_chat

Start a streaming chat with an AI agent. Returns a raw HTTP response — iterate over the stream to read 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 a chat scoped to a sub-agent within a parent session.

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

Embed a file into the agent’s knowledge base.

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

classifyFile / classify_file

Classify a file into a predefined category based on its content.

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

suggestFieldTypes / suggest_field_types

Analyze sample documents and suggest a JSON schema with field types for document extraction.

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

previewEmbeddingFile / preview_embedding_file

Preview the content of an embedded file before processing.

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

updateEmbeddingFileStatus / update_embedding_file_status

Update the processing status of an embedding file.

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

generateParquet / generate_parquet

Convert an array of records into a parquet file for structured data ingestion.

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

getTraces / get_traces

Query distributed traces for debugging and observability.

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