Skip to main content
Give an OpenAI agent access to Tako by registering Tako as a couple of tools in its tool list. The model decides when to call them, you run the call through the Tako Python SDK, and you hand the result back — so your agent can answer data questions with grounded, up-to-date numbers and download the data behind any result on request. This page builds a copy-paste “Tako agent”: a small chat loop that lets gpt-5.5 (or any tool-calling OpenAI model) call Tako across turns until it has an answer.
Tako’s tool-calling primitives — search, answer, and contents — are all fast, synchronous, stateless HTTP calls, which is exactly what function calling expects.

Install

Set up your environment

You need an OpenAI key and a Tako API key:
Set TAKO_BASE_URL to target a non-prod host (e.g. https://staging.tako.com/api); leave it unset for production.

Define the tools

We register two clearly-differentiated tools. The descriptions are what make the model route correctly, so they spell out exactly when each applies:
  • tako_answer — get a synthesized, written answer grounded in Tako cards and web results, plus the backing cards. This is the default for a data question.
  • tako_contents — download the raw data (a CSV for a Tako card, extracted text for a web page) behind a result you already have, given that result’s URL.
A short system prompt tells the model how to use them and to cite its sources:

Handle tool calls

When the model calls a tool, run it through the Tako SDK and return a JSON-serializable result. We summarize each card down to the fields a host agent actually needs to cite or embed it, and we return errors to the model rather than raising — so a failed call (for example, a transient network error) doesn’t kill the loop:

Run the agent loop

The loop is the standard OpenAI tool-calling pattern: call the model, and while it asks for tools, execute each call, append the result as a tool message, and call again. When the model stops asking for tools, it has its answer:

Full code

The complete script below is also committed to the SDK repo at examples/openai_tool_calling.py. Save it, set the two environment variables above, and run python openai_tool_calling.py.
Running it prints each tool call the model makes, followed by the grounded answer:
tako_answer returns prose plus the backing cards — best when you want the model to read an answer back to the user. If instead you want to render the cards yourself (embed the interactive charts, post-process the data) without a written answer on top, swap in tako_search, which returns the cards only. Register this tool definition in place of tako_answer:
and add the matching branch to handle_tool_call:
Register tako_search or tako_answer, not both. They take the same inputs and differ only in whether you want prose or raw cards back, so exposing both forces the model to guess — weaker models route nearly every data question to tako_search. Pick the one that matches how your app consumes the result, and keep tako_contents alongside it.