Course contentsShow
← AI Engineering
Lesson 630 of 1,88616. AI Agents - ImplementationFree lesson

Implementing the Observation Step

Capture and format environment information for the agent to process.

Implementing the Observation Step

What you'll learn: How to capture and format environment information so your AI agent can understand what's happening and decide what to do next.

What Is the Observation Step?

The observation step is where your agent "looks around" and gathers information about its current situation. Just like you glance at your phone screen before deciding whether to answer a call, an agent needs to collect relevant data from its environment before reasoning about what action to take.

This step transforms raw environment data into a structured format the agent can process during its reasoning phase.

Core Components

Environment State Capture

Your agent needs to know:

  • What just happened? (results from the last action, if any)
  • What's the current context? (user input, system state, available tools)
  • What's the goal? (task description, success criteria)

Formatting for the Agent

Raw data isn't enough—you must structure it clearly:

observation = {
    "last_action_result": "User profile retrieved successfully",
    "current_goal": "Send welcome email to new user",
    "available_tools": ["send_email", "log_event"],
    "user_data": {"name": "Alice", "email": "alice@example.com"}
}

This dictionary becomes part of the prompt sent to your LLM for reasoning.

Observation as Prompt Context

Typically, you'll convert the observation into natural language or structured text that gets prepended to your agent's prompt, giving it the context needed to decide the next action.

Key Takeaway: The observation step is your agent's eyes and ears—capture everything it needs to make an informed decision, format it clearly, and feed it into the reasoning phase as structured context.