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’slocalhost. 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:- macOS with Homebrew and Docker Desktop;
- uv;
- a Perplexity API key.
Set up the local workspace
Create a directory, activate a Python 3.12 virtual environment, and install the three libraries used by the example:.env:
.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
Createcompose.yaml with ClickHouse’s official Docker image:
init.sql. It adds one public demo identity and a separate append-only enrichment table:
Call the Agent API
Createenrich_customer.py. This is the complete application:
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:
Verify the saved row
Check the saved row and its required evidence fields: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:- Replace the demo schema and seed in
init.sql. - Update the
SELECTandcolumnslist inenrich_customer.py. - Loop over a small, explicit set of customer IDs.
- Give every customer a separate Agent API run.
- Add duplicate-run protection before processing a production batch.
- Use a ClickHouse user limited to the required
SELECTandINSERTpermissions.
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.