liveBook · Manning

AI agent

As explained in Domain-Specific Small Language Models

An autonomous software entity that can invoke models or tools as part of a larger system.

An AI agent is a software system that autonomously performs tasks and makes decisions on a user’s behalf. A language model can help it interpret a request and choose what to do next, while tools let it act outside the model. A prompt sent to a model followed by a fixed automation sequence is not, by itself, the same thing as an agent. section 13.4

The reason to use an agent is operational: a single model response may not be enough. Context windows can lose earlier conversation, models can struggle with calculation or logic, and supplied context can be outdated or wrong. An agent can break a task into steps, call tools for information or action, and use the results to decide what to do next. Memory management and access to current information are related needs, not automatic properties of every agent. section 13.4 section 13.5

The core capabilities are:

  • Reason: analyze the request and available context, then determine the next step. section 13.4
  • Act: execute a step through an external tool or API, rather than only describing an action. section 13.4
  • Interact: communicate with users or other agents when collaboration is needed. section 13.4

A local implementation can pair a small language model with smolagents’ CodeAgent and Python tools. CodeAgent writes and runs Python snippets for its steps instead of producing JSON action instructions. Custom tool functions need type hints and docstrings so their capabilities are available to the agent. The configured tool set and step limit define what a particular run can attempt; adding a domain-specific tool expands the actions available. section 13.4 section 13.5

from smolagents import CodeAgent

custom_tools = [search_for_flights, find_seat]
agent = CodeAgent(tools=custom_tools, model=model,
                  verbosity_level=2, max_steps=2)

This configuration gives CodeAgent flight-search and seat-selection tools and limits the run to two steps. section 13.4

Chaining actions

For a flight request, an agent can search for flights, pass a returned flight code to a seat-selection tool, and, when a booking tool is added, pass the flight and seat to that tool. The example booking function is a mock; its ticket number demonstrates the workflow rather than a real purchase. section 13.4

In agentic retrieval-augmented generation, the agent chooses how to gather context before answering. It might search local documents, revise a query when results are unhelpful, or use web search. One implementation equips CodeAgent with BM25, semantic, hybrid, and web-search options. Tool choice becomes part of the workflow rather than a fixed retrieval step. section 14.2

How Domain-Specific Small Language Models covers it

How deep it goes
Defines agent capabilities and works through local tool-chaining examples, while deferring advanced agent concepts.
Examples
Uses a flight-search and seat-selection workflow, a mock booking tool, and local-document versus web-search choices.
What it assumes
Assumes familiarity with model prompt-and-response behavior and Python, while defining the agent and introducing its local setup.
What you can do after
Apply it via smolagents CodeAgent to chain Python tools and configure an agent with local-document and web-search options.
How it connects
Connects agents to tool calling, planning, small language models, retrieval-augmented generation, and memory management.

Also explained in

Compare how 33 books explain AI agent →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Domain-Specific Small Language Models. The section links point to the parts of the book it draws on.