Build a loop around an inspectable task
Start with a report that summarizes a small library of synthetic notes. A text-only request can work when the notes are already included. A tool-using loop lets Claude discover which notes exist, choose relevant ones and then write the report. The application supplies the tools and executes them, making it possible to measure exactly which data the agent used.
Prepare the SDK and a test fixture
Install the Anthropic Python SDK in an isolated Python environment and configure its API access through the credential mechanism used by your project. Create a test folder with two short notes, one irrelevant file and a deliberately missing identifier. Select a model available to your API organization and begin with a small output budget so the first run is easy to inspect.
Define two tools with explicit contracts
A list_notes tool can return identifiers and titles from the test library. A read_note tool can take an identifier and return the associated text. Describe what each tool returns and when it is useful. For the input schema, require a string identifier drawn from the library's known records. Identifiers keep callers from turning the routine into general filesystem access.
Keep execution under application control
Map each known tool name to a local function and validate the arguments after dispatch. For list_notes, handle a missing or empty library with a useful response. For read_note, reject unknown identifiers and cap the amount of returned text. Use structured success and error information so Claude can distinguish a bad identifier from a note that simply has no content.
Return each result to the corresponding call
Send the task and tool definitions to the Messages API. If Claude requests tools, append its assistant response and execute the requested calls. Add a user message with the corresponding tool_result blocks, carrying the original tool call IDs, and repeat the request. When a response ends the turn, collect its text blocks as the draft report. Treat truncation or a canceled run as an incomplete outcome.
Test the report against the notes
Ask for two recurring themes and the identifiers of the notes that support them. Record the calls and verify that the report refers to notes the application actually returned. Repeat with an empty library and a missing record. A useful run can explain that it lacks evidence, and a useful test can distinguish that from an incorrectly asserted finding.
Bound the loop before expanding it
Set ceilings for total tool calls, output and execution time, and decide what partial information should be returned if a ceiling is reached. Structure logs around a run ID and tool status without copying entire inputs into logs. After the small report is reliable, consider adding search or filtered data retrieval and test each new operation separately before relying on it.
Source documentation
Related reading
Automate Your Dev Workflow with Claude Code
Monthly Claude API credits and how to claim them
Claude Tool Use in Production: Patterns for Building Reliable AI APIs