Getting Started with Agentic AI Using Claude
You’ve seen the AI demos. A chatbot answers questions, writes code, or drafts emails. That’s impressive, but it’s passive—it waits for you to ask.
Now imagine an AI that doesn’t wait. It reads your project requirements, fetches data from an API, runs a script to process it, checks the output for errors, and emails you a report—all without you typing a single follow-up prompt. That’s Agentic AI.
This tutorial will teach you exactly that. We’ll demystify Agentic AI and show you how to build your first autonomous agent using Claude (Anthropic’s powerful language model). You’ll learn:
- What Agentic AI is and how it differs from a simple chatbot.
- How to give an AI tools and let it “think” step-by-step.
- How to get started with Claude’s API and write a simple agent.
No prior experience with agents is needed. Just basic Python and a desire to build something that works for you.
What is Agentic AI? (And Why Isn’t It Just a Chatbot?)
Plain-English definition: Agentic AI is an AI that can independently decide what actions to take to achieve a goal. A chatbot answers your question; an agent pursues an objective.
How it works under the hood: A standard LLM (like Claude in its simplest form) is a prediction engine. It predicts the next word in a sentence. An agent wraps that LLM with a loop: 1) The AI receives a task. 2) It “reasons” about what to do next. 3) It chooses an action from a set of tools we give it. 4) The tool’s result is fed back into the AI. 5) It repeats steps 2-4 until the task is done.
Real-world analogy: A chatbot is a brilliant tutor who only answers your spoken questions. An agent is that same tutor, but you give them a key to your lab, a list of experiments, and say: “Find out why the reactor is overheating.” They can now run tests, check logs, and come back with an answer.
Code example: Here’s the simplest version. This code doesn’t use a real API, but it shows the loop.
# A simplified agent loop
def simple_agent(task):
response = ask_claude("What is the first step to: " + task)
# Agent can access a "tool" of its own reasoning
if "find" in response:
result = perform_search(response)
elif "calculate" in response:
result = perform_calculation(response)
else:
result = "Task unclear, ask for clarification"
# Check if done
if is_task_complete(task, result):
return result
else:
# Continue the loop
return simple_agent(task + " (after doing: " + result + ")")
# This is a loop, not a single turn. That's the core difference.
Expert insight: A common gotcha is thinking an agent needs complex code. It doesn’t. The loop is simple. The magic is in the prompting and tool design. A poorly described tool is like giving someone a screwdriver but saying “use the pointy thing”—the AI will misuse it.
Claude: The Brain of Your Agent
Plain-English definition: Claude is a large language model (LLM) created by Anthropic. For this tutorial, think of Claude as the ultra-intelligent “brain” that will do the reasoning for your agent.
How it works under the hood: Claude is trained on a vast dataset of text and code. When you give it a prompt (the input text), it predicts the most useful next words to continue the conversation. What makes Claude special for agents is its ability to follow complex instructions and use tools (functions we define) based on what it reads in the prompt.
Real-world analogy: If the agent is the robotic body, Claude is the human pilot inside. The pilot sees a lever (a tool you defined), understands its purpose from the label (the tool description in the prompt), and decides to pull it.
Code example: To use Claude in Python, you’ll need the anthropic package. Here’s how you send a simple message.
from anthropic import Anthropic
# You need an API key from console.anthropic.com
client = Anthropic(api_key="your-api-key-here")
message = client.messages.create(
model="claude-3-5-sonnet-20241022", # A capable model
max_tokens=1024,
messages=[
{"role": "user", "content": "What is the capital of France?"}
]
)
print(message.content[0].text)
Expert insight: The model string matters. “Haiku” is fast and cheap for simple tasks. “Sonnet” is the best balance of speed and intelligence. “Opus” is the most powerful but slower and more expensive. For a beginner agent, start with Sonnet—it’s smart enough to not get confused by your first few tool definitions.
Getting Started: Building Your First Agent with Claude’s API
Plain-English definition: This is the hands-on part. We’ll write a Python script that gives Claude a simple tool—like get_weather(location)—and the ability to decide when to call it.
How it works under the hood: When you use the API, you can define a tool in a specific JSON schema. When you send your prompt, you also send this tool definition. If Claude decides it needs to, say, get the weather, it will return a special response: a tool_use block. Your code must then parse that, call the actual function, and send the result back to Claude.
Real-world analogy: You’re not giving Claude a button to press. You’re showing it a picture of a button with a label “WEATHER”. You tell it: “If you need to know the outside conditions, press this button and I’ll tell you what it says.” Claude can then “press” it by asking for it.
Code example: A functional (but simplified) weather agent.
from anthropic import Anthropic
client = Anthropic(api_key="YOUR_API_KEY")
# Step 1: Define the tool
tools = [
{
"name": "get_weather",
"description": "Get the current weather for a city",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location"]
}
}
]
# Step 2: Send message with tool
response = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
tools=tools,
messages=[{"role": "user", "content": "What's the weather in London?"}]
)
# Step 3: Check if Claude wants to use a tool
if response.stop_reason == "tool_use":
tool_call = response.content[-1] # The tool use block
# Step 4: Actually call the function
if tool_call.name == "get_weather":
city = tool_call.input["location"]
# In reality, you'd call a real weather API here
real_weather_data = {"temp": 15, "condition": "cloudy"}
# Step 5: Send the result back to Claude
result_message = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
tools=tools,
messages=[
{"role": "user", "content": "What's the weather in London?"},
{"role": "assistant", "content": response.content},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": tool_call.id,
"content": str(real_weather_data)
}
]
}
]
)
print(result_message.content[0].text) # Claude reads the data and responds
Expert insight: The tricky part is Step 5. You have to include the entire conversation history. A common mistake is only sending the last message. Claude needs the full context: the original question, its tool use request, and the tool’s result. Miss this, and it will “forget” what it was doing.
Comparison: Agent vs. Chatbot
| Feature | Simple Chatbot | Agentic AI (with Claude) |
|---|---|---|
| Initiation | Waits for user prompt | Can act on a defined goal |
| Tools | None (just text) | Can use tools (APIs, code, databases) |
| Loop | Single turn | Multi-step loop until goal is met |
| Decision Making | Just predicts next word | Decides which tool to call next |
| State | Forgets after context limit | Manages its own progress towards a goal |
This table summarizes the core shift. To build an agent, you are building the loop and the tools. Claude provides the reasoning.
Key Takeaways
- Agentic AI = An AI that can independently decide and execute actions to achieve a goal.
- Claude is the reasoning engine that decides what to do.
- Tools are functions you define (e.g.,
search_web,run_code); you tell Claude about them via a JSON schema. - The Agent Loop is the core pattern: Task → Reason → Act (call tool) → Observe Result → Repeat.
- Getting Started means: 1) Get a Claude API key, 2) Define a simple tool, 3) Write the loop that handles tool_use responses.
- The gotcha: Never skip the full conversation history when sending the tool result back to Claude. Your agent will become amnesiac.
- Next step: Try giving Claude a
python_repltool (a sandboxed Python interpreter) and ask it to “Calculate the compound interest of $1000 at 5% over 10 years.” Watch it decide to write and run code.
Your AI doesn’t have to be passive anymore. Go build something that acts on its own.
Comments