What an AI agent really is
An agent is a loop. It thinks, acts, observes, and goes round again until it can answer. Watch one full turn of a real ADK agent.
A chatbot sends your message to a model and shows the reply. An agent can also do things: call an API, query a database, run code. The trick is that the model never does them itself. It asks, your program does the work, and the result goes back to the model.
That cycle is the agent loop:
- Think: the model reads the conversation and decides what to do next.
- Act: if it needs information or an action, it asks for a tool call, and your code runs the tool.
- Observe: the tool’s result is added to the conversation.
The loop repeats until the model can answer in plain text. Press Play below, then switch the Try it selector to see a question that needs no tool at all.
- Think
- Act
- Observe
- Answer
Press Play to watch it run, or step through with ← →.
00/12
import asyncio
from google.adk.agents.llm_agent import Agent
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
from google.genai import types
def get_weather(city: str) -> dict:
"""Returns the current weather for a city."""
return {"status": "success", "city": city, "temp_c": 31, "condition": "humid"}
root_agent = Agent(
name="weather_agent",
model="gemini-flash-latest",
description="Answers questions about the weather.",
instruction="Answer weather questions. Use get_weather for live data.",
tools=[get_weather],
)
async def main(question: str):
sessions = InMemorySessionService()
await sessions.create_session(app_name="demo", user_id="u1", session_id="s1")
runner = Runner(agent=root_agent, app_name="demo", session_service=sessions)
message = types.Content(role="user", parts=[types.Part(text=question)])
async for event in runner.run_async(
user_id="u1", session_id="s1", new_message=message
):
if event.is_final_response():
print(event.content.parts[0].text)
asyncio.run(main("Weather in Chennai?"))Session events
Empty. Events appear here as the Session records them.
What to notice
- The model never runs your code. It returns a
function_call, which is a structured request. ADK runsget_weatherfor you. - Tools are plain Python functions. ADK reads the function name, parameters and docstring, and turns them into a description the model can understand. A clear docstring helps the model pick the right tool.
- Everything becomes an Event. The user’s message, the tool call, the tool’s result and the final answer are all saved to the session. That history is what the model sees on its next round.
- The number of loops isn’t fixed. “Capital of France?” takes one round. “Weather in Chennai?” takes two. A harder task might call several tools in a row.