Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,40 @@ $$
> managed elsewhere in your project. This makes the agent a proper downstream
> node in your lineage graph.

### Enabling web search

Add `web_search_tool = true` to the config block to give the agent access to
Snowflake's built-in web search capability:

```sql
{{
config(
materialized = 'cortex_agent',
web_search_tool = true
)
}}
models:
orchestration: claude-4-sonnet
instructions:
response: "Be concise."
orchestration: "Use web search to answer questions about current events."
```

This emits a DDL-level `TOOLS` clause before `FROM SPECIFICATION`:

```sql
create or replace agent MY_DB.MY_SCHEMA.MY_AGENT
tools = (
{ TYPE = WEB_SEARCH_TOOL, NAME = 'web_search' }
)
from specification
$$
...
$$
```

Omitting the config key (or setting it to `false`) produces no `TOOLS` clause.

### 2. Raw DDL mode (`raw_ddl=true`)

The body is **everything that follows `CREATE OR REPLACE AGENT <name>`** — a
Expand Down Expand Up @@ -246,11 +280,12 @@ as usual. The model `alias` becomes the skill folder name on the stage.

## `cortex_agent` configuration reference

| Config | Mode | Type | Description |
|-------------|-----------------|----------------|-------------|
| `comment` | specification | string | Sets the agent-level `COMMENT` clause. Single quotes are escaped automatically. |
| `profile` | specification | dict or string | Sets the `PROFILE` clause. A dict is serialized to JSON for you (`display_name`, `avatar`, `color`); a string is used verbatim. |
| `raw_ddl` | both | bool (default `false`) | When `true`, the model body is treated as raw DDL appended after `CREATE OR REPLACE AGENT <name>`, and `comment` / `profile` configs are ignored. |
| Config | Mode | Type | Description |
|-------------------|-----------------|----------------|-------------|
| `comment` | specification | string | Sets the agent-level `COMMENT` clause. Single quotes are escaped automatically. |
| `profile` | specification | dict or string | Sets the `PROFILE` clause. A dict is serialized to JSON for you (`display_name`, `avatar`, `color`); a string is used verbatim. |
| `web_search_tool` | specification | bool (default `false`) | When `true`, adds `{ TYPE = WEB_SEARCH_TOOL, NAME = 'web_search' }` to the DDL-level `TOOLS = (...)` clause, enabling live web search for the agent. |
| `raw_ddl` | both | bool (default `false`) | When `true`, the model body is treated as raw DDL appended after `CREATE OR REPLACE AGENT <name>`, and `comment` / `profile` / `web_search_tool` configs are ignored. |

Standard dbt configs (`database`, `schema`, `alias`, `tags`, `pre_hook`,
`post_hook`, `grants`, `enabled`, …) all work as usual. The agent is created
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/macros/assert_agents_exist.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
-#}
{% macro assert_agents_exist() %}
{%- if execute -%}
{%- set expected = ['agent_minimal', 'agent_with_semantic_view', 'agent_raw_ddl', 'agent_with_skill'] -%}
{%- set expected = ['agent_minimal', 'agent_with_semantic_view', 'agent_raw_ddl', 'agent_with_skill', 'agent_with_web_search'] -%}
{%- for model_name in expected -%}
{%- set rel = ref(model_name) -%}
{%- do run_query("show agents like '" ~ rel.identifier ~ "' in schema " ~ rel.database ~ "." ~ rel.schema) -%}
Expand Down
16 changes: 16 additions & 0 deletions integration_tests/models/agent_with_web_search.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{
config(
materialized = 'cortex_agent',
comment = 'Agent with web search enabled (integration test)',
web_search_tool = true
)
}}
models:
orchestration: claude-4-sonnet
orchestration:
budget:
seconds: 30
tokens: 16000
instructions:
response: "Be concise."
orchestration: "Use web search to answer questions about current events."
11 changes: 11 additions & 0 deletions macros/relations/cortex_agent/create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@

{%- set comment = config.get('comment', default=none) -%}
{%- set profile = config.get('profile', default=none) -%}
{%- set web_search_tool = config.get('web_search_tool', default=false) -%}

{%- set tools_list = [] -%}
{%- if web_search_tool -%}
{%- do tools_list.append("{ TYPE = WEB_SEARCH_TOOL, NAME = 'web_search' }") -%}
{%- endif -%}

create or replace agent {{ relation }}
{%- if comment is not none %}
Expand All @@ -70,6 +76,11 @@
{%- if profile is not none %}
profile = {{ dbt_cortex_agent.cortex_agent_render_profile(profile) }}
{%- endif %}
{%- if tools_list | length > 0 %}
tools = (
{{ tools_list | join(',\n ') }}
)
{%- endif %}
from specification
$${{ '\n' }}{{ sql }}{{ '\n' }}$$

Expand Down
Loading