One Python function wrapped with function_tool lets an agent check a company in its official register: legal name, number, status, legal form, founding date and VAT number. Written against openai-agents 0.26.0, 26 November 2026.
The Agents SDK builds a tool from a plain Python function: its signature becomes the JSON schema and its docstring becomes the description the model reads. This page wraps a function that calls GET /companies/search, returns a small object a model can reason over, and hands every failure back as data. It was written against openai-agents 0.26.0 (installed from PyPI on 26 November 2026). The tool function was run against the live API; the model loop was not, because it needs your own OpenAI key.
Install the package and set the key. Use the public demo key for a first run, or your own key:
pip install openai-agents requests export PROMETIAM_API_KEY=rk_live_demo_publichn # or your own rk_live_ key
The whole file, tool and agent. company_check is the plain function, so you can test it without the SDK; function_tool(company_check) turns it into a tool:
import os
import time
import requests
from agents import Agent, function_tool
BASE = os.environ.get("PROMETIAM_BASE_URL", "https://api.prometiam.com/functions/v1/risk-api")
def company_check(country: str, name: str | None = None, company_number: str | None = None) -> dict:
"""Look up a company in the official register of one country.
Args:
country: Two-letter country code, for example ES, FR or GB.
name: Company name. Give this or company_number.
company_number: National register number. Give this or name; it is exact.
"""
key = os.environ.get("PROMETIAM_API_KEY")
if not key:
return {"ok": False, "error": "missing_key", "message": "PROMETIAM_API_KEY is not set."}
if bool(name) == bool(company_number):
return {"ok": False, "error": "bad_input", "message": "Give exactly one of name or company_number."}
params = {"country": country.upper(), "limit": 3}
params["company_number" if company_number else "name"] = company_number or name
for attempt in range(2):
try:
res = requests.get(
f"{BASE}/companies/search",
params=params,
headers={"Authorization": f"Bearer {key}"},
timeout=15,
)
except requests.RequestException as exc:
return {"ok": False, "error": "network", "message": type(exc).__name__}
if res.status_code != 429:
break
wait = min(int(res.headers.get("Retry-After", "5") or 5), 30)
if attempt == 0:
time.sleep(wait)
if res.status_code == 401:
return {"ok": False, "error": "unauthorized", "message": "The API key is missing, wrong or expired."}
if res.status_code == 429:
return {"ok": False, "error": "rate_limited", "retry_after_seconds": int(res.headers.get("Retry-After", "0") or 0)}
if not res.ok: # includes 403 upgrade_required
err = res.json().get("error", {}) if res.headers.get("content-type", "").startswith("application/json") else {}
return {"ok": False, "error": err.get("code", f"http_{res.status_code}"), "message": err.get("message", "The API returned an error.")}
data = res.json()["data"]
if not data:
return {"ok": True, "found": False, "message": "No company matched in this country. Do not guess; ask for the register number."}
top = data[0]["match_score"]
return {
"ok": True,
"found": True,
"ambiguous": sum(1 for c in data if c["match_score"] == top) > 1,
"companies": [
{
"legal_name": c["company_name"],
"register_number": c["company_number"],
"status": c["status"],
"legal_form": c["legal_form"],
"founding_date": c["founding_date"],
"vat_number": c["vat_number"],
"vat_number_source": c["vat_number_source"],
"match_score": c["match_score"],
}
for c in data
],
}
company_check_tool = function_tool(company_check)
agent = Agent(
name="Counterparty checker",
instructions=(
"You check companies against official registers with the company_check tool. "
"Report only what the tool returns. Fields can be null where a register publishes none. "
"If several companies match equally, list them and ask which one is meant. "
"Never state that a company is safe or approved; a person decides."
),
tools=[company_check_tool],
)
The function takes a country code and exactly one of name or company_number. A register number is an exact match; a name is a ranked search that can return several companies. It sends limit=3 so the model sees the other close candidates and not a list it cannot use.
The SDK reads the signature and the docstring. The tool is named company_check, and because strict_mode is on by default, every parameter is listed as required and the optional ones accept null. That is why the model sends "company_number": null when it searches by name, and why the function treats an empty value as absent:
{
"properties": {
"country": { "type": "string", "description": "Two-letter country code, for example ES, FR or GB." },
"name": { "anyOf": [{ "type": "string" }, { "type": "null" }], ... },
"company_number": { "anyOf": [{ "type": "string" }, { "type": "null" }], ... }
},
"required": ["country", "name", "company_number"],
"additionalProperties": false
}
On 26 November 2026 this call ran against the live API with the demo key, company_check("ES", name="Inditex"), and printed:
{
"ok": true,
"found": true,
"ambiguous": true,
"companies": [
{
"legal_name": "INDUSTRIA DE DISEÑO TEXTIL, S.A",
"register_number": "A15075062",
"status": "active",
"legal_form": "SA",
"founding_date": "1985-06-12",
"vat_number": "ESA15075062",
"vat_number_source": "rule",
"match_score": 100
},
{
"legal_name": "INDITEX SA",
"register_number": "A28601094",
"status": "active",
"legal_form": "SA",
"founding_date": "1980-05-14",
"vat_number": "ESA28601094",
"vat_number_source": "rule",
"match_score": 100
},
{
"legal_name": "INDITEX LOGISTICA, S.A",
"register_number": "A70268669",
"status": "active",
"legal_form": "SA",
"founding_date": "2010-10-14",
"vat_number": "ESA70268669",
"vat_number_source": "rule",
"match_score": 88
}
]
}
Two companies score 100, so ambiguous is true: the tool does not pick one, and the instructions tell the agent to list the candidates and ask. The VAT numbers are rule numbers, built from the Spanish NIF; they are not a VIES confirmation.
A call that finds nothing returns data, not an error. The same day the tool, invoked the way the SDK invokes it (on_invoke_tool with the model's JSON arguments), answered a nonsense name with:
{'ok': True, 'found': False, 'message': 'No company matched in this country. Do not guess; ask for the register number.'}
The bottom of the file already builds the agent: Agent(name=..., instructions=..., tools=[company_check_tool]). Constructing it needs no key, and it was constructed on the same run: the object is an Agent named "Counterparty checker" whose tools are ['company_check']. To run the model loop, add two lines with your own OpenAI key set as OPENAI_API_KEY:
from agents import Runner from company_check import agent result = Runner.run_sync(agent, "Is Inditex active? Check it in the Spanish register.") print(result.final_output)
This last snippet was not run: it calls a model and needs a model key that this page's author did not use. The tool it calls was run, as shown above.
A tool that raises ends the model's turn with a stack trace. This one returns the failure as a small object, so the model can tell the user what happened. The 401, 403 and 429 rows below were checked against a local test server that answers like the API, not against the live API, so the live service is never asked to fail on purpose:
| Answer from the API | What the tool returns to the model |
|---|---|
401 unauthorized | {"ok": false, "error": "unauthorized", ...}: the key is missing, wrong or expired. The model should tell the user, not retry. |
403 upgrade_required | {"ok": false, "error": "upgrade_required", "message": ...} with the API's own message. The key's plan does not include what was asked. |
429 with Retry-After | The tool waits the number of seconds given (at most 30), tries once more, and if it is still limited returns {"error": "rate_limited", "retry_after_seconds": n}. |
200 with an empty data | {"ok": true, "found": false, ...}: no company matched. The message tells the model not to guess. |
| Network error or timeout | {"ok": false, "error": "network", ...}. The request times out after 15 seconds. |
limit you send, so asking for three candidates costs the same as asking for one.X-Credits-Cost on every response lets the tool log what a run spent.rk_live_demo_publichn needs no signup. It is shared, allows 30 calls a minute and 1,000 a day, and covers company search, records, VAT, LEI, insolvency and coverage.upgrade_required with it. company_check calls none of them.GET /account lists the scopes of a key).needs_approval on function_tool). This tool only reads, so it does not need it; use it for a tool that changes something, such as a monitoring subscription.vat_number_source is register where the register publishes the number and rule where the number is built from the register identifier by the country's rule: the format is right, the registration is not confirmed. For an EU number, check it with GET /vat/{number}.entity_class; the tool does not pass it on, so add it to the mapping if your agent must tell companies from other registrants. A name can match several companies, which is why the tool sets ambiguous and the agent asks instead of picking one.If you would rather not write and maintain a tool, the same data is available as a Model Context Protocol server, prometiam-risk-mcp, which exposes company search, records, events, insolvency, VAT, LEI and sanctions screening (beta) as ready-made tools. See the MCP server and the use case for AI agents. The Agents SDK can attach an MCP server to an agent in place of a hand-written tool. The same tool for other stacks: LangChain and Vercel AI SDK.
The free trial lasts 14 days and includes 500 credits. A card is required and nothing is charged during the trial; it then continues as Starter (EUR 9.99/month) unless you cancel.