Problem
Claudette provides the contents function to extract text content from responses, but there's no equivalent utility for extracting tool usage information (tool name, arguments, etc.) from responses. This makes it difficult to analyze or log tool usage patterns.
Steps to Reproduce
- Use Claudette to make a tool call
- Try to extract tool usage information from the response
- Need to manually parse the message object to find tool usage
Current Workaround
Currently, users need to manually extract tool usage information like this:
def extract_tool_usage(message):
if not hasattr(message, 'content') or isinstance(message.content, str):
return []
tool_uses = [i for i in message.content if getattr(i, 'type', None) == 'tool_use']
result = []
for tool in tool_uses:
result.append({
'name': tool.name,
'input': tool.input,
'id': tool.id
})
return result
Impact
This lack of a built-in utility makes it harder to:
- Log and analyze tool usage patterns
- Extract tool arguments for debugging
- Build higher-level abstractions on top of tool usage
Proposed Solution
Add a utility function similar to contents that extracts tool usage information:
def tool_usage(r):
"""Helper to get tool usage information from Claude response `r`."""
if not hasattr(r, 'content') or isinstance(r.content, str):
return []
tool_uses = [i for i in r.content if getattr(i, 'type', None) == 'tool_use']
result = []
for tool in tool_uses:
result.append({
'name': tool.name,
'input': tool.input,
'id': tool.id
})
return result
This would provide a consistent and convenient way to extract tool usage information, similar to how contents works for text content.
Problem
Claudette provides the
contentsfunction to extract text content from responses, but there's no equivalent utility for extracting tool usage information (tool name, arguments, etc.) from responses. This makes it difficult to analyze or log tool usage patterns.Steps to Reproduce
Current Workaround
Currently, users need to manually extract tool usage information like this:
Impact
This lack of a built-in utility makes it harder to:
Proposed Solution
Add a utility function similar to
contentsthat extracts tool usage information:This would provide a consistent and convenient way to extract tool usage information, similar to how
contentsworks for text content.