Interact without an agent object

In some cases, you may want to get started with Cortex Agents by using agent:run without an agent object. For example, this may be useful when you want to quickly try out a use case. For more information about the REST API, see Run agent.

Note

When interacting with an agent without creating an agent object, you must manually maintain the context for the agent with every request.

  1. Specify the tools you want to use in the request.

    {
        "tools": [
            {
                "tool_spec": {
                    "name": "data_model",
                    "type": "cortex_analyst_text_to_sql"
                }
            },
            {
                "tool_spec": {
                    "name": "transcript_search",
                    "type": "cortex_search"
                }
            }
        ]
    }
    
    Copy
  2. Provide static arguments (resources) to the tools that Cortex Agent can use for tool calling.

    {
        "tool_resources": {
            "data_model": {
                "semantic_model_file": "@cortex_tutorial_db.public.revenue_semantic_model.yaml"
            },
            "transcript_search": {
                "name": "cortex_tutorial_db.public.contract_terms",
                "max_results": 5,
                "title_column": "TRANSCRIPT_TITLE",
                "id_column": "TRANSCRIPT_ID",
                "filter": {"@eq": {"TRANSCRIPT_TYPE": "ENTERPRISE"} }
            }
        }
    }
    
    Copy
  3. Now we will specify the model and the system prompt to generate the response

    {
        "model": "claude-3-5-sonnet",
        "messages": [
            {
                "role": "system",
                "content": {
                    "type": "text",
                    "text": "You’re a friendly assistant to answer questions."
                }
            }
        ]
    }
    
    Copy
  4. Create a semantic model file that will be used by the Analyst tool to access structured data. Follow steps 1 to 3 in this guide to create a Cortex Analyst semantic model Getting Started with Cortex Agents (https://quickstarts.snowflake.com/guide/getting_started_with_cortex_agents/index.html?index=..%2F..index#1)

  5. Next, we set up search service for Search tool to access unstructured data. Follow step 4 to 5 in this guide to create Cortex Search Service Getting Started with Cortex Agents (https://quickstarts.snowflake.com/guide/getting_started_with_cortex_agents/index.html?index=..%2F..index#1)

  6. We are now ready to interact with the Agent. You will use the messages field to send requests and receive responses

    {
        "model": "claude-3-5-sonnet",
        "messages": [
            {
                "role": "system",
                "content": [
                    {
                        "type": "text",
                        "text": "You’re a friendly assistant to answer questions"
                    }
                ]
            },
            {
                "role": "user",
                "content": [
                    {
                        "type": "text",
                        "text": "hello"
                    }
                ]
            },
            {
                "role": "assistant",
                "content": [
                    {
                        "type": "text",
                        "text": "hi there!"
                    }
                ]
            },
            {
                "role": "user",
                "content": [
                    {
                        "type": "text",
                        "text": "..."
                    }
                ]
            }
        ]
    }
    
    Copy
  7. As the interaction proceeds, Agent identifies the tools and executes (service-side) to fulfill the task. In the example below, the Agent identifies Text2SQL as the tool and executes to get the SQL query. During the interaction the Agent may request a tool use for the client application (client-side). For example, the Agent specifies the SQL query that should be executed.

    {
        "role": "assistant",
        "content": [
            {
                "type": "tool_use",
                "tool_use": {
                    "tool_use_id": "tool_001",
                    "name": "cortex_analyst_text_to_sql",
                    "input": {
                        "query": "...",
                        "semantic_model_file": "..."
                    }
                }
            },
            {
                "type": "tool_results",
                "tool_results": {
                    "status": "success",
                    "tool_use_id": "tool_001",
                    "content": [
                        {
                            "type": "json",
                            "json": {
                                "sql": "select * from table"
                            }
                        }
                    ]
                }
            }
        ]
    }
    
    Copy
Language: English