Skip to content

Commit

Permalink
start supervised
Browse files Browse the repository at this point in the history
  • Loading branch information
jessedrelick committed Aug 19, 2024
1 parent 910cd30 commit 122e002
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 166 deletions.
177 changes: 72 additions & 105 deletions test/agens/agent_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,24 @@ defmodule Agens.AgentTest do
alias Agens.{Agent, Job, Message}
alias Test.Support.Tools.NoopTool

defp start_agens(_ctx) do
{:ok, _pid} = start_supervised({Agens.Supervisor, name: Agens.Supervisor})
:ok
end

defp start_serving(_ctx) do
%Agens.Serving.Config{
name: :text_generation,
serving: Test.Support.Serving.Stub
}
|> Agens.Serving.start()

:ok
end

describe "agents" do
setup [:start_agens, :start_serving]

test "start agents" do
agents =
[
Expand Down Expand Up @@ -47,63 +64,15 @@ defmodule Agens.AgentTest do
result = Agent.message(message)
assert result == {:error, :agent_not_running}
end
end

describe "errors" do
setup [:start_agens, :start_serving]

test "stop non-existent agent" do
result = Agent.stop(:missing_agent)
assert result == {:error, :agent_not_found}
end
end

describe "messages" do
@tag timeout: :infinity
test "message sequence without job" do
get_agent_configs()
|> Agent.start()

input = "D"

# 0
message = %Message{agent_name: :first_agent, input: input}
%Message{result: result} = Agent.message(message)
input = post_process(result)
assert input == "C"
message = %Message{agent_name: :second_agent, input: input}
%Message{result: result} = Agent.message(message)
input = post_process(result)
assert input == "E"
message = %Message{agent_name: :verifier_agent, input: input}
%Message{result: result} = Agent.message(message)
input = post_process(result)
assert input == "E"

# 1
message = %Message{agent_name: :first_agent, input: input}
%Message{result: result} = Agent.message(message)
input = post_process(result)
assert input == "D"
message = %Message{agent_name: :second_agent, input: input}
%Message{result: result} = Agent.message(message)
input = post_process(result)
assert input == "F"
message = %Message{agent_name: :verifier_agent, input: input}
%Message{result: result} = Agent.message(message)
input = post_process(result)
assert input == "F"

# 2
message = %Message{agent_name: :first_agent, input: input}
%Message{result: result} = Agent.message(message)
input = post_process(result)
assert input == "E"
message = %Message{agent_name: :second_agent, input: input}
%Message{result: result} = Agent.message(message)
input = post_process(result)
assert input == "G"
message = %Message{agent_name: :verifier_agent, input: input}
%Message{result: result} = Agent.message(message)
input = post_process(result)
assert input == "TRUE"
end

test "invalid message returns error" do
agent_name = :second_agent
Expand Down Expand Up @@ -138,57 +107,55 @@ defmodule Agens.AgentTest do
end
end

describe "prompt" do
test "full prompt" do
job_name = :test_prompt_job
agent_name = :test_prompt_agent
input = "test input"

prompt = %Agent.Prompt{
identity: "test agent identity",
constraints: "test agent constraints",
context: "test agent context",
reflection: "test agent reflection"
# examples: [
# %{input: "A", output: "C"},
# %{input: "F", output: "H"},
# %{input: "9vasg2rwe", output: "ERROR"}
# ],
}

%Agent.Config{
name: agent_name,
serving: :text_generation,
prompt: prompt,
tool: NoopTool
}
|> Agent.start()

%Job.Config{
name: job_name,
description: "test job description",
steps: [
%Job.Step{
agent: agent_name,
objective: "test step objective",
conditions: %{
"__DEFAULT__" => :end
}
}
]
}
|> Job.start()

Job.run(job_name, input)

assert_receive {:job_started, ^job_name}

assert_receive {:step_started, {^job_name, 0}, "test input"}
assert_receive {:tool_started, {^job_name, 0}, "STUB RUN"}
assert_receive {:tool_raw, {^job_name, 0}, %{}}
assert_receive {:tool_result, {^job_name, 0}, "TRUE"}
assert_receive {:step_result, {^job_name, 0}, "TRUE"}
assert_receive {:job_ended, ^job_name, :complete}
end
end
# describe "sequence" do
# @tag timeout: :infinity
# test "message sequence without job" do
# get_agent_configs()
# |> Agent.start()

# input = "D"

# # 0
# message = %Message{agent_name: :first_agent, input: input}
# %Message{result: result} = Agent.message(message)
# input = post_process(result)
# assert input == "C"
# message = %Message{agent_name: :second_agent, input: input}
# %Message{result: result} = Agent.message(message)
# input = post_process(result)
# assert input == "E"
# message = %Message{agent_name: :verifier_agent, input: input}
# %Message{result: result} = Agent.message(message)
# input = post_process(result)
# assert input == "E"

# # 1
# message = %Message{agent_name: :first_agent, input: input}
# %Message{result: result} = Agent.message(message)
# input = post_process(result)
# assert input == "D"
# message = %Message{agent_name: :second_agent, input: input}
# %Message{result: result} = Agent.message(message)
# input = post_process(result)
# assert input == "F"
# message = %Message{agent_name: :verifier_agent, input: input}
# %Message{result: result} = Agent.message(message)
# input = post_process(result)
# assert input == "F"

# # 2
# message = %Message{agent_name: :first_agent, input: input}
# %Message{result: result} = Agent.message(message)
# input = post_process(result)
# assert input == "E"
# message = %Message{agent_name: :second_agent, input: input}
# %Message{result: result} = Agent.message(message)
# input = post_process(result)
# assert input == "G"
# message = %Message{agent_name: :verifier_agent, input: input}
# %Message{result: result} = Agent.message(message)
# input = post_process(result)
# assert input == "TRUE"
# end
# end
end
Loading

0 comments on commit 122e002

Please sign in to comment.