An AI agent is a specialized system that autonomously performs tasks by understanding natural language, reasoning and planning, selecting tools, and delivering results. It can break an ambiguous or multistep request into subtasks, call APIs or scripts, process their outputs, and return a coherent response. section 9.1
An agent typically performs four connected actions:
- Interpret a user query with a large language model. section 9.1
- Analyze the task, plan steps, and decide how to proceed. section 9.1
- Select and execute known tools such as search engines, APIs, or custom scripts. section 9.1
- Process tool outputs and deliver a clear answer. section 9.1
Search agent with smolagents
A minimal search agent combines a hosted model with DuckDuckGoSearchTool and runs a natural-language query: `model = HfApiModel(); agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model); response = agent.run("How long does it take to travel from New York to Los Angeles by train?")`. CodeAgent reasons by generating and executing Python code, while run() returns the final answer. The model can instead connect to a local Ollama server through LiteLLMModel. section 9.2.1
Figure 9.1 Roles of an agent
Use the role diagram to navigate the agent’s cycle of understanding language, planning, acting with tools, and delivering results. section 9.1
Frameworks shape the implementation. smolagents emphasizes lightweight experimentation and Python-code execution; LangChain composes prompts, memory, tools, and chains; LangGraph supports complex, stateful, multistep workflows and agent memory. section 9.0 section 9.3
































