Give a search agent several prompts and score a role by its best one
Migration 14 moves each non-empty agents.intent into agent_prompts as one prompt named after the agent, with its cached vector, and drops the three intent columns. A role's fit is the maximum over the agent's prompts of the calibrated cosine, and scores.prompt names the prompt that won. The agents API takes prompts and still takes intent; the role endpoint serves the agent's score and prompt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b6afe24eaa
commit
4e3c3f130e
9 files changed
+552
-127
No files matched your search
+126
-9
@@ -22,7 +22,7 @@ from pipeline import FINAL, JOBS, SCHEDULES, TASKS, JobQueue, Jobs, RunContext,
|
||||
from plugins.ats import ATSSource # noqa: E402
|
||||
from app.config import CALIBRATION, AgentSeed, Config, ConfigError # noqa: E402
|
||||
from app.jobs import cascade, embed, score # noqa: E402
|
||||
from app.models import Candidate, Gate, Limits, Weights # noqa: E402
|
||||
from app.models import Candidate, Gate, Limits, Prompt, Weights # noqa: E402
|
||||
from app.storage import Store # noqa: E402
|
||||
|
||||
NOW = datetime(2026, 9, 23, 9, 0, tzinfo=UTC)
|
||||
@@ -252,11 +252,11 @@ def test_changing_the_embed_model_drops_old_vectors_and_reembeds(
|
||||
assert dim_a != dim_e5, "the fakes must differ in width for this test to mean anything"
|
||||
|
||||
|
||||
def test_changing_the_embed_model_recomputes_the_agents_cached_intent_vector(
|
||||
def test_changing_the_embed_model_recomputes_the_agents_cached_prompt_vector(
|
||||
store: Store, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""`intent_vector` only returns a cache hit when `intent_key` -- which
|
||||
"""`prompt_vector` only returns a cache hit when `intent_key` -- which
|
||||
hashes the model in -- matches what is stored, so a model change is a
|
||||
cache miss and `_intent` re-encodes under the new model, never handing a
|
||||
cache miss and `_prompts` re-encodes under the new model, never handing a
|
||||
stale-dimension vector into a run's cosines."""
|
||||
fake_a, fake_e5 = FakeEmbedder(), FakeE5Embedder()
|
||||
embedders = {"fake": fake_a, "intfloat/multilingual-e5-small": fake_e5}
|
||||
@@ -267,7 +267,7 @@ def test_changing_the_embed_model_recomputes_the_agents_cached_intent_vector(
|
||||
config_a = Config(database=str(tmp_path / "roledesk.db"), embed={"model": "fake"})
|
||||
run(config_a, store, embed.run_embed)
|
||||
run(config_a, store, score.run_score)
|
||||
vec_a = store.intent_vector(agent.id, score.intent_key("fake", "python backend"))
|
||||
vec_a = store.prompt_vector(agent.id, "Backend", score.intent_key("fake", "python backend"))
|
||||
assert vec_a is not None
|
||||
|
||||
config_e5 = Config(database=str(tmp_path / "roledesk.db"),
|
||||
@@ -277,9 +277,10 @@ def test_changing_the_embed_model_recomputes_the_agents_cached_intent_vector(
|
||||
|
||||
# The old key no longer resolves (the row moved on); the new key does,
|
||||
# at the new model's own width, and scoring this role did not raise.
|
||||
assert store.intent_vector(agent.id, score.intent_key("fake", "python backend")) is None
|
||||
vec_e5 = store.intent_vector(
|
||||
agent.id, score.intent_key("intfloat/multilingual-e5-small", "python backend"))
|
||||
assert store.prompt_vector(
|
||||
agent.id, "Backend", score.intent_key("fake", "python backend")) is None
|
||||
vec_e5 = store.prompt_vector(
|
||||
agent.id, "Backend", score.intent_key("intfloat/multilingual-e5-small", "python backend"))
|
||||
assert vec_e5 is not None
|
||||
assert vec_e5.shape != vec_a.shape
|
||||
assert uid in store.scores(agent.id)
|
||||
@@ -676,13 +677,16 @@ def test_an_agent_without_an_intent_feeds_neither_model_stage_and_is_named(
|
||||
store.save_agent("Backend", "python backend", limits=top_one)
|
||||
blind = store.save_agent("Fresh", "", limits=top_one)
|
||||
store.save_agent("Also fresh", " \n", limits=top_one)
|
||||
store.save_agent("Blank prompts", limits=top_one,
|
||||
prompts=[Prompt(name="One"), Prompt(name="Two", text=" ")])
|
||||
store.save_agent("Off", "", enabled=False)
|
||||
|
||||
run(config, store, embed.run_embed)
|
||||
result = run(config, store, score.run_score)
|
||||
|
||||
assert result["notices"] == ["score.no_intent"]
|
||||
assert result["notice_texts"][0].endswith(": Also fresh, Fresh.")
|
||||
assert result["notice_texts"][0].startswith("No prompt with text")
|
||||
assert result["notice_texts"][0].endswith(": Also fresh, Blank prompts, Fresh.")
|
||||
ranked = sorted(store.scores(blind.id).items(), key=lambda kv: -kv[1][0])
|
||||
assert ranked[0][0] == fresh, "the intent-less agent would pick the newer role"
|
||||
assert [r.uid for r in store.extract_waiting(10)] == [wanted]
|
||||
@@ -744,6 +748,105 @@ def test_the_intent_vector_is_cached_until_the_intent_changes(
|
||||
assert fake.calls[-1] == ["react frontend"]
|
||||
|
||||
|
||||
# ----------------------------------------------------------------- prompts
|
||||
|
||||
def test_fit_is_the_best_prompts_level_and_the_score_names_that_prompt(
|
||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||
backend = role(store, "1", "Backend Engineer", body="Python backend")
|
||||
frontend = role(store, "2", "Frontend Engineer", body="React frontend")
|
||||
gated = role(store, "3", "Backend Engineer", body="Python backend", place="Munich")
|
||||
agent = store.save_agent(
|
||||
"Two kinds", gates=[Gate(field="place", values=["Berlin"])],
|
||||
weights=Weights(fit=1, recency=0, affinity=0),
|
||||
prompts=[Prompt(name="Web", text="react frontend"),
|
||||
Prompt(name="Empty"),
|
||||
Prompt(name="Server", text="python backend")])
|
||||
|
||||
run(config, store, embed.run_embed)
|
||||
run(config, store, score.run_score)
|
||||
|
||||
texts = {backend: "Backend Engineer\nPython backend",
|
||||
frontend: "Frontend Engineer\nReact frontend"}
|
||||
served = {r.uid: r for r in store.roles(agent=agent.id, gated=True)}
|
||||
assert served[backend].prompt == "Server" and served[frontend].prompt == "Web"
|
||||
for uid, text in texts.items():
|
||||
best = max(level(text, "react frontend"), level(text, "python backend"))
|
||||
assert served[uid].score == pytest.approx(best, abs=1e-5)
|
||||
# A gated role has no fit that counted, so no prompt.
|
||||
assert (served[gated].gated_reason, served[gated].prompt) == ("place not Berlin", "")
|
||||
assert fake.calls[1:] == [["react frontend"], ["python backend"]]
|
||||
|
||||
|
||||
def test_one_prompt_scores_exactly_as_the_intent_did(
|
||||
store: Store, config: Config, uncalibrated: Config, fake: FakeEmbedder) -> None:
|
||||
"""The legacy intent, one named prompt, and one prompt beside an empty
|
||||
one are the same agent, calibrated and under the min-max fallback."""
|
||||
for n, body in enumerate(["Python backend", "Python backend data", "React apps", "Data"]):
|
||||
role(store, str(n), "Engineer", body=body)
|
||||
legacy = store.save_agent("Legacy", "python backend")
|
||||
named = store.save_agent("Named", prompts=[Prompt(name="Backend", text="python backend")])
|
||||
padded = store.save_agent("Padded", prompts=[Prompt(name="Later"),
|
||||
Prompt(name="Backend", text="python backend")])
|
||||
run(config, store, embed.run_embed)
|
||||
for cfg in (config, uncalibrated):
|
||||
run(cfg, store, score.run_score)
|
||||
assert store.scores(legacy.id) == store.scores(named.id) == store.scores(padded.id)
|
||||
assert {r.prompt for r in store.roles(agent=legacy.id)} == {"Legacy"}
|
||||
assert {r.prompt for r in store.roles(agent=padded.id)} == {"Backend"}
|
||||
|
||||
|
||||
def test_under_the_fallback_each_prompt_is_ranged_on_its_own(
|
||||
store: Store, uncalibrated: Config, fake: FakeEmbedder) -> None:
|
||||
"""Min-max per prompt: each prompt's closest role gets 1, however far
|
||||
that prompt's roles sit from it in absolute terms."""
|
||||
backend = role(store, "1", "Backend Engineer", body="Python backend")
|
||||
frontend = role(store, "2", "Frontend Engineer", body="React frontend")
|
||||
agent = store.save_agent("Two", weights=Weights(fit=1, recency=0, affinity=0),
|
||||
prompts=[Prompt(name="Server", text="python backend"),
|
||||
Prompt(name="Web", text="react")])
|
||||
run(uncalibrated, store, embed.run_embed)
|
||||
run(uncalibrated, store, score.run_score)
|
||||
|
||||
served = {r.uid: (r.score, r.prompt) for r in store.roles(agent=agent.id)}
|
||||
assert served == {backend: (1.0, "Server"), frontend: (1.0, "Web")}
|
||||
|
||||
|
||||
def test_an_edit_re_embeds_only_the_prompt_it_changed(
|
||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||
role(store, "1")
|
||||
agent = store.save_agent("Two", prompts=[Prompt(name="Server", text="python backend"),
|
||||
Prompt(name="Web", text="react frontend")])
|
||||
run(config, store, score.run_score)
|
||||
run(config, store, score.run_score)
|
||||
assert fake.calls == [["python backend"], ["react frontend"]]
|
||||
|
||||
# Reordered, one renamed and one rewritten: only the new text is encoded.
|
||||
store.save_agent("Two", agent_id=agent.id,
|
||||
prompts=[Prompt(name="Frontend", text="react frontend"),
|
||||
Prompt(name="Server", text="python data")])
|
||||
run(config, store, score.run_score)
|
||||
assert fake.calls[2:] == [["python data"]]
|
||||
|
||||
|
||||
def test_without_an_embedder_the_prompts_are_skipped_and_fit_is_out(
|
||||
store: Store, config: Config, fake: FakeEmbedder,
|
||||
monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
uid = role(store, "1")
|
||||
run(config, store, embed.run_embed)
|
||||
|
||||
def missing(model: str) -> Any:
|
||||
raise ImportError("no sentence_transformers")
|
||||
|
||||
monkeypatch.setattr(embed, "load_embedder", missing)
|
||||
agent = store.save_agent("Fit only", weights=Weights(fit=1, recency=0, affinity=0),
|
||||
prompts=[Prompt(name="Server", text="python backend")])
|
||||
|
||||
result = run(config, store, score.run_score)
|
||||
|
||||
assert result["notices"] == ["embed.unavailable"]
|
||||
assert store.scores(agent.id) == {uid: (0.0, "no prompt vector")}
|
||||
|
||||
|
||||
def test_a_disabled_agent_is_not_scored(
|
||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||
role(store, "1")
|
||||
@@ -780,6 +883,20 @@ def test_the_shipped_starter_agents_validate() -> None:
|
||||
for g in a.gates if g.mode == "prefer"} == {0.05}
|
||||
|
||||
|
||||
def test_a_starter_agent_may_list_prompts_or_give_an_intent(
|
||||
store: Store, tmp_path: Path) -> None:
|
||||
config = Config(database=str(tmp_path / "roledesk.db"), agents=[
|
||||
AgentSeed(name="Old", intent="python backend"),
|
||||
AgentSeed.model_validate({"name": "New", "prompts": [
|
||||
{"name": "AI", "text": "Head of AI"}, {"name": "FDE", "text": "FDE lead"}]})])
|
||||
score.seed_agents(config, store)
|
||||
assert {a.name: a.prompts for a in store.agents()} == {
|
||||
"New": [Prompt(name="AI", text="Head of AI"), Prompt(name="FDE", text="FDE lead")],
|
||||
"Old": [Prompt(name="Old", text="python backend")]}
|
||||
with pytest.raises(ValueError, match="two prompts are named"):
|
||||
AgentSeed.model_validate({"name": "Bad", "prompts": [{"name": "A"}, {"name": "a"}]})
|
||||
|
||||
|
||||
def test_the_shipped_starter_searches_validate() -> None:
|
||||
from app import config as config_mod
|
||||
|
||||
|
||||
+112
-4
@@ -11,10 +11,13 @@ import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
from desk.models import Item
|
||||
import numpy as np
|
||||
|
||||
from app.models import (
|
||||
Application, Limits, TRUSTED_POSTED_HOSTS, company_key, place_key, posted_at,
|
||||
Application, Limits, Prompt, TRUSTED_POSTED_HOSTS, company_key, place_key, posted_at,
|
||||
posted_host, title_key,
|
||||
)
|
||||
from app.storage.store import pack
|
||||
from app.storage import LATEST, Store
|
||||
|
||||
|
||||
@@ -66,7 +69,7 @@ def test_schema_creates_on_an_empty_file(tmp_path: Path) -> None:
|
||||
"application_events", "agents", "scores", "state"} <= tables
|
||||
assert "idx_roles_cluster" in indexes
|
||||
assert store.migrations_applied == []
|
||||
assert LATEST == 13
|
||||
assert LATEST == 14
|
||||
# A second open finds it current and applies nothing.
|
||||
assert Store(path).migrations_applied == []
|
||||
|
||||
@@ -85,11 +88,23 @@ def _columns(path: Path, table: str) -> list[tuple[str, str, int, str]]:
|
||||
return [(r[1], r[2], r[3], r[4]) for r in conn.execute(f"PRAGMA table_info({table})")]
|
||||
|
||||
|
||||
def _undo_v14(conn: sqlite3.Connection) -> None:
|
||||
"""A fresh file put back to the v13 shape: an agent's intent and its
|
||||
cached vector on the agent row, no prompts, no prompt on a score. Every
|
||||
downgrade below starts here, since v14 is the last migration."""
|
||||
conn.execute("DROP TABLE agent_prompts")
|
||||
conn.execute("ALTER TABLE scores DROP COLUMN prompt")
|
||||
conn.execute("ALTER TABLE agents ADD COLUMN intent TEXT NOT NULL DEFAULT ''")
|
||||
conn.execute("ALTER TABLE agents ADD COLUMN intent_key TEXT NOT NULL DEFAULT ''")
|
||||
conn.execute("ALTER TABLE agents ADD COLUMN intent_vec BLOB")
|
||||
|
||||
|
||||
def test_a_v1_file_migrates_to_the_shape_a_new_file_has(tmp_path: Path) -> None:
|
||||
fresh, old = tmp_path / "fresh.db", tmp_path / "old.db"
|
||||
Store(fresh)
|
||||
Store(old)
|
||||
with sqlite3.connect(old) as conn:
|
||||
_undo_v14(conn)
|
||||
conn.execute("DROP INDEX idx_roles_posted") # v9: indexes posted_at
|
||||
for column in ("permit", "languages", "extract_tries", "summary", "summarised_at",
|
||||
"article_text", "article_at", "read_at", "posted_at", "salary_text"):
|
||||
@@ -107,8 +122,8 @@ def test_a_v1_file_migrates_to_the_shape_a_new_file_has(tmp_path: Path) -> None:
|
||||
|
||||
assert Store(old).migrations_applied == list(range(2, LATEST + 1))
|
||||
# ALTER appends, so the order differs; every read is by column name.
|
||||
for table in ("roles", "agents", "vectors", "companies", "role_tags",
|
||||
"agent_companies", "role_votes"):
|
||||
for table in ("roles", "agents", "agent_prompts", "scores", "vectors", "companies",
|
||||
"role_tags", "agent_companies", "role_votes"):
|
||||
assert sorted(_columns(old, table)) == sorted(_columns(fresh, table))
|
||||
|
||||
|
||||
@@ -116,6 +131,7 @@ def test_a_v8_file_gains_ats_slug_and_keeps_its_companies(tmp_path: Path) -> Non
|
||||
path = tmp_path / "v8.db"
|
||||
Store(path).add_company("Acme", ats="teamtailor", country="DK")
|
||||
with sqlite3.connect(path) as conn:
|
||||
_undo_v14(conn)
|
||||
conn.execute("ALTER TABLE companies DROP COLUMN ats_slug")
|
||||
conn.execute("DROP INDEX idx_roles_posted") # v10, which follows
|
||||
conn.execute("ALTER TABLE roles DROP COLUMN posted_at")
|
||||
@@ -134,6 +150,7 @@ def _downgrade_to_v4(path: Path) -> None:
|
||||
"""A fresh file put back to the v4 shape: votes on the role, affinity on
|
||||
the company, no read state, no tags, no per-agent tables."""
|
||||
with sqlite3.connect(path) as conn:
|
||||
_undo_v14(conn)
|
||||
conn.execute("ALTER TABLE roles DROP COLUMN read_at")
|
||||
conn.execute("DROP INDEX idx_roles_posted") # v9: indexes posted_at
|
||||
conn.execute("ALTER TABLE roles DROP COLUMN posted_at") # v9
|
||||
@@ -245,6 +262,7 @@ def test_v10_backfills_posted_at_by_the_same_rule_upsert_uses(
|
||||
assert before_trusted is not None and before_untrusted is not None
|
||||
|
||||
with sqlite3.connect(path) as conn:
|
||||
_undo_v14(conn)
|
||||
conn.execute("DROP INDEX idx_roles_posted")
|
||||
conn.execute("ALTER TABLE roles DROP COLUMN posted_at")
|
||||
conn.execute("ALTER TABLE roles DROP COLUMN salary_text") # v12
|
||||
@@ -272,6 +290,7 @@ def test_v13_recomputes_country_from_place_unless_the_board_or_extract_set_it(
|
||||
for item in (wrong, several, given, extracted):
|
||||
store.upsert_role(item)
|
||||
with sqlite3.connect(path) as conn:
|
||||
_undo_v14(conn)
|
||||
conn.execute("UPDATE roles SET country = 'US' WHERE place = 'Bogota, CO'")
|
||||
conn.execute("UPDATE roles SET country = '' WHERE uid = ?", (several.uid,))
|
||||
conn.execute("UPDATE roles SET extracted_at = '2026-09-23' WHERE uid = ?",
|
||||
@@ -287,6 +306,95 @@ def test_v13_recomputes_country_from_place_unless_the_board_or_extract_set_it(
|
||||
extracted.uid: "US"}
|
||||
|
||||
|
||||
def test_v14_makes_each_intent_the_agents_one_prompt_with_its_vector(tmp_path: Path) -> None:
|
||||
path = tmp_path / "v13.db"
|
||||
store = Store(path)
|
||||
store.upsert_role(posting("a"))
|
||||
uid = posting("a").uid
|
||||
backend = store.save_agent("Backend")
|
||||
blank = store.save_agent("Blank")
|
||||
empty = store.save_agent("Empty")
|
||||
store.replace_scores(backend.id, [(uid, 0.7, "")])
|
||||
vec = np.asarray([0.6, 0.8], dtype=np.float32)
|
||||
with sqlite3.connect(path) as conn:
|
||||
_undo_v14(conn)
|
||||
conn.execute("UPDATE agents SET intent = 'python backend', intent_key = 'k', "
|
||||
"intent_vec = ? WHERE id = ?", (pack(vec), backend.id))
|
||||
conn.execute("UPDATE agents SET intent = ' \n ' WHERE id = ?", (blank.id,))
|
||||
conn.execute("PRAGMA user_version = 13")
|
||||
|
||||
migrated = Store(path)
|
||||
|
||||
assert migrated.migrations_applied == [14]
|
||||
assert migrated.agent(backend.id).prompts == [ # type: ignore[union-attr]
|
||||
Prompt(name="Backend", text="python backend")]
|
||||
assert migrated.agent(blank.id).prompts == [] # type: ignore[union-attr]
|
||||
assert migrated.agent(empty.id).prompts == [] # type: ignore[union-attr]
|
||||
# The key hashes the model and the text, both unchanged: nothing to re-embed.
|
||||
cached = migrated.prompt_vector(backend.id, "Backend", "k")
|
||||
assert cached is not None and cached.tolist() == pytest.approx(vec.tolist())
|
||||
assert migrated.scores(backend.id) == {uid: (0.7, "")}
|
||||
assert migrated.role(uid, backend.id).prompt == "" # type: ignore[union-attr]
|
||||
columns = {c[0] for c in _columns(path, "agents")}
|
||||
assert not {"intent", "intent_key", "intent_vec"} & columns
|
||||
|
||||
|
||||
def test_prompts_are_saved_replaced_reordered_and_deleted(store: Store) -> None:
|
||||
ai = Prompt(name="AI leadership", text="Head of AI")
|
||||
fde = Prompt(name="Forward deployed", text="FDE lead")
|
||||
agent = store.save_agent("Wolf", prompts=[ai, fde])
|
||||
assert store.agent(agent.id).prompts == [ai, fde] # type: ignore[union-attr]
|
||||
store.set_prompt_vector(agent.id, "Forward deployed", "k", np.ones(2))
|
||||
|
||||
# Reordered and renamed, the same text keeps its vector; a new text has none.
|
||||
research = Prompt(name="Research", text="AI research")
|
||||
renamed = Prompt(name="FDE", text="FDE lead")
|
||||
store.save_agent("Wolf", agent_id=agent.id, prompts=[renamed, research])
|
||||
assert [p.name for p in store.agents()[0].prompts] == ["FDE", "Research"]
|
||||
assert store.prompt_vector(agent.id, "FDE", "k") is not None
|
||||
assert store.prompt_vector(agent.id, "Research", "k") is None
|
||||
|
||||
# A prompt may have no text; its name is what must be there, and unique.
|
||||
store.save_agent("Wolf", agent_id=agent.id, prompts=[Prompt(name="Later")])
|
||||
assert store.agents()[0].prompts == [Prompt(name="Later", text="")]
|
||||
with pytest.raises(ValueError, match="two prompts are named 'fde'"):
|
||||
store.save_agent("Wolf", agent_id=agent.id,
|
||||
prompts=[renamed, Prompt(name="fde", text="other")])
|
||||
with pytest.raises(ValidationError, match="a prompt needs a name"):
|
||||
Prompt(name=" ", text="x")
|
||||
assert store.agents()[0].prompts == [Prompt(name="Later")]
|
||||
|
||||
# Without prompts an intent is the one prompt, named after the agent.
|
||||
store.save_agent("Wolf", "python backend", agent_id=agent.id)
|
||||
assert store.agent(agent.id).prompts == [ # type: ignore[union-attr]
|
||||
Prompt(name="Wolf", text="python backend")]
|
||||
store.save_agent("Wolf", agent_id=agent.id)
|
||||
assert store.agent(agent.id).prompts == [] # type: ignore[union-attr]
|
||||
|
||||
store.save_agent("Wolf", agent_id=agent.id, prompts=[ai, fde])
|
||||
store.delete_agent(agent.id)
|
||||
with store.transaction() as conn:
|
||||
assert conn.execute("SELECT COUNT(*) FROM agent_prompts").fetchone()[0] == 0
|
||||
|
||||
|
||||
def test_an_agent_whose_prompts_are_all_empty_feeds_neither_model_stage(
|
||||
store: Store) -> None:
|
||||
store.upsert_role(posting("a"))
|
||||
store.upsert_role(posting("b"))
|
||||
a, b = posting("a").uid, posting("b").uid
|
||||
top = Limits(extract_top=1, extract_min=0, summarise_top=1, summarise_min=0)
|
||||
blank = store.save_agent("Blank", limits=top,
|
||||
prompts=[Prompt(name="One"), Prompt(name="Two", text=" \n")])
|
||||
store.replace_scores(blank.id, [(a, 0.9, "")])
|
||||
assert store.extract_waiting(10) == [] and store.summarise_waiting(10) == []
|
||||
|
||||
# One prompt with text is enough.
|
||||
store.save_agent("Blank", agent_id=blank.id, limits=top,
|
||||
prompts=[Prompt(name="One"), Prompt(name="Two", text="python")])
|
||||
assert [r.uid for r in store.extract_waiting(10)] == [a]
|
||||
assert b not in {r.uid for r in store.summarise_waiting(10)}
|
||||
|
||||
|
||||
def test_state_is_a_mapping(store: Store) -> None:
|
||||
store.state["ats:last"] = "2026-09-23"
|
||||
assert store.state["ats:last"] == "2026-09-23"
|
||||
|
||||
+54
-1
@@ -877,6 +877,59 @@ def test_agents_are_created_updated_listed_and_deleted(client: TestClient) -> No
|
||||
assert client.delete(f"/api/agents/{agent['id']}").status_code == 404
|
||||
|
||||
|
||||
def test_agents_take_and_serve_prompts_and_still_take_an_intent(client: TestClient) -> None:
|
||||
prompts = [{"name": "AI and data leadership", "text": "VP, Head or Director of AI"},
|
||||
{"name": "Forward deployed", "text": ""}]
|
||||
created = client.post("/api/agents", json={"name": "Wolf", "prompts": prompts})
|
||||
assert created.status_code == 200
|
||||
assert created.json()["prompts"] == prompts and "intent" not in created.json()
|
||||
listed = client.get("/api/agents").json()
|
||||
assert listed[0]["prompts"] == prompts and "intent" not in listed[0]
|
||||
|
||||
# Reordered in place; then the body from before prompts, which becomes one.
|
||||
agent_id = created.json()["id"]
|
||||
swapped = client.post("/api/agents", json={"id": agent_id, "name": "Wolf",
|
||||
"prompts": prompts[::-1]})
|
||||
assert swapped.json()["prompts"] == prompts[::-1]
|
||||
legacy = client.post("/api/agents", json={"id": agent_id, "name": "Wolf",
|
||||
"intent": "python backend"})
|
||||
assert legacy.json()["prompts"] == [{"name": "Wolf", "text": "python backend"}]
|
||||
# `prompts` wins over `intent` when both are sent.
|
||||
both = client.post("/api/agents", json={"id": agent_id, "name": "Wolf", "prompts": [],
|
||||
"intent": "python backend"})
|
||||
assert both.json()["prompts"] == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize("prompts, says", [
|
||||
([{"name": "AI", "text": "a"}, {"name": "ai", "text": "b"}], "two prompts are named 'ai'"),
|
||||
([{"name": " ", "text": "a"}], "a prompt needs a name"),
|
||||
])
|
||||
def test_a_duplicate_or_empty_prompt_name_is_a_422_sentence(
|
||||
client: TestClient, prompts: list[dict[str, str]], says: str) -> None:
|
||||
res = client.post("/api/agents", json={"name": "Bad", "prompts": prompts})
|
||||
assert res.status_code == 422 and says in res.json()["detail"]
|
||||
assert client.get("/api/agents").json() == []
|
||||
|
||||
|
||||
def test_the_role_endpoint_serves_the_agents_score_and_its_prompt(
|
||||
client: TestClient, store: Store) -> None:
|
||||
store.upsert_role(posting("1"))
|
||||
uid = posting("1").uid
|
||||
agent = store.save_agent("A", prompts=[])
|
||||
store.replace_scores(agent.id, [(uid, 0.8, "", "Forward deployed")])
|
||||
|
||||
role = client.get(f"/api/roles/{uid}", params={"agent": agent.id}).json()
|
||||
assert (role["score"], role["gated_reason"], role["prompt"]) == \
|
||||
(0.8, "", "Forward deployed")
|
||||
row = client.get("/api/roles", params={"agent": agent.id}).json()["items"][0]
|
||||
assert row["prompt"] == "Forward deployed"
|
||||
voted = client.post(f"/api/roles/{uid}/vote", json={"value": 1, "agent": agent.id})
|
||||
assert voted.json()["score"] == pytest.approx(0.96)
|
||||
other = store.save_agent("B")
|
||||
unscored = client.get(f"/api/roles/{uid}", params={"agent": other.id}).json()
|
||||
assert (unscored["score"], unscored["prompt"]) == (None, "")
|
||||
|
||||
|
||||
def test_deleting_an_agent_takes_its_votes_and_affinities_with_it(
|
||||
client: TestClient, store: Store) -> None:
|
||||
store.upsert_role(posting("1"))
|
||||
@@ -950,7 +1003,7 @@ def test_list_roles_serves_the_row_projection_and_not_the_big_columns(
|
||||
assert set(row) == {
|
||||
"uid", "company_key", "company", "title", "place", "country", "remote", "function",
|
||||
"salary_min", "salary_max", "currency", "salary_text", "salary_state",
|
||||
"original_url", "posted_at", "score", "gated_reason", "vote",
|
||||
"original_url", "posted_at", "score", "gated_reason", "prompt", "vote",
|
||||
"voted_at", "read_at", "tags", "excerpt",
|
||||
}
|
||||
assert row["uid"] == uid
|
||||
|
||||
Reference in new issue
Block a user