Skip to main content

What you get

agent_config() gives a Claude agent built on the anthropic package its prompt and skills, one user message at a time. You open a run and pass run.system and run.tools to the SDK’s Tool Runner, or to your own messages.create() loop. It runs before you have a DecimalAI account. DecimalAI changes nothing about how the Anthropic SDK behaves, so only the requests you give these pieces get them. This page is for code that calls the Messages API itself. For Claude Code as a library, see Claude Agent SDK.

Install

The extra installs anthropic and openinference-instrumentation-anthropic, which agent_config() uses to trace its runs.

Run with no account

Save this as main.py:
Run it. With no 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 the with block. A Tool Runner sends nothing until it is consumed, so consume it there too, with until_done() or a for loop.
  • run.system is a list of text blocks: your fallback= (later, the saved prompt), then the skill list and one sentence telling the model to load a skill before using it. The last block carries a prompt-caching breakpoint.
  • run.tools holds one tool, load_skill, for the beta Tool Runner. The model calls it with a skill’s name and gets the skill’s full text back. A refusal (an unknown name, an outage) comes back as text the model can read, marked is_error. The list is empty when the run has no skills to offer.
  • No decimalai.init(). It raises without a key, so a file that calls it can’t run keyless. With a key, agent_config() reads DECIMAL_API_KEY by itself.
To see where the list comes from, read Without a DecimalAI key.

Your own tools

List your @beta_tool functions before *run.tools:
decimalai init <agent> --framework anthropic writes a runnable file in this shape, with an example tool.

Your own messages.create() loop

client.messages.create() takes plain tool definitions. Add *run.tool_params, the same load_skill as a plain definition, and answer each tool_use block with run.tool_result(block), which returns None for a block that is not load_skill:
client.messages.stream() works the same way.

Async

On AsyncAnthropic, open the run with async with support.run(question) as run:. run.tools then holds an async tool for the async Tool Runner, and await run.atool_result(block) answers a block in your own loop.

Add a registry skill

Run 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

Get one from Settings → API keys, and run 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.toml records 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.
  • 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:
A {{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 on Claude needs one conversation. A chat that opens support.run() per message breaks as soon as someone saves a prompt or assigns a skill, because Claude rejects a changed system prompt or tool list once a thinking block is in the history. A chat on Claude has the detail. Start the chat with support.conversation(), and open chat.run() for each message. run.system and the tools stay byte for byte what the first message got, and a newer prompt or skill list reaches the next conversation:
  • Keep every turn. Append message.content as it came back, thinking blocks included.
  • run.message is 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, as a second text block. If you send your own instead, a warning says this message's routed skills were not shown to the model.
  • chat.state is the conversation as JSON-ready data, and None before its first run. support.conversation(state=saved) resumes it in another process with the same system blocks and tool. A state for another agent, or state= together with variables=, raises ValueError.
  • Variables belong to the conversation. They are filled once, at its first message, and chat.run() takes no variables=. Put facts that change per message in the user message.

Prompt caching

run.system carries a prompt-caching breakpoint at its end, so later requests that send the same text read the first one’s cache. When later runs share the prompt but not what follows it (a skill list cut to fit, or skill text pasted in), a second breakpoint goes after the prompt, unless the prompt has variables. That is two of a request’s four breakpoints. agent_config(..., cache_control={"type": "ephemeral", "ttl": "1h"}) sets the breakpoint’s value, and cache_control=None sends none. A cache needs a prefix of at least 512 tokens on Claude Haiku, Sonnet and Opus 5.5 (4,096 on Haiku 4.5). A shorter one doesn’t cache, and no error says so.

Its own skill loader

None. This framework has no skill loader of its own, so agent_config() is the only route.

Tracing

agent_config() turns on Anthropic 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 and output, cache reads and writes, 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. A Claude call made outside one, in any client of the process, is held back, even under the app’s own request span, 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 first agent_config(): OpenTelemetry sets the global provider once.
  • agent_config(..., on_trace=fn) calls fn once per run with a copy of the finished trace, before it is sent. A run made inside decimalai.start_trace() is linked to it.
To trace with no skills, call decimalai.init(anthropic=True). It sends every Claude 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

  • HTTP 400, “The block is bound to a different conversation”. The chat’s system or tools changed after a thinking block entered its history, usually because it opens support.run() per message. Use support.conversation().
  • no Claude request was traced inside this run. The model calls ran outside the with block, usually a Tool Runner consumed later. On AnthropicVertex and the legacy AnthropicBedrock client, the Tool Runner’s requests are not traced, but a hand-written messages.create() loop is. 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 (Tool Runner) or *run.tool_params (messages.create()) to tools=.
  • load_skill was called after its run closed. The skill is served, but the run’s record won’t show it. Consume the Tool Runner inside the with block.
  • The model sees two skill lists. Anthropic’s own Agent Skills, passed through the container parameter, are another way to give an agent skills. See Don’t deliver a skill two ways.
  • The model never loads a skill. After a run, print(support) names the prompt version and the skills on its list, for example AnthropicAgentConfig(name='my-agent', prompt_version=3, skills=['playwright-cli']). With no key, an empty list means .decimal/skills.toml lists nothing. With a key, check that the agent gets the skill, and see The silent no-ops.
  • run.tools is empty though the agent has skills. With a key, DECIMALAI_LOAD_SKILL_TOOL=0 or decimalai.init(load_skill_tool=False) empties run.tools and run.tool_params, and the text of the skills picked for each run goes into run.system instead. A conversation keeps its first message’s text, so later messages get no new skill text. With inject_skill_body=False as well, the agent gets no skills, and one warning says DecimalAI skills are off for this agent. The other switches are in Turn it off.