CortexAgentManager
CortexAgentManager( session: snowpark.Session, config: DeploymentConfig, host: Optional[str] = None)Deploy and manage Cortex AI agents powered by RAI semantic models.
Handles the full lifecycle of a Snowflake Cortex agent that powers a Snowflake Intelligence (SI) experience. Non-technical SI users interact with the agent through the SI UI; this class is for the deployer/admin who creates and maintains the agent behind it.
Parameters
(sessionsnowflake.snowpark.Session) - Authenticatedsnowpark.Sessionwith access to the target database and schema.
(configDeploymentConfig) - Configuration specifying where and how to deploy the agent.
(hoststr, default:None) - Override for the Cortex REST API base URL. Accepts a bare hostname (e.g.amd01.east-us-2.azure.snowflakecomputing.com) or a full URL with scheme. When omitted, the host is derived from the Snowflake connection. Use this when the auto-detected host isn’t reachable (e.g. unusual regional/PrivateLink setups).
Examples
session = create_config().get_session(SnowflakeConnection)manager = CortexAgentManager( session=session, config=DeploymentConfig( agent_name="EXAMPLE_CORTEX", database="EXAMPLE", schema="CORTEX", warehouse="DEMOWAREHOUSE", ),)
def init_tools(model): init_model(model) return ToolRegistry().add(model=model, description="Customers and orders")
manager.deploy(init_tools=init_tools, imports=discover_imports())Methods
.preflight()
CortexAgentManager.preflight() -> PreflightReportProbe Snowflake for required objects and grants without deploying.
Runs the same set of read-only checks that deploy() runs
before attempting to create resources. Use this to surface every
missing grant up front and hand a single fix-list to a Snowflake
admin, instead of round-tripping one error at a time.
Returns:
PreflightReport- A report whoseerrorslist collects blocking issues and whoseformat(config=manager.config)renders a paste-ready diagnostic with a SQL fix block.
Referenced By:
RelationalAI Documentation └── Release Notes └── Python API Release Notes └── What’s New in Version 1.2.2 └── New Features and Enhancements
.print_setup_sql()
CortexAgentManager.print_setup_sql( deployer_role: str = "<your_role>", si_role: Optional[str] = None, create_role: bool = False,) -> strReturn a copy-pasteable SQL block granting the required privileges.
The block matches the privilege table in the Cortex skill but is parameterized with this manager’s actual database, schema, warehouse, agent_schema, and external_access_integration.
Parameters:
(deployer_rolestr, default:“<your_role>”) - Name of the deployer role. Defaults to a placeholder so callers can render a template.
(si_rolestr, default:None) - If given, also emit the SI-user GRANT block. Default: just the deployer block.
(create_rolebool, default:False) - PrependCREATE ROLE IF NOT EXISTSfor each role.
Returns:
str- A SQL block ready to paste into a Snowflake worksheet.
Referenced By:
RelationalAI Documentation └── Release Notes └── Python API Release Notes └── What’s New in Version 1.2.2 └── New Features and Enhancements
.deploy()
CortexAgentManager.deploy( init_tools: Callable, imports: List[Tuple[str, str]], base_agent_spec: Optional[CortexAgentApi.AgentSpec] = None, extra_packages: Optional[List[str]] = None,) -> CortexAgentApi.AgentSpecDeploy the agent and all required Snowflake resources.
Creates a stage (if manage_stage=True), registers RAI tool stored
procedures, and deploys the Cortex agent. On failure, attempts cleanup
of partially deployed resources before raising.
Parameters:
-
(init_toolsCallable) - Callable returning aToolRegistry. Two forms are supported:Recommended (0-param): Import your model definition code inside the function body. The import must happen inside
init_toolsso theModelis created within the sproc’s active Snowpark session:def init_tools():from myproject.model import corereturn ToolRegistry().add(model=core.model, description='...')Legacy (1-param): Accept a
Modelfrom the framework:def init_tools(model):return ToolRegistry().add(model=model, description='...') -
(importslist of tuple of (str, str)) - Project code to upload to Snowflake. Usediscover_imports()for automatic recursive discovery. Format: list of(source_path, module_name)tuples. -
(base_agent_specrelationalai.agent.cortex.api.agent.CortexAgentApi.AgentSpec, default:None) - Base agent spec to extend with RAI tools. Default:None(creates a new spec). -
(extra_packageslist of str, default:None) - Additional PyPI packages for the sproc environment.relationalaiis included automatically.
Returns:
relationalai.agent.cortex.api.agent.CortexAgentApi.AgentSpec- The deployed agent specification.
Raises:
RAIException- If deployment fails at any stage.
.update()
CortexAgentManager.update( init_tools: Callable, imports: List[Tuple[str, str]], extra_packages: Optional[List[str]] = None,) -> CortexAgentApi.AgentSpecUpdate the agent’s tools without recreating the agent.
Recreates stored procedures with updated tool definitions and updates the agent configuration in Cortex. The agent name and identity are preserved; existing SI conversations are unaffected.
Parameters:
(init_toolsCallable) - Updated callable returning aToolRegistry. Same contract asdeploy()— supports both 0-param (recommended) and 1-param (legacy) forms.
(importslist of tuple of (str, str)) - Updated project code. Usediscover_imports().
(extra_packageslist of str, default:None) - Updated PyPI package list.
Returns:
relationalai.agent.cortex.api.agent.CortexAgentApi.AgentSpec- Updated agent specification.
Raises:
RAIException- If agent is not deployed (calldeploy()first).
.chat()
CortexAgentManager.chat() -> CortexAgentChatGet a programmatic chat interface for the deployed agent.
Returns a CortexAgentChat that maintains conversation state across
multiple send() calls. This is primarily useful for testing and
automation — SI users interact through the Snowflake Intelligence UI.
Returns:
CortexAgentChat- Chat interface instance.
Raises:
RAIException- If agent is not deployed (calldeploy()first).
.status()
CortexAgentManager.status() -> DeploymentStatusCheck deployment status of all agent components.
Queries Snowflake and Cortex to verify existence of the agent, stage, and all stored procedures.
Returns:
DeploymentStatus- Usefully_deployed(),partially_deployed(), orclean()for quick checks.
.cleanup()
CortexAgentManager.cleanup(silent: bool = True) -> NoneRemove all agent resources from Snowflake and Cortex.
Deletes the Cortex agent, all RAI tool stored procedures, and the
stage (if manage_stage=True). SI conversation history is
permanently lost.
Parameters:
(silentbool, default:True) - Ignore errors for non-existent resources. Default:True.
Returns:
-
None
Referenced By
RelationalAI Documentation └── Release Notes └── Python API Release Notes └── What’s New in Version 1.2.2 └── New Features and Enhancements