2026年3月14日土曜日

Part 2/6: Setting Up Claude Skills and Your Development Environment: The First Steps — From Obtaining an API Key to Installing the SDK and Making Your First Skill Call

Introduction

In Part 1 of this series, we explained the concept of Claude Skills and its place within AI agent architecture. In this article (Part 2), we will walk step by step through the process of setting up a working development environment hands-on and successfully making your first Skill call. Parts 3 and beyond will move into designing and combining more complex Skills, so it is a prerequisite to have the environment setup covered in this article fully completed.


Step 1: Obtaining an Anthropic API Key

The foundation for running Claude Skills is access to Anthropic's API. First, visit the Anthropic console (https://console.anthropic.com) and create an account. You can generate a new key from the "API Keys" section of the dashboard. [Source: https://docs.anthropic.com/en/api/getting-started]

The best practice is to manage your obtained API key as an environment variable. Avoid hardcoding it directly into a .env file or shell profile.

export ANTHROPIC_API_KEY="sk-ant-xxxxxxxxxxxx" 

An API key leak is not only a financial risk but also directly leads to security incidents, so be sure to add it to .gitignore as well.


Step 2: Setting Up the Python Environment and Installing the SDK

The recommended Python version is 3.9 or higher. Create a virtual environment and then install the official Anthropic Python SDK.

python -m venv claude-skills-env source claude-skills-env/bin/activate  # On Windows: claude-skills-env\Scripts\activate pip install anthropic 

The Anthropic Python SDK is managed on PyPI and includes a full set of agent-oriented features, including tool use (the equivalent of Function Calling). [Source: https://github.com/anthropics/anthropic-sdk-python]

After installation, verify the version.

python -c "import anthropic; print(anthropic.__version__)" 

At the time of writing (March 2026), the 0.49.x line is provided as the stable release. You can check the SDK release notes at any time in the GitHub Changelog. [Source: https://github.com/anthropics/anthropic-sdk-python/blob/main/CHANGELOG.md]


Step 3: Defining and Calling Your First Skill

A "Skill" in Claude Skills is defined as a tool that the model can call. Below is a minimal example of a Skill definition.

import anthropic import json  client = anthropic.Anthropic()  # Skill (Tool) definition tools = [     {         "name": "get_current_date",         "description": "Returns the current date",         "input_schema": {             "type": "object",             "properties": {},             "required": []         }     } ]  # Attach the Skill to the model and call the API response = client.messages.create(     model="claude-3-7-sonnet-20250219",     max_tokens=1024,     tools=tools,     messages=[         {"role": "user", "content": "What is today's date?"}     ] )  print(response.content) 

When the model decides to make a tool call, stop_reason will be "tool_use" and the content block will contain a tool_use object. The basic loop is: once you receive this tool_use block, execute the Skill's logic on the application side and return the result to the model as a tool_result. [Source: https://docs.anthropic.com/en/docs/build-with-claude/tool-use]


Step 4: Returning tool_result and Completing the Turn

# Retrieve the tool_use block tool_use_block = next(b for b in response.content if b.type == "tool_use")  # Execute the Skill's logic (here we return a fixed value) skill_result = {"date": "2026-03-14"}  # Return the tool_result to the model to obtain the final response final_response = client.messages.create(     model="claude-3-7-sonnet-20250219",     max_tokens=1024,     tools=tools,     messages=[         {"role": "user", "content": "What is today's date?"},         {"role": "assistant", "content": response.content},         {             "role": "user",             "content": [                 {                     "type": "tool_result",                     "tool_use_id": tool_use_block.id,                     "content": json.dumps(skill_result)                 }             ]         }     ] )  print(final_response.content[0].text) 

This two-turn structure is the minimal execution unit of Claude Skills. The model receives the tool_result and generates a final answer in natural language.


Common Pitfalls

  • API key not set: An AuthenticationError will occur. Verify that the environment variable has been exported correctly.
  • Incomplete input_schema: "type": "object" and "properties" are required fields. Omitting them will result in a validation error.
  • Overlooking the tool_use block: If you treat the content directly as text without checking stop_reason, the application will crash.

Summary and Preview of the Next Part

In this article, we built a minimal working configuration, from obtaining an API key to installing the SDK, making the first Skill call, and returning the tool_result. In the next part (Part 3), we will dive into design patterns for multi-tool agents that combine multiple Skills, as well as the implementation of parallel tool_use processing. Please proceed to the next step with your environment fully ready.


Category: LLM | Tags: Claude, Anthropic, AIエージェント, SDK, ToolUse

0 件のコメント:

コメントを投稿