Builder¶
LLM Agent Builder.
LLMAgentBuilder
¶
A builder for LLM Agents.
Attributes:
| Name | Type | Description |
|---|---|---|
llm |
LLM | None
|
The backbone LLM for the agent. |
tools |
list[Tool]
|
Tools to equip the agent with. |
templates |
LLMAgentTemplates
|
Prompt templates for the agent. |
mcp_providers |
list[MCPToolProvider]
|
MCP providers for tool discovery. |
Source code in src/llm_agents_from_scratch/agent/builder.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
__init__
¶
Initialize an LLMAgentBuilder.
All parameters can also be set via fluent with_* builder methods for
chained configuration.
Examples:
Fluent style::
agent = await (
LLMAgentBuilder()
.with_llm(llm)
.with_tool(my_tool)
.with_mcp_provider(provider)
.build()
)
Direct params::
agent = await LLMAgentBuilder(
llm=llm,
tools=[my_tool],
mcp_providers=[provider],
).build()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
llm
|
LLM | None
|
The backbone LLM for the agent.
Required before calling |
None
|
tools
|
list[Tool] | None
|
Initial list of tools to equip the agent with. Defaults to None. |
None
|
templates
|
LLMAgentTemplates
|
Prompt templates for
the agent. Defaults to |
default_templates
|
mcp_providers
|
list[MCPToolProvider] | None
|
MCP
providers for tool discovery. Tools are fetched during
|
None
|
Source code in src/llm_agents_from_scratch/agent/builder.py
with_llm
¶
with_tool
¶
with_tools
¶
with_templates
¶
with_mcp_provider
¶
with_mcp_providers
¶
build
async
¶
Build an LLMAgent with configured tools and MCP providers.
Discovers tools from all registered MCP providers concurrently, combines them with manually added tools, and returns a configured LLMAgent.
This is the recommended pattern for building agents with MCP tools. Alternatively, you can manually discover tools and pass them directly:
provider = MCPToolProvider(name="github", url="...")
tools = await provider.get_tools()
agent = LLMAgent(llm=llm, tools=tools)
Returns:
| Name | Type | Description |
|---|---|---|
LLMAgent |
LLMAgent
|
The configured agent with all tools. |
Raises:
| Type | Description |
|---|---|
LLMAgentBuilderError
|
If |