windlass.providers.llm.fake¶
fake
¶
A deterministic, dependency-free LLM for tests, demos and CI.
FakeLLM is not a toy. It is the reason the entire Windlass test suite runs
offline in a few seconds with no API keys, and the reason pip install
windlass alone gives you a working end-to-end pipeline to learn from.
It can:
- replay a scripted list of responses;
- answer via a callable, so a test can assert on the prompt it received;
- emit tool calls on cue, exercising the whole agent loop;
- record every call it received for assertions.
Example
llm = FakeLLM(responses=["first", "second"]) llm.complete("a").content, llm.complete("b").content ('first', 'second') llm.calls[0][-1].content 'a'
FakeLLM
¶
FakeLLM(
responses: Sequence[str] | str | None = None,
*,
handler: Callable[[list[Message], list[dict[str, Any]] | None], Any] | None = None,
tool_calls: Sequence[Sequence[ToolCall]] | None = None,
cycle: bool = False,
latency: float = 0.0,
model: str = "fake-1",
**config: Any
)
Bases: LLM
A scripted language model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
responses
|
Sequence[str] | str | None
|
Texts to return, one per call. Exhausting the list cycles
back to the start when |
None
|
handler
|
Callable[[list[Message], list[dict[str, Any]] | None], Any] | None
|
Callable receiving |
None
|
tool_calls
|
Sequence[Sequence[ToolCall]] | None
|
Tool calls to emit, one list per call. Use this to drive an agent through a specific tool-use path in a test. |
None
|
cycle
|
bool
|
Whether |
False
|
latency
|
float
|
Artificial delay per call in seconds, for testing timeouts and progress indicators. |
0.0
|
model
|
str
|
Reported model name. |
'fake-1'
|
**config
|
Any
|
Forwarded to :class: |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
calls |
list[list[Message]]
|
Every message list this model was asked to complete. |
tool_schemas |
list[list[dict[str, Any]] | None]
|
The tool definitions passed on each call. |
Example
Driving an agent through one tool call, then a final answer::
llm = FakeLLM(
responses=["", "The weather is sunny."],
tool_calls=[[ToolCall(name="weather", arguments={"city": "Paris"})], []],
)
Source code in src\windlass\providers\llm\fake.py
default_model
classmethod
¶
agenerate
async
¶
agenerate(
messages: list[Message], *, tools: list[dict[str, Any]] | None = None, **kwargs: Any
) -> Completion
Return the next scripted response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[Message]
|
The conversation, recorded on :attr: |
required |
tools
|
list[dict[str, Any]] | None
|
Tool definitions, recorded on :attr: |
None
|
**kwargs
|
Any
|
Ignored. |
{}
|
Returns:
| Type | Description |
|---|---|
Completion
|
The scripted completion. |
Source code in src\windlass\providers\llm\fake.py
astream_generate
async
¶
astream_generate(
messages: list[Message], *, tools: list[dict[str, Any]] | None = None, **kwargs: Any
) -> AsyncIterator[StreamEvent]
Stream the scripted response one word at a time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[Message]
|
The conversation. |
required |
tools
|
list[dict[str, Any]] | None
|
Tool definitions. |
None
|
**kwargs
|
Any
|
Ignored. |
{}
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[StreamEvent]
|
Word-level text events, then any tool calls, then |
Source code in src\windlass\providers\llm\fake.py
last_prompt
¶
Return the text of the most recent user message.
Returns:
| Type | Description |
|---|---|
str
|
The last user message's content, or |
Raises:
| Type | Description |
|---|---|
IndexError
|
If the model has not been called yet. |
Source code in src\windlass\providers\llm\fake.py
reset
¶
EchoLLM
¶
Bases: LLM
A model that echoes its input.
Useful for wiring tests where you need to prove that a prompt reached the model intact — the answer is the prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
Prepended to the echoed text. |
''
|
**config
|
Any
|
Forwarded to :class: |
{}
|
Example
EchoLLM().complete("hello there").content 'hello there' EchoLLM(prefix="You said: ").complete("hi").content 'You said: hi'
Source code in src\windlass\providers\llm\fake.py
default_model
classmethod
¶
agenerate
async
¶
agenerate(
messages: list[Message], *, tools: list[dict[str, Any]] | None = None, **kwargs: Any
) -> Completion
Echo the last user message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[Message]
|
The conversation. |
required |
tools
|
list[dict[str, Any]] | None
|
Ignored — this model does not call tools. |
None
|
**kwargs
|
Any
|
Ignored. |
{}
|
Returns:
| Type | Description |
|---|---|
Completion
|
A completion containing the echoed text. |