Perception and Action › What Is Perception?
AI Agent HandbookAll chapters Perception and Action › What Is Perception?One section · Sections in this chapter2 / 10 ↓
For our personal assistant, perception is simpler than you might think. The agent perceives its environment by reading inputs. When you type a message, the agent "hears" it. When a tool returns data, the agent "sees" it. When it checks its memory, it "remembers" previous context.
Here's a concrete example. When you ask your assistant, "What's the weather like today?", several perceptions happen:
- User input perception: The agent receives your text query
- Context perception: It accesses its memory to understand you're asking about weather
- Tool output perception: After calling a weather API, it receives structured data about temperature, conditions, etc.
Each of these is a form of perception. The agent takes information from its environment and incorporates it into its understanding of the current situation.
Perception in Code (Claude Sonnet 4.5)
Let's see how perception works in a simple agent loop:
import os
from anthropic import Anthropic
## Using Claude Sonnet 4.5 for its superior agent reasoning capabilities
client = Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
def perceive_user_input(user_message):
"""
Perception: Agent reads and processes user input
Returns the perceived information in a structured format
"""
return {
"type": "user_message",
"content": user_message,
"timestamp": "2025-11-09T10:30:00Z"
}
def perceive_tool_output(tool_name, tool_result):
"""
Perception: Agent reads and processes tool output
"""
return {
"type": "tool_output",
"tool": tool_name,
"content": tool_result
}
## Example: Agent perceives a user query
perception_1 = perceive_user_input("What's the weather in San Francisco?")
print(f"Perceived: {perception_1}")
## Later, agent perceives tool output
weather_data = {"temperature": 65, "condition": "sunny"}
perception_2 = perceive_tool_output("weather_api", weather_data)
print(f"Perceived: {perception_2}")Perceived: {'type': 'user_message', 'content': "What's the weather in San Francisco?", 'timestamp': '2025-11-09T10:30:00Z'}
Perceived: {'type': 'tool_output', 'tool': 'weather_api', 'content': {'temperature': 65, 'condition': 'sunny'}}This example shows perception as a deliberate process. The agent doesn't just receive data; it structures and interprets what it perceives. This structured perception becomes part of the agent's state, which we covered in Chapter 7.
Types of Perception
Our assistant can perceive different kinds of information:
Direct user input: The most obvious form. When you type a message, the agent perceives your intent, the specific words you used, and any context clues in your phrasing.
Tool responses: When the agent calls a calculator, searches the web, or queries a database, the returned data is a perception. The agent must interpret this data and integrate it into its understanding.
Memory retrieval: When the agent looks up previous conversations or stored facts, it's perceiving information from its own long-term memory. This is like you remembering something from yesterday.
System signals: The agent might perceive metadata like timestamps, user IDs, or error messages. These help it understand the broader context of its environment.