Defining the Agent's Environment › A Simple Environment Model
Michael BrenndoerferJuly 13, 20252 min read
AI Agent HandbookAll chapters Part 8 of 15Environment and Interaction - The Agent's World
Defining the Agent's Environment › A Simple Environment ModelOne section · Sections in this chapter5 / 11 ↓
Sections in this chapter11
Let's build a basic model of our assistant's environment. This model will help us think systematically about how agents interact with their world. We'll keep it simple but extensible:
In[4]:
Code## Using Claude Sonnet 4.5 for agent-based applications
class AgentEnvironment:
"""Represents the world our assistant operates in"""
def __init__(self):
self.available_tools = {
"calendar": self.get_calendar,
"email": self.get_emails,
"weather": self.get_weather
}
self.conversation_history = []
def get_calendar(self, date=None):
"""Retrieve calendar events"""
# Simplified for illustration
return [{"time": "9:00 AM", "title": "Team meeting"}]
def get_emails(self, count=5):
"""Retrieve recent emails"""
return [{"from": "boss@company.com", "subject": "Q4 Planning"}]
def get_weather(self, location):
"""Get weather information"""
return {"temp": "72°F", "condition": "Sunny"}
def perceive(self, user_input):
"""Agent perceives new input from the environment"""
self.conversation_history.append({
"role": "user",
"content": user_input
})
return user_input
def act(self, action_type, **params):
"""Agent takes an action in the environment"""
if action_type in self.available_tools:
result = self.available_tools[action_type](**params)
return result
else:
return {"error": "Tool not available"}
## Create the environment
env = AgentEnvironment()
## Agent perceives user input
user_query = env.perceive("What's the weather like?")
## Agent decides to use the weather tool
weather_data = env.act("weather", location="San Francisco")
print(f"Weather: {weather_data}")Out[4]:
ConsoleWeather: {'temp': '72°F', 'condition': 'Sunny'}This simple model captures the key idea: the environment is where perception happens (through perceive()) and where actions take effect (through act()). Everything the agent knows about the world comes through perception, and everything it does to change the world happens through actions.