Skip to main content
Sales benefits from the most up-to-date customer data. Customer data can become stale quickly. Titles, employers, and public profiles change. A live web search can keep customer data updated with the most recent information. This tutorial uses the Agent API. A short Python program reads one customer from ClickHouse, gives the row to perplexity/glm-5.3, lets the model use built-in People Search, validates the selected result ID and status, and appends the enrichment to ClickHouse.

Why this tutorial uses a Python program

This tutorial runs the ClickHouse Docker image on your computer. Agent API runs remotely, so it cannot connect directly to ClickHouse on your computer’s localhost. The Python app provides that local connection: it reads the customer, sends the row to Agent API, and writes the validated result back to ClickHouse. If your ClickHouse deployment is online, you can instead expose it through a remote, authenticated ClickHouse MCP server and add that server to Agent API as an mcp tool. Agent API can then discover and call the ClickHouse tools inside its loop. Replacing both local database operations requires the MCP server to expose both read and insert tools.

Prerequisites

You need: Install the local tools:
Open Docker Desktop before continuing.

Set up the local workspace

Create a directory, activate a Python 3.12 virtual environment, and install the three libraries used by the example:
Create .env:
Keep .env out of source control. Do not paste your API key into chat, screenshots, or test fixtures. The ClickHouse password protects only this disposable local container; use a strong secret and a restricted database user outside the tutorial.

Start ClickHouse

Create compose.yaml with ClickHouse’s official Docker image:
Create init.sql. It adds one public demo identity and a separate append-only enrichment table:
Start ClickHouse and wait for it to become healthy:
Confirm the source row exists:

Call the Agent API

Create enrich_customer.py. This is the complete application:
The request gives Agent API two tools. people_search runs inside the managed agent loop. save_customer_enrichment is a custom function that formats the final enrichment into a predictable schema. The code reads the raw response JSON so it can process the documented people_search_results item directly. When the API returns the custom function call, Python validates its selected result ID against the people_search_results from the same run. Python then sends the original call and its function_call_output back to Agent API so the model can finish.

Run the enrichment

Change the spend acknowledgement in .env:
Run the Python file:
A successful run prints the run ID, status, resolved profile URL, search queries, model, and Agent API response IDs:
Search results can change, so your queries, result ID, profile URL, and normalized fields may differ.

Verify the saved row

Check the saved row and its required evidence fields:
For the first run, runs, valid_statuses, valid_evidence, and with_response_ids should all equal 1. The selected result ID and URL come from the same people_search_results item, so the model cannot write an arbitrary URL directly into ClickHouse. Run the Python file again to append another enrichment. Keeping each run lets you compare model changes and public profile changes over time.

Limitations

  • The example processes one public demo row. It does not implement batch controls, retries, rate limiting, or duplicate-run protection.
  • The ClickHouse password and default user are for a loopback-only local container, not production.

Adapt the example

To process your own table:
  1. Replace the demo schema and seed in init.sql.
  2. Update the SELECT and columns list in enrich_customer.py.
  3. Loop over a small, explicit set of customer IDs.
  4. Give every customer a separate Agent API run.
  5. Add duplicate-run protection before processing a production batch.
  6. Use a ClickHouse user limited to the required SELECT and INSERT permissions.
Do not send private notes, contact data, credentials, payment fields, or unrelated columns to the model. You are responsible for permission, retention, deletion, employment, privacy, and data-protection requirements that apply to your data.

Troubleshooting

Clean up

Stop ClickHouse and delete the tutorial volume:

Tested with

  • Python 3.12.13;
  • ClickHouse 25.8.33.6;
  • Perplexity Python library 0.43.5; and
  • perplexity/glm-5.3.

Resources