Public registry lookup
An agent finds a company in the UK's public company register (Companies House) and opens its page; extract then reads the record into JSON with a schema.
When to use it: You look up records in a public register through its website.
| Uses | agent.run and agent.stream, then extract with a schema |
|---|---|
| Needs | a model on the API |
| Site | find-and-update.company-information.service.gov.uk (public) |
| Output | output/record.json |
| Languages | Node and Python |
The code
The example as it is in its folder. Both versions do the same job and write the same output/, so one result check covers both.
/** * Public registry lookup: an agent finds a company in the UK's public company register (Companies House), then * extract reads its record into JSON with a schema. * * npx tsx node/index.ts (BOXLINE_API_KEY; COMPANY for another company) * * Writes output/record.json. */import { mkdirSync, writeFileSync } from "node:fs";import { join } from "node:path";import { Boxline } from "@boxline/sdk";const out = process.env.OUTPUT_DIR ?? "output";const company = process.env.COMPANY ?? "ARM LIMITED";const REGISTER = "https://find-and-update.company-information.service.gov.uk";const bx = new Boxline();interface CompanyRecord { companyNumber: string; name: string; status: string; type: string; incorporated: string; registeredOffice: string;}// 1. The agent searches the register and opens the company's overview page (it chooses among similar names).const run = await bx.agent.run({ task: `Find the company "${company}" on the UK Companies House register (${REGISTER}): search for it and open its overview page. Reply with the address of that overview page only.`, maxSteps: 15,});console.log(`Agent run ${run.id} (${run.provider}/${run.model}) · Session: ${run.sessionId}`);for await (const e of bx.agent.stream(run.id)) { if (e.type === "tool") console.log(`→ ${e.name} ${JSON.stringify(e.input ?? {}).slice(0, 100)}`); else if (e.type === "done") console.log(`${e.status}: ${e.result ?? e.error}`);}const done = await bx.agent.get(run.id);const page = /https:\/\/find-and-update\.company-information\.service\.gov\.uk\/company\/[A-Z0-9]+/i.exec(done.result ?? "")?.[0];if (!page) throw new Error(`the agent did not find the company's page: ${done.result ?? done.error}`);// 2. extract reads the record on that page into a fixed shape.const { data, usage } = await bx.extract<CompanyRecord>({ url: page, prompt: "The company record on this page.", schema: { type: "object", properties: { companyNumber: { type: "string" }, name: { type: "string" }, status: { type: "string" }, type: { type: "string", description: "the company type, e.g. Private limited company" }, incorporated: { type: "string", description: "the incorporation date as YYYY-MM-DD" }, registeredOffice: { type: "string", description: "the registered office address on one line" }, }, required: ["companyNumber", "name", "status", "type", "incorporated", "registeredOffice"], },});console.log(JSON.stringify(data, null, 2));mkdirSync(out, { recursive: true });writeFileSync(join(out, "record.json"), JSON.stringify(data, null, 2));writeFileSync(join(out, "result.json"), JSON.stringify({ company, page, record: data, agentRuns: [{ id: run.id }], usage: { modelUsd: usage.costUsd } }, null, 2));"""Public registry lookup: an agent finds a company in the UK's public company register (Companies House), thenextract reads its record into JSON with a schema. python python/main.py (BOXLINE_API_KEY; COMPANY for another company)Writes output/record.json."""import jsonimport osimport refrom pathlib import Pathfrom boxline import Boxlineout = Path(os.environ.get("OUTPUT_DIR", "output"))company = os.environ.get("COMPANY", "ARM LIMITED")REGISTER = "https://find-and-update.company-information.service.gov.uk"bx = Boxline()# 1. The agent searches the register and opens the company's overview page (it chooses among similar names).run = bx.agent.run( f'Find the company "{company}" on the UK Companies House register ({REGISTER}): search for it and open its overview page. ' "Reply with the address of that overview page only.", max_steps=15,)print(f"Agent run {run['id']} ({run['provider']}/{run['model']}) · Session: {run['sessionId']}", flush=True)for e in bx.agent.stream(run["id"]): if e["type"] == "tool": print(f"-> {e['name']} {json.dumps(e.get('input') or {})[:100]}") elif e["type"] == "done": print(f"{e['status']}: {e.get('result') or e.get('error')}")done = bx.agent.get(run["id"])m = re.search(r"https://find-and-update\.company-information\.service\.gov\.uk/company/[A-Z0-9]+", done["result"] or "", re.I)if not m: raise SystemExit(f"the agent did not find the company's page: {done['result'] or done['error']}")page = m.group(0)# 2. extract reads the record on that page into a fixed shape.r = bx.extract( url=page, prompt="The company record on this page.", schema={ "type": "object", "properties": { "companyNumber": {"type": "string"}, "name": {"type": "string"}, "status": {"type": "string"}, "type": {"type": "string", "description": "the company type, e.g. Private limited company"}, "incorporated": {"type": "string", "description": "the incorporation date as YYYY-MM-DD"}, "registeredOffice": {"type": "string", "description": "the registered office address on one line"}, }, "required": ["companyNumber", "name", "status", "type", "incorporated", "registeredOffice"], },)record = r["data"]print(json.dumps(record, indent=2))out.mkdir(parents=True, exist_ok=True)(out / "record.json").write_text(json.dumps(record, indent=2))result = {"company": company, "page": page, "record": record, "agentRuns": [{"id": run["id"]}], "usage": {"modelUsd": r["usage"]["costUsd"]}}(out / "result.json").write_text(json.dumps(result, indent=2))Inputs
Environment variables the example reads:
COMPANY: the company to look up (defaultARM LIMITED).
Run it
Get the examples with git clone https://github.com/Boxline-dev/examples.git and open this one: cd examples/public-registry-lookup. Put your API key in BOXLINE_API_KEY (and BOXLINE_API_URL for another API), then run either version from the example’s folder. Both write to output/ and stop their sessions when they finish.
# Node 18 or newer, in the example's folderexport BOXLINE_API_KEY=… # your API keynpm install @boxline/sdk tsxnpx tsx node/index.ts# Python 3.9 or newer, in the example's folderexport BOXLINE_API_KEY=… # your API keypip install boxline-sdkpython python/main.pyThen check the result, from the same folder: npx tsx check.ts output. It exits with 0 only when the result is right.
What its check proves
check.ts reads what the example wrote and passes only when the result is right, not merely when the example ran.
The record is complete and matches its page; for ARM LIMITED: 02557590, active, incorporated in 1990, Fulbourn Road.
Source
github.com/Boxline-dev/examples/public-registry-lookup on GitHub, with its README.md, check.ts and .env.example. The examples are open source. See all examples.
These docs describe a beta API. Endpoints, fields and SDK methods may change before general availability; breaking changes will be listed in the changelog.