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
- Install the Python SDK and import query, AssistantMessage, TextBlock, and ResultMessage. [readme]
- Use async for over messages from query(prompt=..., options=...), collecting text only from TextBlock items in AssistantMessage. [readme]
- 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
- Python 3.10+, claude-agent-sdk, and a supported Claude Code authentication setup.
Permissions
- Submit only the scoped task prompt; store output only in a caller-approved log location.
Limitations
Model output still needs application validation; local SDK calls require supported Claude Code authentication and CLI runtime.
Pinned upstream source
- 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