Jido.AI.Test (Jido AI v2.3.0)

Copy Markdown View Source

Public test helpers for deterministic Jido.AI ReAct tests.

expect_react/1 scripts the model boundary while the application still runs its real ReAct runtime, tools, event projection, and assertions.

expect_react do
  user "summarize README"
  call "read", %{path: "README.md"}
  answer "README says Hello."
end

The script is registered for the current test process tree and matched by the latest user prompt. For code that starts agents outside that tree, pass the returned script explicitly:

script =
  expect_react do
    user "summarize README"
    answer "README says Hello."
  end

MyAgent.ask_sync(pid, "summarize README", react_opts(script))

Summary

Functions

Adds the final scripted model answer.

Asserts that a collected ReAct result or event list ended with expected.

Asserts that a ReAct trace has no terminal runtime failure or cancellation.

Asserts that the ReAct trace includes a model-requested tool call.

Adds a scripted model tool call.

Starts a deterministic ReAct script and registers it for the current test.

Adds a terminal scripted model failure.

Returns ReqLLM generation opts for an explicit script.

Returns ReAct runtime opts for an explicit script.

Clears scripts registered by the current test process tree.

Adds the expected initial user prompt for a ReAct test script.

Functions

answer(text, opts \\ [])

@spec answer(
  term(),
  keyword()
) :: :ok

Adds the final scripted model answer.

assert_final_answer(source, expected)

@spec assert_final_answer(map() | [map()], String.t() | Regex.t()) :: map() | [map()]

Asserts that a collected ReAct result or event list ended with expected.

assert_no_runtime_failure(source)

@spec assert_no_runtime_failure(map() | [map()]) :: map() | [map()]

Asserts that a ReAct trace has no terminal runtime failure or cancellation.

assert_tool_called(source, name, expected_args \\ :any)

@spec assert_tool_called(map() | [map()], String.t() | atom(), map() | :any) ::
  map() | [map()]

Asserts that the ReAct trace includes a model-requested tool call.

call(name, arguments, opts \\ [])

@spec call(String.t() | atom(), map(), keyword()) :: :ok

Adds a scripted model tool call.

expect_react(list)

(macro)

Starts a deterministic ReAct script and registers it for the current test.

fail(reason, opts \\ [])

@spec fail(
  term(),
  keyword()
) :: :ok

Adds a terminal scripted model failure.

react_llm_opts(script)

@spec react_llm_opts(Jido.AI.Test.ReActScript.t()) :: keyword()

Returns ReqLLM generation opts for an explicit script.

react_opts(script)

@spec react_opts(Jido.AI.Test.ReActScript.t()) :: keyword()

Returns ReAct runtime opts for an explicit script.

reset_react_scripts()

@spec reset_react_scripts() :: :ok

Clears scripts registered by the current test process tree.

user(content)

@spec user(term()) :: :ok

Adds the expected initial user prompt for a ReAct test script.