-
Notifications
You must be signed in to change notification settings - Fork 603
Closed
Labels
bugSomething isn't workingSomething isn't workingplannedThe issue is planned and will be resolved. Claude should never use this label, only humans.The issue is planned and will be resolved. Claude should never use this label, only humans.
Description
Bug Report: Custom Agents Not Registered When System Prompt Exceeds Token Limit
Summary
Custom agents defined in ClaudeAgentOptions are silently ignored by ClaudeSDKClient when the prompt is too large. The init message only shows default Cursor agents instead of the custom agents, with no error or warning about token limits being exceeded.
Environment
- Package:
claude-agent-sdkv0.1.6 - Python: 3.13.7
- OS: macOS (darwin 24.4.0)
Expected Behavior
When providing custom agents via ClaudeAgentOptions:
- Custom agents should appear in the init message
agentsarray - OR an error/warning should be raised if the system prompt + agent definitions exceed token limits
- Token limit constraints should be documented
'agents': ['general-purpose', 'statusline-setup', 'Explore', 'Plan', 'custom_agent', ...]Actual Behavior
When the system prompt is large:
- Custom agents are silently ignored - no error or warning
- Init message only contains default Cursor agents:
'agents': ['general-purpose', 'statusline-setup', 'Explore', 'Plan']- The
Tasktool cannot delegate to custom agents and falls back tosubagent_type='general-purpose' - No indication that token limits were exceeded
Minimal Reproducible Example
✅ Working: Small System Prompt
from claude_agent_sdk import ClaudeSDKClient, ClaudeAgentOptions
from claude_agent_sdk.types import AgentDefinition
agents = {
"custom_agent": AgentDefinition(
description="A custom specialist agent",
prompt="You are a custom agent.",
tools=["Read", "Write"],
model="sonnet",
),
}
# Small system prompt - works fine
options = ClaudeAgentOptions(
system_prompt="You are an orchestrator. Delegate tasks to custom_agent.",
model="claude-sonnet-4-5-20250929",
allowed_tools=["Task", "Read", "Write"],
agents=agents # ✅ This works - agents appear in init message
)
async with ClaudeSDKClient(options=options) as client:
await client.query("Test query")
async for message in client.receive_response():
if hasattr(message, 'subtype') and message.subtype == 'init':
print(message.data.get('agents'))
# Output: ['general-purpose', ..., 'custom_agent'] ✅❌ Broken: Large System Prompt (Exceeds Token Limit)
from claude_agent_sdk import ClaudeSDKClient, ClaudeAgentOptions
from claude_agent_sdk.types import AgentDefinition
agents = {
"custom_agent": AgentDefinition(
description="A custom specialist agent",
prompt="You are a custom agent.",
tools=["Read", "Write"],
model="sonnet",
),
}
# Large system prompt (e.g., >8K tokens with detailed instructions)
large_prompt = """
You are an orchestrator agent.
[... extensive instructions ...]
[... detailed workflow descriptions ...]
[... multiple sections of guidance ...]
[... examples and edge cases ...]
# This prompt is several thousand tokens
""" * 1000 # Simulate large prompt
options = ClaudeAgentOptions(
system_prompt=large_prompt,
model="claude-sonnet-4-5-20250929",
allowed_tools=["Task", "Read", "Write"],
agents=agents # ❌ Silently ignored due to token limit!
)
async with ClaudeSDKClient(options=options) as client:
await client.query("Test query")
async for message in client.receive_response():
if hasattr(message, 'subtype') and message.subtype == 'init':
print(message.data.get('agents'))
# Output: ['general-purpose', 'statusline-setup', 'Explore', 'Plan'] ❌
# custom_agent is missing! No error or warning!Investigation Findings
-
Internal logging confirms agents are passed correctly:
logger.info(f"agents dict: {list(agents.keys())}") # Output: ['custom_agent', 'another_agent', ...] logger.info(f"options.agents: {list(options.agents.keys())}") # Output: ['custom_agent', 'another_agent', ...]
-
But init message shows only defaults:
{'subtype': 'init', 'data': {..., 'agents': ['general-purpose', 'statusline-setup', 'Explore', 'Plan'], ...}} -
Consequence: The
Tasktool cannot delegate to custom agents and falls back to:Task(description="...", subagent_type="general-purpose") # Wrong! # Instead of: Task(description="...", agent="custom_agent") # Correct!
Suspected Root Cause
The SDK appears to have an undocumented token limit for the combined system prompt + agent definitions. When this limit is exceeded:
- Silent Truncation: Custom agents are silently dropped without any error or warning
- No Validation: The SDK doesn't validate or warn about token limits before initialization
- Unclear Limits: Documentation doesn't specify:
- What the token limit is for system prompts
- Whether agent definitions count toward this limit
- How the limit is calculated
- No Error Handling: Users have no way to know their agents were ignored until runtime behavior is incorrect
Thank you!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingplannedThe issue is planned and will be resolved. Claude should never use this label, only humans.The issue is planned and will be resolved. Claude should never use this label, only humans.