Lesson

Building a Simple AI Agent

We have all the pieces: API Keys, System Prompts, Chat History, and Tool Calling. When you put them all together, you are no longer just writing scripts—you are building an AI Agent.

An Agent is a system that observes its environment, makes decisions, and takes action.

The Core Agent Loop

Let's look at the pseudo-code for a basic AI Agent that can help a user manage their calendar.

  1. Setup: You define the tools: get_schedule(date), add_meeting(time, person), and cancel_meeting(id). You define the System Prompt: "You are an executive assistant. Manage the user's calendar. Be polite but brief." You initialize chatHistory = [].

  2. The User Trigger: User says: "Do I have time to meet with Sarah tomorrow afternoon? If so, book it for 2pm."

  3. The First API Call (Observation): Your server sends the prompt and tools to Claude. Claude realizes it doesn't know the schedule. Claude responds with a tool_use request for get_schedule("tomorrow").

  4. The First Action (Execution): Your server intercepts the request and runs get_schedule("tomorrow"). It finds a meeting from 1pm to 3pm.

  5. The Second API Call (Decision): Your server appends the result to chatHistory and sends it back to Claude. Claude reads the result: Ah, there is a meeting at 2pm. I cannot book Sarah then. Claude does NOT answer the user yet. Instead, Claude decides to take another action based on the new data! Claude responds with a new text block: "You have a conflict at 2pm. Would 3:30pm work instead?"

  6. The User Loop: The user replies: "Yes, 3:30 is fine."

  7. The Final Action: Claude reads the approval and sends a tool_use request for add_meeting("3:30pm", "Sarah"). Your server executes the addition, returns the success message to Claude, and Claude finally tells the user: "Done! Sarah is booked for 3:30."

The Magic of Agency

Notice what happened in step 5. You didn't write an if/else statement in your code saying "If there is a conflict, suggest a new time."

Claude made that logical leap entirely on its own based on the System Prompt. This is the magic of Agentic AI. You provide the tools (the hands) and the rules (the system prompt), and the LLM acts as the central brain, dynamically routing logic and executing tools to achieve the user's goal.

Ready to test your understanding? Take the quiz to reinforce what you learned.

© 2026 Ant Skillsv.26.07.07-23:01