agentic_ai_basics

agentic_loop

Agentic Loop — the core observe → think → act → observe cycle an agent runs until the task is done or halted, in its simplest possible form: a multi-turn chat built on top of a stateless API.

basic_agentic_loop.py

A continuous chat agent. Keeps asking you questions and answering on any topic until you type exit. Maintains full conversation history across turns.

Concepts covered

Mapping the loop onto observe → think → act → observe

This template’s loop is the cycle at its most stripped-down — worth naming explicitly, since every other template in Execution_Loops/ and most of the rest of the repo is a variation on it:

Phase In this template
Observe input("You: ") — read what the user just said
Think the API call itself — Claude reasons over the accumulated messages history
Act print(f"\nClaude: {reply}\n") — the only “action” here is responding in text; there’s no tool call, so nothing actually changes in the world
Observe (again) back to input("You: ") for the next cycle

The honest limitation: because this loop never calls a tool, “Act” never touches anything external, and there’s nothing for a subsequent “Observe” to notice besides the user’s next message — the cycle only closes through the human, not through the environment. For the version where Act means calling a tool and Observe means reading back that tool’s real result — the fuller form of the cycle — see ../../Core_Architecture/tool_use/basic_agentic_tools.py.

Run

From the repo root:

pip install -r requirements.txt
export ANTHROPIC_API_KEY=your-key-here
python3 Execution_Loops/agentic_loop/basic_agentic_loop.py

You’ll see:

Chat with Claude. Type 'exit' to end the conversation.

You:

Type a message and press Enter to get a response. Keep chatting, or type exit to end the conversation.

Configuration

Edit the constants at the top of basic_agentic_loop.py:

See also