📝 LLM & AI

AI Agents: ReAct Loop and Autonomous Actions

P
Author
Pyland
📅
Published
30.06.2026
⏱️
Reading time
1 min
👁️
Views
103
🌳
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": "Возвращает текущее время",
        "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

📝

What is an ORM

ORM (Object-Relational Mapping) is a technology that lets you work with a database through Python...

📅 30.06.2026 👁️ 131
📝

httpx: A Modern HTTP Client for Python

httpx is a next-generation HTTP client. Its interface is similar to requests, but it supports...

📅 30.06.2026 👁️ 108
📝

Typer: CLI Applications Without the Boilerplate

Typer builds CLIs from Python type annotations. No argparse, no manual parsing — just decorators...

📅 30.06.2026 👁️ 88

Did you like the article?

Subscribe to our updates and receive new articles first. Grow with PyLand!