Connect AI agent tools to external services
This feature is in Public Preview.
Learn how to connect AI agent tools to external applications like Slack, Google Calendar, or any service with an API using HTTP requests. Agents can use externally connected tools to automate tasks, send messages, and retrieve data from third-party platforms.
Requirements
- Create a Unity Catalog HTTP connection. See Connect to external HTTP services.
Create a Unity Catalog function tool
After creating the HTTP connection and testing that it works properly, create a Unity Catalog function that uses the connection. The following example creates a Unity Catalog function tool that an agent can use to post a message to Slack:
CREATE OR REPLACE FUNCTION main.default.slack_post_message(
text STRING COMMENT 'message content'
)
RETURNS STRING
COMMENT 'Sends a Slack message by passing in the message and returns the response received from the external service.'
RETURN (http_request(
conn => 'test_sql_slack',
method => 'POST',
path => '/api/chat.postMessage',
json => to_json(named_struct(
'channel', "C032G2DAH3",
'text', text
))
)).text
Create a tool in agent code
To send HTTP requests to external services with Python, use the http_request function from the databricks-sdk
library. This function sends an HTTP request to an external service using a Unity Catalog connection to authenticate.
Permissions required: USE CONNECTION
on the connection object.
The following example makes an external HTTP request from inside agent code.
from databricks.sdk import WorkspaceClient
from databricks.sdk.service.serving import ExternalFunctionRequestHttpMethod
WorkspaceClient().serving_endpoints.http_request(
conn="connection_name",
method=ExternalFunctionRequestHttpMethod.POST,
path="/api/v1/resource",
json={"key": "value"},
headers={"extra_header_key": "extra_header_value"},
)
conn
: The connection object that specifies the host, port, base_path, and access credentials.method
: The HTTP request method used to make the call. For example:GET
,POST
,PUT
,DELETE
path
: The path to concatenate after thebase_path
to invoke the service resource.json
: The JSON body to send with the request.headers
: A Map to specify the request headers.
Example notebooks
The following notebooks demonstrate creating AI agent tools that connect to Slack, OpenAI, and Azure AI search.