← Talks

How to start building agents · Nov 30, 2026

From “hello” to agent

Build an AI agent from scratch in eight curl commands you copy and paste. No code to write. An agent is a loop, a function and a human who says yes.

An agent is a loop

The word makes it sound harder than it is. You send the model a message. It answers, or it asks to run one of your functions. You run it, send back the result, and it decides again. Repeat until it’s done.

We’ll walk that loop in eight curl commands. You don’t write any code. Copy each command, paste it into a terminal and read the JSON that comes back. Every command is complete on its own: the whole conversation is written inside it, including the model’s earlier replies, because the model remembers nothing between requests. You write its past, and you play the part of the code.

  • Steps 1–4 make a chatbot: it talks, remembers and follows instructions.
  • Steps 5–7 make it an agent: it asks for an action, and you send back the result.
  • Step 8 makes it an agent with human approval: a person decides what it’s allowed to do.

Setup

You need a terminal (macOS, Linux, or WSL or Git Bash on Windows; PowerShell quotes differently) and an API key from the Claude Console. No budget? All eight run on Groq’s free tier.

export ANTHROPIC_API_KEY=sk-ant-...

Tip: if you have jq, add | jq to the end of any command to pretty-print the reply.

Step 1Say hello

curl https://api.anthropic.com/v1/messages \
  -H "content-type: application/json" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2026-10-21" \
  -d '{
    "model": "claude-opus-5-5",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "hello"}
    ]
  }'

What came back a real run · trimmed

{
  "model": "claude-opus-5-5",
  "id": "msg_011Cha9zUmZcbJiSCC66Ax99",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Hello! How can I help you today?"
    }
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 10,
    "output_tokens": 13
  }
}

One request: your key, a model and a list of messages. The first four lines never change; from here on, only the JSON after -d does.

The reply is JSON. Find "content": a list of blocks, with the answer in a "text" block. "stop_reason": "end_turn" means it’s finished, and "usage" is what you pay for. Some replies also start with a "thinking" block: the model’s private reasoning, empty here, with a long "signature". Skip past it to the "text" block. The % at the end in zsh just means the reply had no trailing newline.

Step 2Tell it your name, then ask

Two pastes. First:

curl https://api.anthropic.com/v1/messages \
  -H "content-type: application/json" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2026-10-21" \
  -d '{
    "model": "claude-opus-5-5",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "my name is Sam"}
    ]
  }'

What came back a real run · trimmed

{
  "model": "claude-opus-5-5",
  "id": "msg_011ChaA2EytrhduTDprRDh5W",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Nice to meet you, Sam! What can I help you with today?"
    }
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 14,
    "output_tokens": 22
  }
}

Then:

curl https://api.anthropic.com/v1/messages \
  -H "content-type: application/json" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2026-10-21" \
  -d '{
    "model": "claude-opus-5-5",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "what is my name?"}
    ]
  }'

What came back a real run · trimmed

{
  "model": "claude-opus-5-5",
  "id": "msg_011ChaA3eo9WKnByTeTYzR8f",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "thinking",
      "thinking": "",
      "signature": "CAQSnQUKEAgUGAI4AUII..."
    },
    {
      "type": "text",
      "text": "I don't know your name. I can't see any personal information about you, and you haven't mentioned it in our conversation. If you'd like to tell me, I'm happy to use it while we chat."
    }
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 13,
    "output_tokens": 76
  }
}

It doesn’t know. Each request stands alone; the model keeps nothing between calls.

Step 3Send the history, so it remembers

curl https://api.anthropic.com/v1/messages \
  -H "content-type: application/json" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2026-10-21" \
  -d '{
    "model": "claude-opus-5-5",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "my name is Sam"},
      {"role": "assistant", "content": "Nice to meet you, Sam."},
      {"role": "user", "content": "what is my name?"}
    ]
  }'

What came back a real run · trimmed

{
  "model": "claude-opus-5-5",
  "id": "msg_011ChaA4xhgTDjVzepMSP2Ve",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "thinking",
      "thinking": "",
      "signature": "CAQSnQUKEAgUGAI4AUII..."
    },
    {
      "type": "text",
      "text": "Your name is Sam. You told me just a moment ago."
    }
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 35,
    "output_tokens": 26
  }
}

Now it knows. You wrote the assistant line yourself, and the model accepted it as its own. “Memory” is just the list of messages you send, and you resend all of it every time. That’s why long conversations get slow and expensive.

Step 4Add a system prompt

curl https://api.anthropic.com/v1/messages \
  -H "content-type: application/json" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2026-10-21" \
  -d '{
    "model": "claude-opus-5-5",
    "max_tokens": 1024,
    "system": "Talk like a pirate. Keep every answer to one sentence.",
    "messages": [
      {"role": "user", "content": "my name is Sam"},
      {"role": "assistant", "content": "Nice to meet you, Sam."},
      {"role": "user", "content": "what is my name?"}
    ]
  }'

What came back a real run · trimmed

{
  "model": "claude-opus-5-5",
  "id": "msg_011ChaA6nKfWoUvSsK9kRfDr",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "thinking",
      "thinking": "",
      "signature": "CAQSnQUKEAgUGAI4AUII..."
    },
    {
      "type": "text",
      "text": "Arr, yer name be Sam, matey, and beggin' yer pardon fer forgettin' me pirate tongue in me last reply!"
    }
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 57,
    "output_tokens": 262
  }
}

Same conversation, different behaviour. The system prompt sits outside the messages and applies to every turn. In real work it’s the agent’s job description and rules.

When we ran it, it even apologized for not talking like a pirate in its last reply: the one you wrote. It really does treat your hand-written history as its own.

Step 5Ask for something it can’t do

curl https://api.anthropic.com/v1/messages \
  -H "content-type: application/json" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2026-10-21" \
  -d '{
    "model": "claude-opus-5-5",
    "max_tokens": 1024,
    "system": "Look at files before answering questions about them.",
    "messages": [
      {"role": "user", "content": "what is in notes.txt?"}
    ]
  }'

What came back a real run · trimmed

{
  "model": "claude-opus-5-5",
  "id": "msg_011ChaA8b6Hp11Vkhi9f4q1n",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "thinking",
      "thinking": "",
      "signature": "CAQSnQUKEAgUGAI4AUII..."
    },
    {
      "type": "text",
      "text": "I don't see a file called **notes.txt** in our conversation, and I don't have a way to open files on your computer or system, so I can't tell you what's in it.\n\nTo share it with me, you can:\n- **Paste the contents** directly into the chat, or\n- **Upload/attach the file**, if your interface supports attachments.\n\nThen I can summarize it, answer questions about it, or help edit it."
    }
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 30,
    "output_tokens": 187
  }
}

It wants to look, but it has no way to. This is where a chatbot stops: it can talk, but it can’t act.

Step 6Give it a tool

curl https://api.anthropic.com/v1/messages \
  -H "content-type: application/json" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2026-10-21" \
  -d '{
    "model": "claude-opus-5-5",
    "max_tokens": 1024,
    "system": "Look at files before answering questions about them.",
    "tools": [{
      "name": "read_file",
      "description": "Read a text file and return its contents.",
      "input_schema": {
        "type": "object",
        "properties": {"path": {"type": "string"}},
        "required": ["path"]
      }
    }],
    "messages": [
      {"role": "user", "content": "what is in notes.txt?"}
    ]
  }'

What came back a real run · trimmed

{
  "model": "claude-opus-5-5",
  "id": "msg_011ChaA9fdQjsc3fyeLxgkLH",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "tool_use",
      "id": "toolu_01VE4tmoZSytaj6iivmsZxN5",
      "name": "read_file",
      "input": {
        "path": "notes.txt"
      }
    }
  ],
  "stop_reason": "tool_use",
  "usage": {
    "input_tokens": 388,
    "output_tokens": 51
  }
}

Look for "stop_reason": "tool_use" and a "tool_use" block: "name": "read_file", "input": {"path": "notes.txt"}. The model is asking you to run read_file. Nothing ran. There is no read_file anywhere; the model can only ask. Whatever happens next is up to your code, and today your code is you.

Step 7Send back the result

Pretend you read the file, and send the model what it “contained”:

curl https://api.anthropic.com/v1/messages \
  -H "content-type: application/json" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2026-10-21" \
  -d '{
    "model": "claude-opus-5-5",
    "max_tokens": 1024,
    "system": "Look at files before answering questions about them.",
    "tools": [{
      "name": "read_file",
      "description": "Read a text file and return its contents.",
      "input_schema": {
        "type": "object",
        "properties": {"path": {"type": "string"}},
        "required": ["path"]
      }
    }],
    "messages": [
      {"role": "user", "content": "what is in notes.txt?"},
      {"role": "assistant", "content": [
        {"type": "tool_use", "id": "toolu_01", "name": "read_file",
         "input": {"path": "notes.txt"}}
      ]},
      {"role": "user", "content": [
        {"type": "tool_result", "tool_use_id": "toolu_01",
         "content": "Rehearse the talk. Check the Wi-Fi. Bring an HDMI adapter."}
      ]}
    ]
  }'

What came back a real run · trimmed

{
  "model": "claude-opus-5-5",
  "id": "msg_011ChaAC47L51ho4KL7112W6",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "notes.txt is a short to-do list with three items:\n\n1. Rehearse the talk.\n2. Check the Wi-Fi.\n3. Bring an HDMI adapter."
    }
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 476,
    "output_tokens": 59
  }
}

It answers from the “file.” Two things to notice:

  • The tool request goes into the history as an assistant message, and the result follows it as a user message with the same id (toolu_01). That’s how the model matches results to requests. We made the id up; in a real loop you copy it from the reply.
  • No file was read. The model believes whatever comes back from a tool, so be careful what your tools return. Try it: change the result to something untrue.

That’s the loop. Send, read stop_reason, run the tool, send the result, repeat until stop_reason is end_turn. You just did one turn of it by hand. That’s what an agent is.

Step 8Say no

Same request, but you decline instead of running the tool:

curl https://api.anthropic.com/v1/messages \
  -H "content-type: application/json" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2026-10-21" \
  -d '{
    "model": "claude-opus-5-5",
    "max_tokens": 1024,
    "system": "Look at files before answering questions about them.",
    "tools": [{
      "name": "read_file",
      "description": "Read a text file and return its contents.",
      "input_schema": {
        "type": "object",
        "properties": {"path": {"type": "string"}},
        "required": ["path"]
      }
    }],
    "messages": [
      {"role": "user", "content": "what is in notes.txt?"},
      {"role": "assistant", "content": [
        {"type": "tool_use", "id": "toolu_01", "name": "read_file",
         "input": {"path": "notes.txt"}}
      ]},
      {"role": "user", "content": [
        {"type": "tool_result", "tool_use_id": "toolu_01",
         "content": "The user declined to share this file."}
      ]}
    ]
  }'

What came back a real run · trimmed

{
  "model": "claude-opus-5-5",
  "id": "msg_011ChaAH2DN8wvTeXAih5U56",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "thinking",
      "thinking": "",
      "signature": "CAQSnQUKEAgUGAI4AUII..."
    },
    {
      "type": "text",
      "text": "I couldn't read notes.txt because access to that file was declined, so I can't tell you what's in it.\n\nIf you want me to look at it, you could allow access and I'll try again, or paste the contents here."
    }
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 453,
    "output_tokens": 110
  }
}

“No” isn’t an error. It goes back as the result, and the model works with it. That’s human approval: the model asks, a person decides. Reading a file is harmless, but the moment your tools write, delete, send or deploy, this is the step that matters.

Autonomous execution, not autonomous approval.

Next: let code do the pasting

You were the loop: you read each reply, decided what to run and pasted the next request. Do that in code, with a limit on how many rounds it can run, and you’ve built an agent. The curl/ scripts build it up a step at a time in about 60 lines of bash, with a real read_file and a y/N prompt. Here is the finished loop from step8.sh, to read rather than paste: it needs the helpers the script loads first, and it’s bash, not zsh.

Excerpt from step8.sh read, don’t paste

for ((i = 1; i <= 10; i++)); do        # a cap on rounds
  ask; remember                         # send; add its reply
  [ "$(stop_reason)" = tool_use ] || break
  file=$(tool_arg path)
  read -r -p "allow read_file $file? [y/N] " ok
  if [ "$ok" = y ]; then
    read_file "$file" | answer          # send the result
  else
    echo "The user declined." | answer
  fi
done

ask is the curl command you’ve been pasting. remember adds the reply to the messages, and answer sends a tool result back. To run it, paste this. It downloads the scripts into a new folder with curl, then starts the agent with bash:

mkdir hello-agent && cd hello-agent
base=https://fullstackclouddeveloper.com/talks/from-hello-to-agent/curl
for f in helpers.sh 01-hello.json 02-tools.json notes.txt README.md \
         step1.sh step2.sh step3.sh step4.sh \
         step5.sh step6.sh step7.sh step8.sh; do
  curl -sO $base/$f
done
bash step8.sh

They need jq too (it ships with recent macOS). The README walks through each script; helpers.sh is every helper, one curl or jq command each. For Groq, use curl/groq as the base.

Next: route before you loop

Not every request needs every tool, the longest instructions and the biggest model. In AlwaysBuilt, the development environment I’m building, every chat message goes through an intent router first: one small, cheap classification call decides what kind of request it is, and that picks the tools, instructions and model for the loop. In paste terms: one extra request to a small model, and its answer decides which system and tools go into the next one.

Three lessons from running it:

  • Route on what a request is, not on keywords. “Build a Jira clone with auth” went to the backend route on 26 of 26 turns, because of the word “auth,” so no design guidance ever reached the model. Each route now says what it’s for, what it’s not for, and gives examples.
  • Test the router like code. Every misrouted request became a test case.
  • The model classifies; code decides. Hard rules, like “anything that changes the page gets at least the mid-tier model,” live in code. If the classifier is down, it says so instead of guessing.

Next: the same loop in Python

Once you’ve been the loop, every SDK reads the same way. The JSON you pasted is the JSON the SDK sends: the messages become a Python list, each paste becomes client.messages.create(...), and the result you wrote becomes a tool_result your code appends. Anthropic’s SDK also has a tool runner that writes the loop for you; it makes much more sense after you’ve done it by hand.

On Groq’s free tier

The same eight pastes work on Groq, which uses OpenAI’s request format. Get a key at console.groq.com, then export GROQ_API_KEY=gsk_.... What’s different:

  • The key goes in an Authorization: Bearer header, and the system prompt is the first message, with "role": "system".
  • The reply is in choices[0].message. finish_reason is tool_calls when it wants a tool, and the arguments arrive as a JSON string.
  • A tool result is a message with "role": "tool" and the request’s tool_call_id.
Show the eight Groq commands

1. Say hello

curl https://api.groq.com/openai/v1/chat/completions \
  -H "content-type: application/json" \
  -H "Authorization: Bearer $GROQ_API_KEY" \
  -d '{
    "model": "llama-3.3-70b-versatile",
    "messages": [
      {"role": "user", "content": "hello"}
    ]
  }'

2. Tell it your name

curl https://api.groq.com/openai/v1/chat/completions \
  -H "content-type: application/json" \
  -H "Authorization: Bearer $GROQ_API_KEY" \
  -d '{
    "model": "llama-3.3-70b-versatile",
    "messages": [
      {"role": "user", "content": "my name is Sam"}
    ]
  }'

2. Then ask

curl https://api.groq.com/openai/v1/chat/completions \
  -H "content-type: application/json" \
  -H "Authorization: Bearer $GROQ_API_KEY" \
  -d '{
    "model": "llama-3.3-70b-versatile",
    "messages": [
      {"role": "user", "content": "what is my name?"}
    ]
  }'

3. Send the history

curl https://api.groq.com/openai/v1/chat/completions \
  -H "content-type: application/json" \
  -H "Authorization: Bearer $GROQ_API_KEY" \
  -d '{
    "model": "llama-3.3-70b-versatile",
    "messages": [
      {"role": "user", "content": "my name is Sam"},
      {"role": "assistant", "content": "Nice to meet you, Sam."},
      {"role": "user", "content": "what is my name?"}
    ]
  }'

4. Add a system prompt

curl https://api.groq.com/openai/v1/chat/completions \
  -H "content-type: application/json" \
  -H "Authorization: Bearer $GROQ_API_KEY" \
  -d '{
    "model": "llama-3.3-70b-versatile",
    "messages": [
      {"role": "system", "content": "Talk like a pirate. Keep every answer to one sentence."},
      {"role": "user", "content": "my name is Sam"},
      {"role": "assistant", "content": "Nice to meet you, Sam."},
      {"role": "user", "content": "what is my name?"}
    ]
  }'

5. Ask for something it can’t do

curl https://api.groq.com/openai/v1/chat/completions \
  -H "content-type: application/json" \
  -H "Authorization: Bearer $GROQ_API_KEY" \
  -d '{
    "model": "llama-3.3-70b-versatile",
    "messages": [
      {"role": "system", "content": "Look at files before answering questions about them."},
      {"role": "user", "content": "what is in notes.txt?"}
    ]
  }'

6. Give it a tool

curl https://api.groq.com/openai/v1/chat/completions \
  -H "content-type: application/json" \
  -H "Authorization: Bearer $GROQ_API_KEY" \
  -d '{
    "model": "llama-3.3-70b-versatile",
    "tools": [{
      "type": "function",
      "function": {
        "name": "read_file",
        "description": "Read a text file and return its contents.",
        "parameters": {
          "type": "object",
          "properties": {"path": {"type": "string"}},
          "required": ["path"]
        }
      }
    }],
    "messages": [
      {"role": "system", "content": "Look at files before answering questions about them."},
      {"role": "user", "content": "what is in notes.txt?"}
    ]
  }'

7. Send back the result

curl https://api.groq.com/openai/v1/chat/completions \
  -H "content-type: application/json" \
  -H "Authorization: Bearer $GROQ_API_KEY" \
  -d '{
    "model": "llama-3.3-70b-versatile",
    "tools": [{
      "type": "function",
      "function": {
        "name": "read_file",
        "description": "Read a text file and return its contents.",
        "parameters": {
          "type": "object",
          "properties": {"path": {"type": "string"}},
          "required": ["path"]
        }
      }
    }],
    "messages": [
      {"role": "system", "content": "Look at files before answering questions about them."},
      {"role": "user", "content": "what is in notes.txt?"},
      {"role": "assistant", "content": null, "tool_calls": [
        {"id": "call_01", "type": "function",
         "function": {"name": "read_file", "arguments": "{\"path\": \"notes.txt\"}"}}
      ]},
      {"role": "tool", "tool_call_id": "call_01",
       "content": "Rehearse the talk. Check the Wi-Fi. Bring an HDMI adapter."}
    ]
  }'

8. Say no

curl https://api.groq.com/openai/v1/chat/completions \
  -H "content-type: application/json" \
  -H "Authorization: Bearer $GROQ_API_KEY" \
  -d '{
    "model": "llama-3.3-70b-versatile",
    "tools": [{
      "type": "function",
      "function": {
        "name": "read_file",
        "description": "Read a text file and return its contents.",
        "parameters": {
          "type": "object",
          "properties": {"path": {"type": "string"}},
          "required": ["path"]
        }
      }
    }],
    "messages": [
      {"role": "system", "content": "Look at files before answering questions about them."},
      {"role": "user", "content": "what is in notes.txt?"},
      {"role": "assistant", "content": null, "tool_calls": [
        {"id": "call_01", "type": "function",
         "function": {"name": "read_file", "arguments": "{\"path\": \"notes.txt\"}"}}
      ]},
      {"role": "tool", "tool_call_id": "call_01",
       "content": "The user declined to share this file."}
    ]
  }'

The model is llama-3.3-70b-versatile. If it errors, check Groq’s model list for what’s current.

When something goes wrong

  • x-api-key header is required: run the export line in this terminal window first.
  • dquote> or quote> and nothing happens: the paste was cut off, or a message has an apostrophe in it. The JSON sits inside single quotes, so write “what is”, not “what’s”. Press Ctrl-C and paste again.
  • tool_use ids were found without tool_result blocks: the tool_result must come right after the tool_use, with the same id.