# SnowflakeCortexAgent

> **Class** in `langchain_snowflake`

📖 [View in docs](https://reference.langchain.com/python/langchain-snowflake/agents/base/SnowflakeCortexAgent)

Snowflake Cortex Agent integration with thread management and feedback.

This class provides access to Snowflake's Cortex Agents REST API, enabling
managed orchestration of multiple tools with conversation management.

## Signature

```python
SnowflakeCortexAgent(
    self,
    **kwargs = {},
)
```

## Description

**Setup:**

Install ``langchain-snowflake`` and configure Snowflake connection.

.. code-block:: bash

    pip install -U langchain-snowflake

**Key init args:**

name: str
    Name of the Cortex Agent in Snowflake
database: str
    Database containing the agent
schema: str
    Schema containing the agent
session: Optional[Session]
    Active Snowflake session
auto_create_threads: bool
    Whether to automatically create threads (default: True)

**Instantiate:**

.. code-block:: python

from langchain_snowflake import SnowflakeCortexAgent

agent = SnowflakeCortexAgent(
    name="sales_assistant",
    database="sales_db",
    schema="analytics",
    session=session
)

**Direct Usage:**

.. code-block:: python

# Basic execution
response = agent.invoke("What were Q3 sales trends?")

# With thread management
thread_id = agent.create_thread(metadata={"customer": "ACME"})
response = agent.invoke_with_thread("Show ACME sales", thread_id)

# Check usage
usage = agent.last_usage
print(f"Tokens used: {usage['total_tokens']}")

# Submit feedback
from langchain_snowflake.agents.schemas import FeedbackInput
feedback = FeedbackInput(
    request_id=response["run_id"],
    positive=True,
    feedback_message="Good analysis",
    categories=["accuracy"]
)
agent.submit_feedback(feedback)

**Async Usage:**

.. code-block:: python

# Async execution
response = await agent.ainvoke("What were Q3 sales trends?")

# Async streaming
async for chunk in agent.astream("Generate sales report"):
    print(chunk, end="", flush=True)

## Extends

- `Runnable`
- `SnowflakeConnectionMixin`
- `AgentManagement`
- `ThreadManagement`
- `RunManagement`
- `FeedbackManagement`

## Constructors

```python
__init__(
    self,
    **kwargs = {},
)
```


## Properties

- `name`
- `database`
- `sf_schema`
- `auto_create_threads`
- `track_usage`
- `session`
- `account`
- `user`
- `password`
- `token`
- `private_key_path`
- `private_key_passphrase`
- `warehouse`
- `request_timeout`
- `verify_ssl`
- `respect_session_timeout`
- `last_usage`
- `last_run_id`

## Methods

- [`invoke()`](https://reference.langchain.com/python/langchain-snowflake/agents/base/SnowflakeCortexAgent/invoke)
- [`ainvoke()`](https://reference.langchain.com/python/langchain-snowflake/agents/base/SnowflakeCortexAgent/ainvoke)
- [`invoke_with_thread()`](https://reference.langchain.com/python/langchain-snowflake/agents/base/SnowflakeCortexAgent/invoke_with_thread)
- [`stream()`](https://reference.langchain.com/python/langchain-snowflake/agents/base/SnowflakeCortexAgent/stream)
- [`astream()`](https://reference.langchain.com/python/langchain-snowflake/agents/base/SnowflakeCortexAgent/astream)

---

[View source on GitHub](https://github.com/langchain-ai/langchain-snowflake/blob/1a32a1c6642b6c453e9537f35afbc7da280f8679/libs/snowflake/langchain_snowflake/agents/base.py#L25)