diff --git a/lib/gpt_agent.ex b/lib/gpt_agent.ex index 09b31a2..9c67d3f 100644 --- a/lib/gpt_agent.ex +++ b/lib/gpt_agent.ex @@ -50,6 +50,7 @@ defmodule GptAgent do @callback submit_tool_output(pid(), Types.tool_name(), Types.tool_output()) :: Types.result(:invalid_tool_call_id) @callback run_in_progress?(pid()) :: boolean() + @callback set_assistant_id(pid(), Types.assistant_id()) :: Types.success() defp noreply(%__MODULE__{} = state), do: {:noreply, state, state.timeout_ms} defp noreply(%__MODULE__{} = state, next), do: {:noreply, state, next} @@ -591,5 +592,10 @@ defmodule GptAgent do def run_in_progress?(pid) do GenServer.call(pid, :run_in_progress?) end + + @impl true + def set_assistant_id(pid, assistant_id) do + GenServer.cast(pid, {:set_assistant_id, assistant_id}) + end end end diff --git a/mix.exs b/mix.exs index 5c492a7..ce31dc2 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule GptAgent.MixProject do def project do [ app: :gpt_agent, - version: "6.1.0", + version: "6.2.0", elixir: "~> 1.16", start_permanent: Mix.env() == :prod, aliases: aliases(), diff --git a/test/gpt_agent_test.exs b/test/gpt_agent_test.exs index c724061..aaf11c6 100644 --- a/test/gpt_agent_test.exs +++ b/test/gpt_agent_test.exs @@ -1380,4 +1380,21 @@ defmodule GptAgentTest do refute GptAgent.run_in_progress?(pid) end end + + describe "set_assistant_id/2" do + test "updates the assistant_id in the agent's state", %{ + assistant_id: assistant_id, + thread_id: thread_id + } do + {:ok, pid} = + GptAgent.connect(thread_id: thread_id, last_message_id: nil, assistant_id: assistant_id) + + assert %GptAgent{assistant_id: ^assistant_id} = :sys.get_state(pid) + + new_assistant_id = UUID.uuid4() + :ok = GptAgent.set_assistant_id(pid, new_assistant_id) + + assert %GptAgent{assistant_id: ^new_assistant_id} = :sys.get_state(pid) + end + end end