diff --git a/lib/gpt_agent.ex b/lib/gpt_agent.ex index 9c67d3f..79c3915 100644 --- a/lib/gpt_agent.ex +++ b/lib/gpt_agent.ex @@ -458,7 +458,7 @@ defmodule GptAgent do case Registry.lookup(GptAgent.Registry, opts.thread_id) do [{pid, :gpt_agent}] -> - handle_existing_agent(pid, opts.last_message_id) + handle_existing_agent(pid, opts.last_message_id, opts.assistant_id) [] -> handle_no_existing_agent( @@ -523,10 +523,11 @@ defmodule GptAgent do defp maybe_subscribe(result, _opts), do: result - defp handle_existing_agent(pid, last_message_id) do + defp handle_existing_agent(pid, last_message_id, assistant_id) do log("Found existing GPT Agent with PID #{inspect(pid)}") log("Updating last message ID to #{inspect(last_message_id)}") GenServer.cast(pid, {:set_last_message_id, last_message_id}) + GenServer.cast(pid, {:set_assistant_id, assistant_id}) {:ok, pid} end diff --git a/mix.exs b/mix.exs index ce31dc2..4d2a7ae 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule GptAgent.MixProject do def project do [ app: :gpt_agent, - version: "6.2.0", + version: "7.0.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 aaf11c6..316849d 100644 --- a/test/gpt_agent_test.exs +++ b/test/gpt_agent_test.exs @@ -281,16 +281,22 @@ defmodule GptAgentTest do refute_receive {^pid, %UserMessageAdded{}} end - test "does not update the assistant id on an agent if the agent is already running", + test "updates the assistant id on an agent if the agent is already running", %{thread_id: thread_id, assistant_id: assistant_id} do {:ok, pid1} = GptAgent.connect(thread_id: thread_id, last_message_id: nil, assistant_id: assistant_id) + new_assistant_id = UUID.uuid4() + {:ok, pid2} = - GptAgent.connect(thread_id: thread_id, last_message_id: nil, assistant_id: UUID.uuid4()) + GptAgent.connect( + thread_id: thread_id, + last_message_id: nil, + assistant_id: new_assistant_id + ) assert pid1 == pid2 - assert %GptAgent{assistant_id: ^assistant_id} = :sys.get_state(pid1) + assert %GptAgent{assistant_id: ^new_assistant_id} = :sys.get_state(pid1) end test "loads existing thread run status when connecting to thread with a run history", %{