Skip to content

CortexAgentChat

relationalai.agent.cortex.chat
CortexAgentChat(
client: httpx.Client,
name: str,
db="SNOWFLAKE_INTELLIGENCE",
schema="AGENTS",
app_name="",
)

High-level client for conversing with deployed Cortex agents.

Provides a simple interface for interacting with agents defined in Snowflake. The agent handles tool execution server-side, manages conversation state through threads, and you simply send messages and receive structured responses.

  • client

    (httpx.Client) - Configured httpx.Client with authentication headers.
  • name

    (str) - Agent name to interact with.
  • db

    (str, default: “SNOWFLAKE_INTELLIGENCE”) - Database name. Default: "SNOWFLAKE_INTELLIGENCE".
  • schema

    (str, default: “AGENTS”) - Schema name. Default: "AGENTS".
  • app_name

    (str, default: "") - Optional application identifier for thread grouping.
>>> chat = CortexAgentChat(client=client, name="my_agent")
>>> response = chat.send("What can I ask about?")
>>> print(response.full_text())
CortexAgentChat.config() -> dict

Retrieve the agent’s configuration.

Fetches the complete agent specification from the API and returns it as a dictionary.

Returns:

  • dict - Dictionary containing agent name and cortex_agent specification.

Raises:

  • AssertionError - If agent_spec is not present in the response.
  • httpx.HTTPStatusError - If the API request fails.
CortexAgentChat.send(prompt: str) -> ChatResponse

Send a message to the agent and get the response.

Creates a thread if this is the first message, then sends the prompt to the agent and returns the complete response including any tool calls and results. Automatically maintains conversation context across multiple send() calls.

Parameters:

  • prompt

    (str) - User message to send to the agent.

Returns:

  • ChatResponse - The agent’s reply including tool interactions.

Raises:

  • httpx.HTTPStatusError - If the API request fails.
  • AssertionError - If the response doesn’t contain expected content.
CortexAgentChat.thread_id() -> int

Get the current thread ID, creating one if necessary.

Returns:

  • int - Thread ID for this conversation.
CortexAgentChat.messages() -> List

Retrieve all messages from the current conversation thread.

Fetches the complete message history from the server, including both user and assistant messages. Messages are returned in descending order (newest first) by default.

Returns:

  • list of CortexThreadApi.Message - Conversation history.

Raises:

  • RAIException - If no thread exists yet (call send() first).
  • httpx.HTTPStatusError - If the API request fails.