windlass.agent.builder¶
builder
¶
The fluent agent builder.
::
agent = (
Windlass.agent()
.llm("gpt-4o")
.tool(weather_tool)
.tool(search_tool)
.mcp(command="npx",
args=["-y", "@modelcontextprotocol/server-filesystem", "."])
.memory()
.guardrails()
)
response = agent.run("Summarise my PDF documents")
Like the RAG builder, nothing is constructed until first use, every argument
accepts a name, an instance or a factory, and the builder forwards the runtime's
methods so there is no mandatory .build() step.
AgentBuilder
¶
Fluent builder for an agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container
|
Container | None
|
Dependency container. Defaults to a child of the process root. |
None
|
Example
Level 1 — a working agent in two lines, no dependencies::
agent = Windlass.agent().llm("fake", responses=["Hello!"])
print(agent.run("Say hello"))
Level 2 — a real agent::
agent = (Windlass.agent()
.llm("anthropic", model="claude-sonnet-4-5")
.tool(search).tool(calculator)
.system("You are a research assistant. Cite your sources.")
.memory("summary")
.guardrails(pii=True, on_violation="redact")
.checkpoint("sqlite", path="./state.db")
.max_iterations(15)
.observe("langfuse"))
Level 3 — a graph you control::
agent = Windlass.agent().llm("openai").tool(search).graph()
graph = agent.native_graph()
graph.add_node("critic", critic_fn)
graph.add_edge("tools", "critic")
agent.recompile()
Source code in src\windlass\agent\builder.py
llm
¶
Choose the reasoning model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
Any
|
Registry name ( |
None
|
**config
|
Any
|
Provider options — |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
|
Example
from windlass import Windlass _ = Windlass.agent().llm("gpt-4o-mini", temperature=0)
Source code in src\windlass\agent\builder.py
tool
¶
Bind one or more tools.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*tools
|
Any
|
:class: |
()
|
Returns:
| Type | Description |
|---|---|
Self
|
|
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
When an argument cannot be interpreted as a tool. |
Example
from windlass import Windlass, tool @tool ... def now() -> str: ... '''Return the current time.''' ... return "12:00" _ = Windlass.agent().tool(now)
Source code in src\windlass\agent\builder.py
tools
¶
mcp
¶
Connect an MCP server and bind its tools.
Call it repeatedly to connect several servers; their tools are namespaced by server name so identically-named tools do not collide.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
Any
|
Registry name ( |
None
|
**config
|
Any
|
Transport options — |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
|
Example
from windlass import Windlass _ = Windlass.agent().mcp(server="fs", command="npx", ... args=["-y", "@modelcontextprotocol/server-filesystem", "."])
Source code in src\windlass\agent\builder.py
memory
¶
Attach conversation memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
Any
|
Registry name ( |
None
|
**config
|
Any
|
Memory options. |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
|
Source code in src\windlass\agent\builder.py
guardrails
¶
Enable input and output guardrails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
Any
|
Registry name ( |
None
|
**config
|
Any
|
Policy options. |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
|
Source code in src\windlass\agent\builder.py
observe
¶
Enable tracing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
Any
|
Registry name ( |
None
|
**config
|
Any
|
Tracer options. |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
|
Source code in src\windlass\agent\builder.py
checkpoint
¶
Enable durable state, resume and human-in-the-loop approval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
Any
|
Registry name ( |
None
|
**config
|
Any
|
Checkpointer options — |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
|
Note
Approval interrupts require a checkpointer, since a paused run has to be stored somewhere before it can be resumed.
Source code in src\windlass\agent\builder.py
agent
¶
Add a specialist, turning this into a supervisor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name the supervisor uses to delegate. |
required |
worker
|
Any
|
An agent, builder, or anything with |
required |
description
|
str
|
What the specialist is good at. The supervisor routes on this text. |
''
|
Returns:
| Type | Description |
|---|---|
Self
|
|
Example
from windlass import Windlass _ = (Windlass.agent().llm("fake") ... .agent("researcher", Windlass.agent().llm("fake"), ... "Finds and summarises source material."))
Source code in src\windlass\agent\builder.py
system
¶
Set the system prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
Instructions prepended to every run. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
|
name
¶
max_iterations
¶
Set the reason/act step budget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
Maximum cycles before
:class: |
required |
Returns:
| Type | Description |
|---|---|
Self
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src\windlass\agent\builder.py
tool_call_retries
¶
Set how often a run may recover from an unparseable tool call.
Models occasionally emit a tool call the provider cannot parse — most often by nesting one call inside another's arguments, which the tool-calling protocol has no way to express. Windlass shows the model the problem and lets it retry, the same way it handles an invented tool name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
Maximum corrections per run. Each one costs an iteration from
:meth: |
required |
Returns:
| Type | Description |
|---|---|
Self
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Example
from windlass import Windlass _ = Windlass.agent().llm("fake").tool_call_retries(3)
Source code in src\windlass\agent\builder.py
parallel_tools
¶
Control whether simultaneous tool calls run concurrently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enabled
|
bool
|
False forces serial execution — occasionally necessary when tools share mutable state. |
True
|
Returns:
| Type | Description |
|---|---|
Self
|
|
Source code in src\windlass\agent\builder.py
human_in_the_loop
¶
Require human approval before every tool call.
Individual tools can require approval on their own with
@tool(requires_approval=True); this turns it on globally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enabled
|
bool
|
True to pause before every tool call. |
True
|
Returns:
| Type | Description |
|---|---|
Self
|
|
Note
Implies a checkpointer, since a paused run has to be stored. One is enabled automatically if you have not chosen one.
Source code in src\windlass\agent\builder.py
graph
¶
Use the LangGraph runtime instead of the built-in loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enabled
|
bool
|
True to compile the agent into a LangGraph state machine. |
True
|
Returns:
| Type | Description |
|---|---|
Self
|
|
Raises:
| Type | Description |
|---|---|
MissingDependencyError
|
At build time, when |
Source code in src\windlass\agent\builder.py
bind
¶
Bind an arbitrary dependency into this builder's container.
Source code in src\windlass\agent\builder.py
build
¶
Resolve every component and construct the runtime.
Called automatically on first use.
Returns:
| Name | Type | Description |
|---|---|---|
An |
AgentRuntime
|
class: |
AgentRuntime
|
class: |
|
AgentRuntime
|
class: |
|
AgentRuntime
|
configuration describes. |
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
When a component cannot be constructed. |
MissingDependencyError
|
When a chosen provider's extra is missing. |
Source code in src\windlass\agent\builder.py
run
¶
arun
async
¶
stream
¶
Stream the run. See :meth:~windlass.agent.runtime.AgentRuntime.stream.
astream
¶
astream_text
¶
resume
¶
aresume
async
¶
pending_approvals
¶
state
¶
history
¶
broadcast
¶
Run every specialist on the same task (supervisor only).
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
When no specialists are configured. |
Source code in src\windlass\agent\builder.py
pipeline
¶
Chain specialists in sequence (supervisor only).
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
When no specialists are configured. |
Source code in src\windlass\agent\builder.py
native_llm
¶
native_graph
¶
Return the LangGraph StateGraph.
Raises:
| Type | Description |
|---|---|
AgentError
|
When the agent was not built with :meth: |
recompile
¶
Recompile the graph after editing it.
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
When the agent is not graph-backed. |