LESSON · 1 OF 4

What is an agent

What is an agent

An agent is an LLM running in a loop, given the freedom to use tools to reach a goal. A plain prompt goes one way: you ask, the model answers, done. An agent adds a cycle. The model looks at the goal, decides whether it needs a tool, calls one, reads the result, and decides again - keep going or stop and answer.

You already met the piece that makes this possible. In tool calling the model didn't run your function - it told you which function to call and with what arguments, and you ran it. An agent is just that idea wrapped in a loop that runs the function automatically and feeds the result straight back to the model.

The loop

Every agent runs the same four steps until the goal is met:

  • Decide. The model reads the goal and the results so far, then picks the next move: call a tool, or give the final answer.
  • Act. If it picked a tool, the agent runs that tool with the arguments the model chose.
  • Observe. The tool's result is added back into the conversation so the model can see what happened.
  • Repeat. Back to decide, now with one more fact in hand. When the model decides it has enough, it stops and answers.

Prompt versus agent

Ask a plain model "what is 4817 times 39?" and it predicts text, which is why it's shaky at exact math. Give an agent the same question plus a calculator tool, and a different thing happens: the model decides it needs to calculate, calls the calculator with 4817 and 39, reads the exact result, and answers from that. The model didn't get better at arithmetic. It got the ability to reach for a tool that is.

That's the whole point of an agent. The model supplies the judgment about what to do next, and the tools supply the abilities the model doesn't have on its own: doing math, reading a file, searching, calling an API. Next you'll see the small set of pieces that make one in LangChain.


Your lab setup

This VM comes preconfigured with your AI keys - just type claude to get started. Your key and URL are already set as $OPENAI_BASE_URL and $OPENAI_API_KEY.

Spin up a fresh environment and practice live.
linux-basic-ai · fresh machine · ready in under a minute