Stage 07 — Agentic AI Fundamentals

Agentic AI Fundamentals  ·  Comprehensive Technical Training  ·  ⏱ 6–8 hours

Learning Objectives

By the end of this stage you will be able to:

  • Understand the fundamental agent loop and ReAct pattern
  • Design multi-step workflows vs. autonomous agents
  • Integrate tools and external APIs into agent reasoning
  • Handle agent failures, loops, and safety constraints
  • Evaluate agent performance and debug common issues
  • Design agentic AI systems that can act autonomously on complex tasks

Section 1: The Agent Loop

An agent is an LLM that operates in a loop: Observe → Think → Act → Observe → Think → Act → ... until the task is complete or a stop condition is reached.

Basic Agent Loop

def agent_loop(task, max_steps=10):
    history = []
    state = {"task": task, "status": "started"}

    for step in range(max_steps):
        # 1. Observe: gather current information
        observation = f"Current state: {state}"
        history.append({"role": "observation", "content": observation})

        # 2. Think: LLM decides what to do
        prompt = f"Task: {task}\nHistory: {history}\nWhat should we do next?"
        thought = llm(prompt)
        history.append({"role": "thought", "content": thought})

        # 3. Act: execute an action
        action = extract_action_from_thought(thought)
        result = execute_action(action)
        history.append({"role": "action", "content": f"{action} → {result}"})

        # 4. Check if done
        if is_task_complete(state, result):
            return result

        state.update(result)

    return {"status": "max_steps_reached", "history": history}

# Example
result = agent_loop("Book a flight from NYC to SF on Friday")

Section 2: The ReAct Pattern

ReAct (Reasoning + Acting) structures agent prompts to encourage explicit reasoning before taking actions:

REACT_PROMPT = """
You are a helpful assistant. Follow this format:

Thought: Consider what you need to do
Action: Take an action from the available tools
Observation: See what happened
... (repeat Thought/Action/Observation until done)
Final Answer: Your conclusion

Available tools:
- search(query): Search the web
- calculate(expression): Evaluate math
- fetch_api(url): Call an API

Task: {task}

Thought: """

def react_agent(task, max_steps=5):
    messages = [{"role": "user", "content": REACT_PROMPT.format(task=task)}]

    for step in range(max_steps):
        response = llm(messages)
        messages.append({"role": "assistant", "content": response})

        # Parse action from response
        action = parse_action(response)
        if action.type == "final_answer":
            return action.content

        # Execute action
        observation = execute_tool(action)

        # Add observation back to messages
        messages.append({"role": "user", "content": f"Observation: {observation}"})

    return "Max steps reached"

Key insight: Explicit reasoning reduces errors and makes agent behavior interpretable.


Section 3: Tool Integration

Defining Available Tools

TOOLS = {
    "search": {
        "description": "Search the web for information",
        "params": {"query": "What to search for"},
    },
    "calculate": {
        "description": "Perform mathematical calculations",
        "params": {"expression": "Math expression in Python"},
    },
    "send_email": {
        "description": "Send an email",
        "params": {
            "to": "Recipient email",
            "subject": "Email subject",
            "body": "Email body",
        },
    },
}

def execute_tool(tool_name, **params):
    if tool_name == "search":
        return search_web(params["query"])
    elif tool_name == "calculate":
        return eval(params["expression"])
    elif tool_name == "send_email":
        return send_email(**params)
    else:
        raise ValueError(f"Unknown tool: {tool_name}")

Section 4: Multi-Agent Systems

Instead of one agent doing everything, delegate to specialized agents:

class ResearchAgent:
    """Searches for and summarizes information"""
    def __init__(self):
        self.tools = ["search", "summarize"]

class WriterAgent:
    """Writes content based on research"""
    def __init__(self):
        self.tools = ["format", "revise"]

class ReviewAgent:
    """Reviews work for quality"""
    def __init__(self):
        self.tools = ["check_quality", "provide_feedback"]

# Workflow: Research → Write → Review
task = "Write a summary of recent AI breakthroughs"
research_result = ResearchAgent().run(task)
written_result = WriterAgent().run(research_result)
final_result = ReviewAgent().run(written_result)
print(final_result)

Section 5: Agent Failure Modes

Infinite Loops

Agent repeats same action without progress. Fix: track state history, penalize repeated actions.

Hallucinated Tools

Agent invents tool calls that don't exist. Fix: provide schema strictly, constrain output format.

Context Window Exhaustion

History grows too large. Fix: summarize old steps, keep only relevant context.


What's Next

Stage 8 introduces OpenAI Agents SDK—a production-ready framework for building reliable, traceable agents with structured logging and error handling.

Lock In Founding Member Access

Get full access to every course on TechNodeX — AI, cybersecurity, Python, and everything we build next. $9/month, price locked forever.

Become a Founding Member →