Build a context pack in one call
assemble_context runs the search, collapses duplicates, ranks by trust and packs to a token budget — replacing about twenty calls and the reasoning between them.
The problem
The expensive part of agentic retrieval is not the search. It is everything after: working out which results duplicate each other, which sources are independent, which are authoritative, and what fits — reasoning that happens in the context window and is billed by the token.
What to send
querythe question
Natural language. The whole task, not a keyword soup.
budget4000
The token ceiling. The response reports what it actually used.
min_independent_sources2
Applies the corroboration floor during selection rather than after it.
The code
import httpx
pack = httpx.get(
"https://api.unlob.com/assemble_context",
headers={"x-api-key": "ulb_..."},
params={
"query": "what changed in the EU AI Act general-purpose model rules",
"budget": 4000,
"min_independent_sources": 2,
},
).json()
# Each passage carries why it was included, so the agent can cite and a
# human can audit the selection rather than trusting it.
for p in pack["passages"]:
print(f"- {p['url']}\n {p['reason']}")
context = "\n\n".join(p["text"] for p in pack["passages"])The mistake to avoid
Throwing away the `reason` field and keeping only the text. It is what lets you cite a source and what lets a reviewer check the selection — without it you have rebuilt an opaque retrieval layer, which is the thing worth avoiding.
Frequently asked questions
How is this different from just calling search?
Search returns ranked hits and leaves selection to you. assemble_context does the deduplication, trust ranking and budget packing server-side, and tells you why each passage survived. It bills as one request.
Can I use it without MCP?
Yes — it is an ordinary HTTP endpoint. The MCP tool of the same name wraps it for agent clients, and both bill identically.
Try it against your own queries
10,000 requests a month on the free tier, no card. Enough to run a real evaluation set rather than a demo.