Register and share your invite link to earn from video plays and referrals.

cv usk
@cv_usk
AI / Software Research Notes AI Agent, LLMOps, MLOps, Software Architecture ๆŠ•็จฟใฏๅ€‹ไบบใฎๆ„่ฆ‹ใงใ™ใ€‚
Joined May 2026
279 Following    408 Followers
# Useful but Little-Known Features of Claude Agent SDK ๐ŸŒ Want to pause a subagent and pick up where it left off later? Resume keeps the full conversation history intact! Claude Agent SDK lets you resume subagents by capturing their session ID and agent ID, retaining all previous tool calls, results, and reasoning. ๐Ÿ“Œ Title: Subagent Resume ๐Ÿ”— URL: ๐Ÿงฉ Overview When a subagent completes, the Agent tool result includes `agentId: `. By saving this `agentId` along with the `session_id`, you can resume the same session using the `resume` option and a prompt like `"Resume agent "`. The resumed subagent retains its full conversation history, including all previous tool calls, results, and reasoning. Note that built-in `Explore` and `Plan` agents are one-shot and do not emit `agentId`, so they cannot be resumed. ๐Ÿ›  How to Use ```python # Python - resuming a subagent import re from claude_agent_sdk import query, ClaudeAgentOptions, AgentDefinition, ToolResultBlock AGENTS = { "endpoint-finder": AgentDefinition( description="Locates and catalogs API endpoints", prompt="Find and document API endpoints", tools=["Read", "Grep", "Glob"], ) } # First run: execute subagent and capture IDs agent_id = None session_id = None async for message in query( prompt="Use the endpoint-finder agent to find all API endpoints", options=ClaudeAgentOptions( allowed_tools=["Read", "Grep", "Glob", "Agent"], agents=AGENTS, ), ): if hasattr(message, "session_id"): session_id = message.session_id for block in getattr(message, "content", None) or []: if isinstance(block, ToolResultBlock): text = str(block.content) if match := "agentId:\s*([\w-]+)", text): agent_id = # Second run: resume the same session with a follow-up if agent_id and session_id: async for message in query( prompt=f"Resume agent {agent_id} and list the top 3 most complex endpoints", options=ClaudeAgentOptions( allowed_tools=["Read", "Grep", "Glob", "Agent"], agents=AGENTS, resume=session_id, # Resume the same session ), ): if hasattr(message, "result"): print(message.result) ``` ๐Ÿ— Integration into Production Systems - Break long analysis tasks into phases, review intermediate results, then resume for follow-up - Persist `session_id` and `agentId` to a database for resumption at any later time - Use custom agents or `general-purpose` (Explore/Plan cannot be resumed) - Pass the same agent definition in the `agents` parameter when resuming ๐Ÿ’ก Use Cases ๐Ÿ”„ Conduct phased investigations of large codebases, reviewing results at each stage ๐Ÿ’ฌ Interactive workflows with follow-up questions on subagent analysis results ๐Ÿ“Š Run detailed follow-up analysis with a narrowed scope after initial exploration โš ๏ธ Caveats - Resuming requires the same `session_id`; new `query()` calls start fresh sessions by default - Built-in `Explore` and `Plan` agents are one-shot and do not output `agentId`, so they cannot be resumed - Subagent transcripts are automatically cleaned up based on `cleanupPeriodDays` (default: 30 days) - Main conversation compaction does not affect subagent transcripts โœจ With resume, subagents become ongoing analysis partners rather than one-shot throwaway tools. Use it for iterative, multi-phase investigations! #ClaudeAgentSDK# #AIAgent#
Show more