What you get
agent_config() gives your own Chat Completions or Responses API loop its prompt and skills, one user message at a time. You open a run and pass run.system, run.message and run.tools into the requests you already make. It runs before you have a DecimalAI account. DecimalAI changes nothing about how the OpenAI SDK behaves, so only the requests you give these pieces get them.
This page is for code that calls the openai package itself. Building on the OpenAI Agents SDK (from agents import Agent)? See OpenAI Agents.
Install
openai and openinference-instrumentation-openai, which agent_config() uses to trace its runs.
Run with no account
Save this asmain.py:
DECIMAL_API_KEY, it says so once on stderr and sends nothing to DecimalAI. The project has no skills yet, so the model guesses the command.
support.run(question)opens one run for one user message. It calls no model, so make the model calls inside thewithblock.run.systemis the system message’s text: yourfallback=(later, the saved prompt), then the skill list and one sentence telling the model to load a skill before using it.run.messageis the user turn,{"role": "user", "content": question}. Send it instead of your own dict: in a conversation it can carry more.run.toolsholds one tool,load_skill, in Chat Completions’ shape. The model calls it with a skill’s name and gets the skill’s full text back. It is empty when the run has no skills to offer.run.tool_result(call)answers aload_skillcall with itstoolmessage, and returnsNonefor any other tool, soorhands the call to yours. A refusal (an unknown name, an outage) comes back as a sentence the model can read.run.load_skill(name)returns the same text alone, for a dispatcher of your own.- No
decimalai.init(). It raises without a key, so a file that calls it can’t run keyless. With a key,agent_config()readsDECIMAL_API_KEYby itself.
Your own tools
List your tools before*run.tools, and answer whatever run.tool_result(call) leaves as None:
decimalai init <agent> --framework openai writes this loop as a runnable file, with an example tool.
The Responses API
The same run works onclient.responses.create(). The system text goes in instructions, the user turn in input, and the tool comes from run.response_tools: the same load_skill in the Responses API’s flat shape, strict, so the model can name only a listed skill. run.tool_result(call) answers a function_call item with its function_call_output:
run.system with every request: previous_response_id does not carry the earlier request’s instructions over.
Async, and other clients
AsyncOpenAI: open the run withasync with support.run(question) as run:, and answer each call withawait run.atool_result(call)(await run.aload_skill(name)for the text alone), which keep the load off the event loop.- OpenAI-compatible endpoints: the tools are plain dicts, and
run.tool_result()reads a call as the SDK returns it or as a dict. So anOpenAI(base_url=...)client for Azure OpenAI, a local server or another provider’s endpoint takes the same run, and its calls are traced. - LiteLLM:
litellm.completion()takes the same pieces, andrun.tool_result()answers its tool calls. Calls made through a library other thanopenaiare not traced, but the run’s record is.
Add a registry skill
main.py again. The model loads the skill and gives the real command, playwright-cli attach --cdp=http://localhost:9222.
The command wrote the skill’s files to .agents/skills/, listed it in .decimal/skills.toml, and recorded its exact bytes in .decimal/skills.lock. To find others, see Browse the registry. A skill you wrote goes in the same folder, and decimalai skills add <folder> lists it.
Add a key
main.py again.
- The first run connects the project. The agent is created in your workspace, and your project’s skill list is copied onto it once. In a git repository,
.decimal/link.tomlrecords this: commit it. Without a DecimalAI key has the detail. - From now on its skills live on DecimalAI. Each run’s list is picked from them, and every request in a run sees the same list, however many tool calls it takes.
- Every run is one trace, filed under
support.name. See Tracing.
Change the prompt without redeploying
Write a prompt on the agent’s Prompt & skills page and save it.agent_config() keeps a local copy of the prompt and re-reads it in the background at most once a minute, so the next run gets the saved prompt within a minute, in place of fallback=. A version pinned through the API works the same way.
fallback= still runs when the agent has no saved prompt or DecimalAI can’t be reached at startup. With a key and no fallback=, an unreachable DecimalAI raises rather than start an agent with no prompt.
A saved prompt can hold variables, written {{name}}. Pass their values as variables= to support.run(), as dict keys or attributes, so {{customer.name}} reads variables["customer"]["name"] or variables.customer.name:
{{name}} in your fallback= is filled the same way. A variable with no value raises decimalai.MissingPromptVariable, naming it, as the with block opens, so no model call is made. DecimalAI fills only the prompt, never a skill’s text, and the trace keeps the placeholder names, not their values.
Conversations
A chat keeps one conversation.support.conversation() holds the system text and tool its first message got, and every later message reuses them byte for byte, so the chat’s requests share a prefix that OpenAI’s prompt cache reuses. A newer saved prompt or skill list reaches the next conversation, not an open one. If the model behind your client is Claude, see A chat on Claude.
run.messageis the user turn to send: the question, plus, for an agent whose skill list is cut to fit, the skills ranked for this message that the chat has not shown yet.chat.stateis the conversation as JSON-ready data, andNonebefore its first run.support.conversation(state=saved)resumes it in another process with the same system text and tool. A state for another agent, orstate=together withvariables=, raisesValueError.- Variables belong to the conversation. They are filled once, at its first message, and
chat.run()takes novariables=. Put facts that change per message in the user message.
Its own skill loader
None. This framework has no skill loader of its own, soagent_config() is the only route.
Tracing
agent_config() turns on OpenAI tracing with OpenInference’s instrumentor, which wraps the SDK’s classes for the process, and sends only its runs. With no key, nothing is traced.
- Each run is one trace, filed under
support.name. It holds each model request with its input, output and token counts (Chat Completions and Responses API alike), the prompt version, the variable names it filled, any skill outage, and the skills offered, delivered and loaded, each delivery with the exact version the model received. - A conversation’s runs share its id as the trace’s
session_id. A run opened inside your own span, such as a web server’s request span, is a trace of its own, linked to that span. - Nothing outside a run is sent. An OpenAI call made outside one, in any client of the process, is held back, and so are the app’s own spans.
- Set up tracing first. Your own OpenTelemetry tracer provider, and
decimalai.init(otel=True), go before the firstagent_config(): OpenTelemetry sets the global provider once. agent_config(..., on_trace=fn)callsfnonce per run with a copy of the finished trace, before it is sent. A run made insidedecimalai.start_trace()is linked to it.
decimalai.init(openai=True). It sends every OpenAI call in the process and gives none of them a prompt or skills. To group calls into one run, see Mark where a run begins and ends.
Troubleshooting
no OpenAI request was traced inside this run. The model calls ran outside thewithblock, or through a library other thanopenai. If another tool turned the instrumentor on first, DecimalAI gets those calls only if that tool sends its spans to the global tracer provider.run.system names the load_skill tool, but this run's tools never included it. Add*run.tools(Chat Completions) or*run.response_tools(Responses API) totools=, and answer its calls withrun.tool_result(call).load_skill was called after its run closed. The skill is served, but the run’s record won’t show it. Make the model calls inside thewithblock.this message's routed skills were not shown to the model. A conversation’s message went out withoutrun.message. Send it as the user turn.- The model never loads a skill. After a run,
print(support)names the prompt version and the skills on its list, for exampleOpenAISDKAgentConfig(name='my-agent', prompt_version=3, skills=['playwright-cli']). With no key, an empty list means.decimal/skills.tomllists nothing. With a key, check that the agent gets the skill, and see The silent no-ops. run.toolsis empty though the agent has skills. With a key,DECIMALAI_LOAD_SKILL_TOOL=0ordecimalai.init(load_skill_tool=False)emptiesrun.toolsandrun.response_tools, and the text of the skills picked for each run goes intorun.systeminstead. Withinject_skill_body=Falseas well, the agent gets no skills, and one warning saysDecimalAI skills are off for this agent. The other switches are in Turn it off.- A run makes one more model request than you expected. Loading a skill costs one: the model asks for the skill in one request and uses it in the next. Leave room for that in any cap on your loop.