Add a company check tool to your AI agent: OpenAI Agents SDK

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.

The tool

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.

What the SDK builds from it

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
}

The real result

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.'}

Register it with the agent

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.

What the tool hands back when something fails

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 APIWhat 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-AfterThe 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.

What a call costs

  • One company search is 1 credit, whatever limit you send, so asking for three candidates costs the same as asking for one.
  • Errors are free: a 401, 403, 429 or 5xx is not charged.
  • Starter is EUR 9.99 a month for 1,000 credits, Professional EUR 29.99 for 10,000, Scale EUR 99.99 for 50,000; Enterprise is priced to order. The free trial runs 14 days, needs a card, charges nothing while it lasts and includes 500 credits, then becomes Starter unless you cancel.
  • X-Credits-Cost on every response lets the tool log what a run spent.

The demo key

  • The public demo key 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.
  • Sanctions screening, people and company events answer 403 upgrade_required with it. company_check calls none of them.
  • The key is shared, so someone else can use up the daily cap and a 429 from it is normal. Use your own key for anything that runs unattended.

Guardrails

  • Keep the key in an environment variable read inside the tool. It is not a tool parameter and is not in the prompt or the instructions, so the model cannot see it or be talked into revealing it.
  • The agent reports register facts and a person decides. The sample instructions forbid saying that a company is safe or approved.
  • Sanctions screening is beta. If you add it as a second tool, a hit is a prompt for a person to review, never a verdict, and a clear result means only that no match was found in the lists checked on the date shown.
  • Give each agent its own key, and a key whose scopes cover only what the agent needs (GET /account lists the scopes of a key).
  • The SDK can hold a tool until a person approves it (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.

Scope limits an agent should know

  • Coverage differs by country. The tool works for every live country, and the fields it returns are null where the register publishes none. The API documentation lists what each country serves.
  • 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}.
  • A search returns the register's records, and what counts as a record differs by country. Every result carries 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.

Or use the MCP server

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.

Related pages

Sign up · API documentation

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.

Frequently asked questions

Does the tool need a paid plan?
No. The public demo key covers company search with a shared cap of 30 calls a minute and 1,000 a day, which is enough to build and test. Production use needs a key of your own: the 14-day free trial needs a card and includes 500 credits.
Why a search and not the one-call company check?
GET /companies/check returns the record, officers, owners, insolvency notices and a sanctions screen in one answer, and costs up to 6 credits for a full check by company number (7 by name). A first-pass identity tool needs only the record, so the search at 1 credit is the cheaper fit. Swap the URL and the mapping when your agent needs the full check.
Why does the model send null for the field it does not use?
The Agents SDK builds a strict schema, in which every parameter is required and an optional one is nullable. The function treats null as not given and refuses a call that gives both or neither.
Can the agent call the API without my key in the prompt?
Yes, and it should. The function reads PROMETIAM_API_KEY from the environment of the process that runs the tool. The model never sees it.
Is the answer a decision about the company?
No. It is what the register says today. The agent reports it and a person decides.