๐Ÿ“ LLM & AI

AI Agents: ReAct Loop and Autonomous Actions

P
Author
PyLand Team
๐Ÿ“…
Published
30.06.2026
โฑ๏ธ
Reading time
1 min
๐Ÿ‘๏ธ
Views
335
๐ŸŒณ
Level
Advanced

A chatbot answers questions. An agent takes action: it calls tools, retrieves real data, and uses that data in its response.

Chatbot vs Agent

Chatbot Agent
Data source Training only APIs, files, search
Actions Text only Tool calls
Loops Single request Multiple iterations
Use case Q&A Task automation

The ReAct Pattern

ReAct = Reasoning + Acting. An agent operates in a loop:

User question
       โ†“
  REASON: Claude analyzes โ€” is a tool needed?
       โ†“
   ACT: Tool call (get_weather, read_file, ...)
       โ†“
OBSERVE: We receive the tool result
       โ†“
  REASON: Claude analyzes the result
       โ†“
  (repeat until we have a final answer)
       โ†“
 ANSWER: Final text response

A Simple Agent

import anthropic

client = anthropic.Anthropic()

TOOLS = [
    {
        "name": "get_time",
        "description": "Returns the current time",
        "input_schema": {"type": "object", "properties": {}}
    }
]

def get_time() -> str:
    from datetime import datetime
    return datetime.now().strftime("%H:%M:%S")

def run_agent(question: str) -> str:
    messages = [{"role": "user", "content": question}]

    while True:
        response = client.messages.create(
            model="claude-sonnet-4-6",
            max_tokens=512,
            tools=TOOLS,
            messages=messages,
        )

        if response.stop_reason == "end_turn":
            return next(b.text for b in response.content if hasattr(b, "text"))

        messages.append({"role": "assistant", "content": response.content})
        results = []
        for block in response.content:
            if block.type == "tool_use":
                if block.name == "get_time":
                    result = get_time()
                results.append({
                    "type": "tool_result",
                    "tool_use_id": block.id,
                    "content": result
                })
        messages.append({"role": "user", "content": results})

print(run_agent("What time is it right now?"))

Common Agent Tools

  • Web search โ€” up-to-date information
  • File reading โ€” local documents
  • HTTP requests โ€” external APIs
  • Code execution โ€” computations
  • Database โ€” data storage and retrieval

Your reaction to the article

๐Ÿ’ฌ Comments (0)

๐Ÿ” Sign in to leave a comment
๐Ÿšช Login
๐Ÿ’ญ

No comments yet

Be the first to share your opinion about this article!

๐Ÿ”— Similar

Similar articles

Continue learning with these materials

๐Ÿ“

Pydantic v2: Data Validation in Python

Pydantic validates and converts data through type annotations. It is commonly used in APIs and...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 327
๐Ÿ“

asyncio in Python: Asynchronous Programming

asyncio is Python's standard library for asynchronous code. It lets you execute multiple tasks "simultaneously"...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 317
๐Ÿ“

RAG: Chatting with Documents via Vector Search

RAG (Retrieval-Augmented Generation) is a pattern for working with your own documents. Instead of fine-tuning...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 312
๐ŸŽ“ Continue learning

Courses that cover this material

Visit the course to apply this material in practice.

Neural Networks in Code: 5 AI Projects in Python with Claude Open course curriculum