AnswerDotAI / AnswerDotAI/claudette

Add utility function for extracting tool usage from Claudette responses

Open
#81 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
316
Forks
43
PR merge metrics
No merged PRs in 30d

Description

## 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
1. Use Claudette to make a tool call
2. Try to extract tool usage information from the response
3. Need to manually parse the message object to find tool usage

## Current Workaround
Currently, users need to manually extract tool usage information like this:

```python
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:
1. Log and analyze tool usage patterns
2. Extract tool arguments for debugging
3. Build higher-level abstractions on top of tool usage

## Proposed Solution
Add a utility function similar to `contents` that extracts tool usage information:

```python
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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the existing `contents` utility and the response-handling entry point in Claudette. Compare the proposed `tool_usage` behavior with the response content shapes shown here, including text-only and tool-use responses. Done means the utility returns the requested tool name, input, and id consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.