LLMAgentBuilder constructs an LLMAgent from configured model, tools, templates, and MCP providers. Its main convenience is discovering MCP tools during construction, avoiding manual discovery for each server. section 5.3
Configure and build an agent in three stages:
- Set or add inputs with the constructor or chainable with_* methods; with_tools() and with_mcp_providers() extend their lists. section 5.3.1
- Call the asynchronous build() method. It validates that an LLM is set, discovers tools from each MCPToolProvider, and constructs the LLMAgent. section 5.3.1
Build an agent with a Hailstone tool
Configure an MCPToolProvider for the Hailstone server, add it and an LLM to the builder, then await build(). The resulting agent can call the discovered hailstone_step_fn tool to evaluate hailstone_step_fn(5), which returns 16. section 5.3.1 section 5.3
# Included in examples/ch05.ipynb #A
from llm_agents_from_scratch.notebook_utils import make_llm
from llm_agents_from_scratch.agent.builder import LLMAgentBuilder
provider = MCPToolProvider(
name="hailstone",
stdio_params=server_params,
)
llm = make_llm()
llm_agent = await LLMAgentBuilder()\
.with_llm(llm)\
.with_mcp_provider(provider)\
.build() #BShows fluent configuration of an MCP provider and LLM followed by asynchronous construction. section 5.3.1
