Snowflake-Labs / orchestration-framework

A multi-agent framework with native support for Snowflake services
Apache License 2.0
8 stars 3 forks source link

ENH: Review database/schema usage on tool configuration #46

Open sfc-gh-twhite opened 1 week ago

sfc-gh-twhite commented 1 week ago
# Cortex Analyst Config
analyst_config = {
    "semantic_model": "sp500_semantic_model.yaml",
    "stage": "ANALYST",
    "service_topic": "S&P500 company and stock metrics",
    "data_description": "a table with stock and financial metrics about S&P500 companies ",
    "snowflake_connection": session,
}

sp500 = CortexAnalystTool(**analyst_config)

If the user was to fully qualify the STAGE, such as "stage": "CUBE_TESTING.PUBLIC.ANALYST", we hit an unhandled exception: Caught unhandled exception: Unexpected error during Cortex gateway Tool request: Stage CUBE_TESTING.PUBLIC.CUBE_TESTING.PUBLIC.ANALYST does not exist or is not authorized.

We need to either document this behavior or internally handle the cases where a user fully qualifies the stage.

I suspect this will have implications on using tools when the connection context changes.

sfc-gh-twhite commented 4 days ago

This presents a situation where a user may use a different database or schema and will likely attempt to fully qualify the stage. This wouldn't work. The only way to get around such a predicament today would be to have another instance of a Session class available set to the particular database and schema where the stage housing the semantic file exists.

I really think we'll need to address how we're referencing the semantic_model_file here:

https://github.com/Snowflake-Labs/orchestration-framework/blob/4f3775cc82369ddb6ce05764ae4bb441e7c3d084/agent_gateway/tools/snowflake_tools.py#L372-L378

One option would be to support fully qualifying the stage path. Another option might be to support a database and a schema argument to initialize the CortexAnalystTool class. Both database and schema could be optional, especially if the stage is already in the current context.

cc: @sfc-gh-alherrera