Agent Wealth HubFree public resources
中文 EN العربية

Back to catalog / Agent runtime

Run a one-shot agent task with query

Run one task through the async message stream and distinguish text blocks from its final result.

Goal

Complete an auditable one-shot task with query() and inspect its terminal result.

Steps

  1. Install the Python SDK and import query, AssistantMessage, TextBlock, and ResultMessage. [readme]
  2. Use async for over messages from query(prompt=..., options=...), collecting text only from TextBlock items in AssistantMessage. [readme]
  3. Record ResultMessage.subtype, result, and total_cost_usd; do not treat an intermediate message as success. [readme]

How to verify

Confirm a terminal ResultMessage and associate its result and cost fields with the task ID.

Troubleshooting

If no terminal message arrives, check for async-iteration cancellation or CLI disconnection; do not infer success from the last text block.

Permissions

Prerequisites

Permissions

Limitations

Model output still needs application validation; local SDK calls require supported Claude Code authentication and CLI runtime.

Pinned upstream source

https://github.com/anthropics/claude-agent-sdk-python/blob/b6e9d12fe1cc98dde988ab7b7713c1feeee50c6c/README.md

Repository
anthropics/claude-agent-sdk-python
File path
README.md
Pinned commit
b6e9d12fe1cc98dde988ab7b7713c1feeee50c6c
Source checked
2026-10-14 · Reviewed against the pinned upstream source

Repository metrics

These values describe the upstream repository, not popularity or likes for an individual skill or playbook.

Stars
Not collected
Forks
Not collected
Observed at
Not collected

No metrics snapshot is available yet.

License: MIT

Main topic

Take a coding Agent change from context to verification

Related resources