LiveKit Agents Deep Search
Give a LiveKit voice agent Deep Search as three function tools. The caller describes the rows they need, the agent reads back the request and the most it can cost, and after a yes SpecStream returns every match on the live web as a table. Source URL and read time on every value.
SpecStream for LiveKit Agents Deep SearchAgent frameworks & buildersWhat you need
- Python 3.10 or newer, the LiveKit CLI (
lk) and a LiveKit Cloud project. The steps start from LiveKit'sagent-starter-pythonproject, which pinslivekit-agents~=1.8. - A SpecStream API key with a total spending limit. New accounts start with $10 of credit, no card. Create an account.
- 1
1. Create a SpecStream API key
In the SpecStream workspace, open API keys and click New key. Name it for the agent and choose Call the APIs under What the key can do: it holds Authorize paid work, which starting a search needs.
Enter a Total spending limit, the most the agent may spend across all its calls, then click Create key. Copy the key from Copy your key now, because it is shown once. The tools run in your agent process, so the key never reaches the room, the caller or the model.
- 2
2. Create the agent project
Create a project from LiveKit's Python starter, install its dependencies when the CLI asks, and add
httpx, the async HTTP client the tools use. Then put the key in the project's.env.local, beside the LiveKit keys the CLI wrote there:Terminal - 3
3. Write the Deep Search tools
@function_toolturns each function into a tool, and LiveKit sends its docstring to the model as the tool description. Deep Search takes three tools, because a search runs longer than one turn of the conversation:price_deep_searchsends the request toPOST /v1/parse, which returnsread_back, the request in plain words, andast_hash. It then asksPOST /v1/capacity/quotesfor the price of that many rows. The quote'smaximum_centsis the most the search can cost. Pricing spends nothing, and the quote stays open for 30 minutes.start_deep_searchapproves the quote withPOST /v1/capacity/executions. The amount comes from the quote your code kept, never from the model's arguments, and the quote's own ID is the request key, so a repeated call cannot start a second search. It returns at once and leaves a background task that checks the search every 10 seconds and has the agent tell the caller when the table is ready.read_deep_searchreads the first 10 rows fromGET /v1/finds/{id}/rowswithformat=markdown: one table with a column for each fact the caller asked for and a Source column. A failed call raisesToolError, and LiveKit passes its message to the model, so the agent tells the caller why the call failed and the session keeps running. Save this assrc/specstream_deep_search.py:src/specstream_deep_search.py - 4
4. Give the tools to the agent
In
src/agent.py, import the three tools, add the rules below to the end of the starter's instructions, and pass the tools intools. The rules make the agent read the price aloud and wait for a yes before it starts anything:src/agent.py - 5
5. Run it and ask
Start the agent with
lk agent devand talk to it in the Agent Console (opens in a new tab). Ask for rows and say how many. The agent reads back the request and the maximum price. Say yes, and it starts the search and keeps talking. When the table is ready the agent says so, and asking for the rows makes it callread_deep_search.Spoken to the agent
What the agent gets back
Deep Search turns one request in plain words into rows from the live web: companies, local businesses, people, grants, tenders, papers and other records, each with the facts the caller asked for. Every row meets the conditions in the request.
read_deep_search hands the model a Markdown table. Its Source column holds the page most of the row's values were read on, and a value read on another page carries its own link, so the agent can name the site behind each row it speaks. The model reads the table and the caller hears sentences.
For the full rows in your own code, call GET /v1/finds/{id}/rows without format: each row's cells hold the column's label, the value as display, and a provenance with source_url and observed_at. format=csv returns the same page as one CSV text. Follow next_cursor for the rows past the first page.
Why the search runs in the background
A Deep Search can run for minutes, and up to four hours on the largest lists. A LiveKit tool that waited for it would hold the turn, so start_deep_search returns as soon as the search starts, and the caller can keep talking.
The background task keeps the session from the tool's RunContext. When the search ends it calls session.generate_reply, and the agent tells the caller the table is ready. The task set keeps a reference to each running check until it ends.
How spending stays under control
- Pricing spends nothing.
price_deep_searchonly reads the request and returns a quote. - The caller approves the price. The rules in the instructions make the agent read the maximum aloud and wait for a yes before
start_deep_search. - The model cannot change the amount.
confirm_max_centscomes from the quote your code kept, and a search never costs more than it. - The row limit holds in code.
price_deep_searchcapsrowsat 100 whatever number the model sends. - The key has a ceiling. Its total spending limit caps what the agent can spend across all calls, and a call over it is refused with
403.
If something doesn't work
| What you see | What to do |
|---|---|
price_deep_search returns a status other than runnable | The request needs more detail, such as the place or the facts to bring back. The agent asks the caller and prices it again. |
The agent says Unknown or used quote | The quote was used, or the agent process restarted. Price the request again. A quote also expires after 30 minutes. |
SpecStream answered 402 | The balance is too low for the approved maximum. Add balance in your SpecStream workspace. |
SpecStream answered 403 | The key has no Authorize paid work, or the search would go over its total spending limit. Raise the limit under API keys. |
SpecStream answered 401 | The key is unknown, expired or revoked. Create a new key and set it as SPECSTREAM_API_KEY in .env.local. |
KeyError: 'SPECSTREAM_API_KEY' | The agent process has no key. Check the line in .env.local, or set the variable where the agent server runs. |
Cost
Pricing a request, reading rows and checking a search's status cost nothing. A search is charged per delivered row: 5¢, 15¢ or $1 a row depending on how much each row needs, plus 5¢ for a person's email and 15¢ for a phone when the request asks for them. Duplicates and rows a page contradicts are not charged, a search that finds nothing costs nothing, and no search costs more than the maximum the caller approved. New accounts start with $10 of credit, no card. The rates are on pricing, and balance and billing covers quotes.
Web search and page reading too
For one fact in the middle of a call, the LiveKit Agents web search guide adds search_web and read_page tools on the same key. The Search API is $5 per 1,000 searches of up to 10 results and the Extract API $0.80 per 1,000 pages, with no quote and no approval. The REST API reference lists every call on this page.
Remove
Take the three tools out of the agent's tools and the rules out of its instructions. Then open API keys in your SpecStream workspace and revoke the key, which cuts the agent off at once. Rows already delivered stay in your account. Browse the other tools SpecStream connects to, or write to [email protected] if a step here doesn't match what you see.
More
SpecStream for LiveKit Agents Deep Search covers what it does in LiveKit Agents Deep Search on one page. Every other tool has its guide in Connect your tools. You see the most a request can cost before it starts, and the matches are paid from your balance. Billing has the details. For help, email [email protected].