Perception and Action › What Is Action?
AI Agent HandbookAll chapters Perception and Action › What Is Action?One section · Sections in this chapter3 / 10 ↓
If perception is input, action is output. But action goes beyond just generating text. When our assistant takes an action, it changes something in its environment.
Here are the main types of actions our assistant can take:
Generating responses: The most common action. The agent produces text that answers your question or continues the conversation.
Calling tools: When the agent invokes a calculator, sends an email, or searches the web, it's taking action that affects the external world.
Updating memory: Saving information for later is an action. When the agent stores "User's birthday is July 20," it's changing its internal environment.
Requesting clarification: Sometimes the best action is to ask for more information. "Did you mean San Francisco, California or San Francisco, Philippines?" is an action that seeks better perception.
Action in Code (Claude Sonnet 4.5)
Let's extend our example to show how the agent takes actions:
def action_generate_response(agent_message):
"""
Action: Agent generates a text response
This changes the environment by adding to the conversation
"""
return {
"type": "response",
"content": agent_message,
"timestamp": "2025-11-09T10:30:05Z"
}
def action_call_tool(tool_name, tool_params):
"""
Action: Agent calls an external tool
This changes the environment by triggering external systems
"""
print(f"Calling {tool_name} with params: {tool_params}")
# Simulate tool call
if tool_name == "weather_api":
return {"temperature": 65, "condition": "sunny"}
return None
## Agent decides to take action based on perception
user_query = perceive_user_input("What's the weather in San Francisco?")
## Action 1: Call weather tool
weather_result = action_call_tool("weather_api", {"city": "San Francisco"})
## Perception: Agent perceives the tool output
tool_perception = perceive_tool_output("weather_api", weather_result)
## Action 2: Generate response based on perceptions
response = action_generate_response(
f"The weather in San Francisco is {weather_result['condition']} "
f"with a temperature of {weather_result['temperature']}°F."
)
print(f"Agent response: {response['content']}")Calling weather_api with params: {'city': 'San Francisco'}
Agent response: The weather in San Francisco is sunny with a temperature of 65°F.Notice how actions and perceptions alternate. The agent perceives the user query, takes an action (calling a tool), perceives the result, and takes another action (generating a response). This is the perception-action cycle in practice.