Skip to main content

What you get

agent_config() gives each Claude Agent SDK run its prompt and skills. You open a run, pass your own ClaudeAgentOptions to run.query(), and read its message stream as usual. It runs before you have a DecimalAI account. Nothing is patched, so ordinary query() calls elsewhere in your process are left alone. This page is for claude-agent-sdk, which runs a tool-use loop on the Claude Code engine. For your own Messages API loop, see Anthropic API. For the Claude Code terminal tool, see Claude Code.

Install

The extra installs claude-agent-sdk.

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.
  • async with support.run(question) as run: opens one independent query. Its system text is your fallback= (later, the saved prompt), then the skill list and one sentence telling the model to load a skill before using it.
  • run.query(options=options) calls query() with your options plus three things: that system text as system_prompt, an in-process MCP server named decimalai, and permission for its one tool, mcp__decimalai__load_skill, when the run lists skills. The model calls the tool with a skill’s name and gets the skill’s full text back. Your model, tools, other MCP servers, working directory and limits stay as you set them, and your options object isn’t changed.
  • async for needs an async def. At module level it is a SyntaxError. Inside an event loop you already have, such as a notebook or a FastAPI handler, await main() instead of asyncio.run(main()).
  • No decimalai.init(). init() raises without a key, so a file that calls it can’t run keyless. With a key, agent_config() sets the SDK up from DECIMAL_API_KEY by itself.
To see where the list comes from, read Without a DecimalAI key.

Your own tools

Name Claude Code’s own tools in tools=, and add your own through an MCP server of your own:

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-name> lists it.

Add a key

Get one from Settings → API keys, and run main.py again. The code stays the same.
  • The first run connects the project. The agent is created in your workspace. In a git repository, your project’s skill list is copied onto it once, and .decimal/link.toml records this: commit it.
  • From now on its skills live on DecimalAI. Each run’s list is picked from them.
  • Every query is one trace, filed under support.name. See Tracing.
  • Your fallback= keeps running until you save a prompt.
The detail is in Without a DecimalAI key.

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=. An open conversation keeps its first message’s prompt. support.prompt_source and support.prompt_version say which prompt it has read. With a key, fallback= is what 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 async 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

For a chat, keep one support.conversation() beside its history, and run its messages one at a time:
  • A conversation keeps its first message’s prompt, variables and load_skill definition, and resumes its own Claude session. That is what a chat on Claude requires. A newer saved prompt or skill list reaches the next conversation.
  • A later message’s new skills go in after the user’s text, when the agent has more skills than one list holds and that message’s ranking picks ones the chat has not shown.
  • It lives in this process. Unlike the other frameworks, it has no state to store, so a chat can’t continue after a restart or in another process.
  • Variables belong to the conversation. chat.run() takes only the message.

Its own skill loader

Claude Code reads skills from disk itself, and decimalai skills keeps .agents/ as a Claude Code plugin named decimalai-skills. decimalai.claude_agent_sdk.skills_plugin() passes that folder to the Agent SDK:
  • Keep this apart from agent_config(). Use one per agent, or the model sees a skill twice. run.query() refuses skills=.
  • Claude Code picks the skill. A trace on this path has no DecimalAI ranking. With the stream traced, each skill text the CLI hands the model counts as Loaded, with the version found from the lock, and the DecimalAI skills in its catalog count as Offered.
  • Names carry the plugin’s prefix: decimalai-skills:playwright-cli. skills="all" also offers Claude Code’s built-in skills. To offer only yours, list them: skills=["decimalai-skills:playwright-cli"]. A skill left off the list is hidden, and nothing reports it.
  • Only skills your organization wrote pre-approve tools. For any other, only Read, Grep and Glob stay in its allowed-tools, so running its scripts needs your permission.
Interactively, the same plugin loads with this. The path must be absolute: a relative --plugin-dir started from a subdirectory loads nothing and shows no error.
The rest is in Native skill loaders.

Tracing

With a key, each run.query() is one trace, filed under support.name. With no key, nothing is traced. A trace holds:
  • Every assistant turn as a model call, and tool calls matched to their results, with latency and per-tool error status. A failed tool doesn’t fail the run: the ResultMessage decides.
  • Token usage and cost from the final ResultMessage, including cache tokens.
  • The agent’s manifest (the record of its model, prompt, allowed tools by name, and sub-agents), detected from your options. For tool schemas, use register_manifest().
  • On agent_config() runs: the saved prompt version, the ranking decision, and the skills offered, delivered and loaded, with the versions the model got.
Tracing never alters or swallows a message, and a failed upload never breaks your run.

Tracing only

To trace ordinary query() calls with no prompt or skills from DecimalAI, use the framework flag. It patches claude_agent_sdk.query, so call it before from claude_agent_sdk import query:
To patch nothing, wrap a stream you already have, such as ClaudeSDKClient.receive_response(), with trace_stream. traced_query(prompt=..., options=..., agent_name=...) calls query() and wraps it in one step:

Troubleshooting

  • raw Claude resume, session_id and continue_conversation options bypass config. A session under a different prompt breaks Claude’s thinking history. Use support.conversation().
  • Claude config supplies routed skills; do not also enable native skills. Remove skills= from the options you pass to run.query(). For disk skills, use the loader on its own.
  • mcp_servers['decimalai'] is reserved, or Claude config needs mcp_servers as a dict. Pass your servers as dictionary entries under other names.
  • load_skill is disallowed by these Claude options. Take mcp__decimalai__load_skill out of disallowed_tools.
  • consume run.query() inside 'async with support.run(question) as run:'. Read the stream inside the block.
  • each Claude config run can query only once. Start another support.run() for each message.
  • run a Claude conversation's messages sequentially. Two messages of one conversation overlapped. Wait for the first.
  • Your system_prompt has no effect. run.query() replaces it. Put your code’s prompt in agent_config(..., fallback=...).
  • A run stops early after adding skills. Each load_skill call is one more turn. Leave room under max_turns.
  • A query() isn’t traced under init(claude_agent_sdk=True). You imported query by name before calling init(), so you hold the unpatched function. DECIMAL_AUTO_TRACE has no value for this framework: use the flag in code.
  • The model never loads a skill. After a run, support.skill_names lists the skills on its list. With no key, an empty list means .decimal/skills.toml lists nothing. With a key, check that the agent gets the skill.
  • No load_skill tool on the run. The tool is added only when the run lists skills. With DECIMALAI_LOAD_SKILL_TOOL=0 or decimalai.init(load_skill_tool=False), the text of the skills picked for each run goes into the system text instead. The other switches are in Turn it off.