Add app agents list and prompt, and document prompts for the seed agents
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4e3c3f130e
commit
2534803df3
3 files changed
+106
-6
No files matched your search
+61
@@ -5,6 +5,7 @@
|
||||
app worker [--workers http=8,cpu=1] [--until-idle]
|
||||
app companies seed|add|set-board|detach|discover|check
|
||||
app searches add|list|remove
|
||||
app agents list|prompt
|
||||
app stages [extract|summarise on|off]
|
||||
app db init
|
||||
|
||||
@@ -110,6 +111,17 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
"remove", help="stop running a search and close its open roles")
|
||||
search_remove.add_argument("name")
|
||||
|
||||
agents = sub.add_parser("agents", help="search agents and their prompts")
|
||||
agents_sub = agents.add_subparsers(dest="action", required=True)
|
||||
agents_sub.add_parser("list", help="every agent and its prompts")
|
||||
prompt = agents_sub.add_parser(
|
||||
"prompt", help="add a prompt to an agent, replace its text, or --remove it")
|
||||
prompt.add_argument("agent", help="the agent's name")
|
||||
prompt.add_argument("name", help='the prompt\'s name, e.g. "AI leadership"')
|
||||
prompt.add_argument("text", nargs="?", default="",
|
||||
help="what the agent looks for, in a sentence or a paragraph")
|
||||
prompt.add_argument("--remove", action="store_true", help="remove the prompt instead")
|
||||
|
||||
stages = sub.add_parser(
|
||||
"stages", help="show whether extract and summarise run, or switch one")
|
||||
stages.add_argument("name", nargs="?", choices=["extract", "summarise"])
|
||||
@@ -135,6 +147,8 @@ def main(argv: list[str] | None = None) -> int:
|
||||
return run_companies(args)
|
||||
if args.command == "searches":
|
||||
return run_searches(args)
|
||||
if args.command == "agents":
|
||||
return run_agents(args)
|
||||
if args.command == "stages":
|
||||
return run_stages(args)
|
||||
return init_db(args)
|
||||
@@ -420,6 +434,53 @@ def add_search(config: config_mod.Config, store: Store, args: argparse.Namespace
|
||||
return 0
|
||||
|
||||
|
||||
def run_agents(args: argparse.Namespace) -> int:
|
||||
"""`app agents list` prints every agent and its prompts. `app agents
|
||||
prompt "Wolf, next role" "AI leadership" "Head of AI ..."` adds that
|
||||
prompt at the end, or replaces the text of the one of that name in its
|
||||
place; `--remove` removes it. The agent's other fields stay as they are.
|
||||
Scores follow at the next `score`."""
|
||||
from app.models import Prompt
|
||||
from app.storage import Store
|
||||
|
||||
config = config_mod.load(args.config)
|
||||
store = Store(config.database)
|
||||
if args.action == "list":
|
||||
for each in store.agents():
|
||||
print(each.name + ("" if each.enabled else " (off)"))
|
||||
for p in each.prompts:
|
||||
text = " ".join(p.text.split())
|
||||
print(f" {p.name}: {text[:100] + '…' if len(text) > 100 else text}")
|
||||
return 0
|
||||
agent = next((a for a in store.agents() if a.name == args.agent), None)
|
||||
if agent is None:
|
||||
print(f"agents prompt: no agent named {args.agent!r}", file=sys.stderr)
|
||||
return 1
|
||||
named = args.name.strip().casefold()
|
||||
prompts = [p for p in agent.prompts if not (args.remove and p.name.casefold() == named)]
|
||||
if args.remove and len(prompts) == len(agent.prompts):
|
||||
print(f"agents prompt: {agent.name!r} has no prompt named {args.name!r}",
|
||||
file=sys.stderr)
|
||||
return 1
|
||||
if not args.remove:
|
||||
try:
|
||||
new = Prompt(name=args.name, text=args.text)
|
||||
except ValueError as exc:
|
||||
print(f"agents prompt: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
at = next((n for n, p in enumerate(prompts) if p.name.casefold() == named), None)
|
||||
if at is None:
|
||||
prompts.append(new)
|
||||
else:
|
||||
prompts[at] = new
|
||||
saved = store.save_agent(agent.name, gates=agent.gates, weights=agent.weights,
|
||||
enabled=agent.enabled, agent_id=agent.id, limits=agent.limits,
|
||||
prompts=prompts)
|
||||
print(json.dumps({"agent": saved.name, "prompts": [p.name for p in saved.prompts]},
|
||||
ensure_ascii=False))
|
||||
return 0
|
||||
|
||||
|
||||
def run_stages(args: argparse.Namespace) -> int:
|
||||
"""`app stages` prints what `GET /api/stages` returns; `app stages extract
|
||||
on` stores the switch through the function `PUT /api/stages/extract`
|
||||
|
||||
+18
-6
@@ -69,7 +69,7 @@ summarise:
|
||||
enabled: false
|
||||
model: claude-haiku-4-5-20251001
|
||||
|
||||
# A role and each agent's intent as vectors, for the fit term of a score
|
||||
# A role and each agent's prompts as vectors, for the fit term of a score
|
||||
# (app/jobs/embed.py). Needs the `embeddings` extra; without it `embed` posts
|
||||
# a notice and scores leave fit out. Changing the model re-embeds.
|
||||
# multilingual-e5-small, not English-only MiniLM, because the corpus is now
|
||||
@@ -117,15 +117,27 @@ sources: {}
|
||||
# 0.65}; measured for "Copenhagen engineering" on 16,841 open roles, 0.55
|
||||
# admits about 300 roles to extract and 0.65 about 35 to summarise. A wide
|
||||
# monitoring search lowers the bars and raises the counts, a narrow hunt the
|
||||
# reverse. An agent without an intent has no fit and feeds neither stage.
|
||||
# reverse. An agent without a prompt that has text has no fit and feeds
|
||||
# neither stage.
|
||||
# prompts is a list of {name, text}, each what the agent looks for; a role's
|
||||
# fit is its best prompt's, so one agent can hunt several kinds of role
|
||||
# without blending them into one paragraph. Votes, gates and limits stay the
|
||||
# agent's, shared by its prompts. intent, as in config.yaml, is one prompt
|
||||
# named after the agent.
|
||||
# The Search agents sub-tab lists and edits them; the order menu on Roles
|
||||
# picks one by name. Two more, beside the starter in config.yaml:
|
||||
agents: []
|
||||
# - name: Remote from Europe
|
||||
# intent: >-
|
||||
# Staff or lead engineer role, fully remote from Europe. Platform and
|
||||
# infrastructure work, distributed systems, developer tooling, technical
|
||||
# leadership across teams.
|
||||
# prompts:
|
||||
# - name: Platform lead
|
||||
# text: >-
|
||||
# Staff or lead engineer role, fully remote from Europe. Platform and
|
||||
# infrastructure work, distributed systems, developer tooling,
|
||||
# technical leadership across teams.
|
||||
# - name: Forward deployed
|
||||
# text: >-
|
||||
# Forward deployed or solutions engineering lead, fully remote from
|
||||
# Europe. Hands-on with customers' systems, owns technical delivery.
|
||||
# gates:
|
||||
# - {field: remote, values: [remote], mode: require}
|
||||
# - {field: country, values: [AT, BE, BG, HR, CY, CZ, DK, EE, FI, FR, DE, GR, HU, IE, IT,
|
||||
|
||||
@@ -897,6 +897,33 @@ def test_a_starter_agent_may_list_prompts_or_give_an_intent(
|
||||
AgentSeed.model_validate({"name": "Bad", "prompts": [{"name": "A"}, {"name": "a"}]})
|
||||
|
||||
|
||||
def test_the_cli_adds_replaces_removes_and_lists_prompts(
|
||||
tmp_path: Path, capsys: pytest.CaptureFixture[str]) -> None:
|
||||
import yaml
|
||||
from app import cli
|
||||
|
||||
db = tmp_path / "roledesk.db"
|
||||
path = tmp_path / "config.yaml"
|
||||
path.write_text(yaml.safe_dump({"database": str(db)}))
|
||||
agent = Store(db).save_agent("Wolf", "Head of data")
|
||||
|
||||
def app(*argv: str) -> int:
|
||||
return cli.main(["-c", str(path), "agents", *argv])
|
||||
|
||||
assert app("prompt", "Wolf", "FDE", "Forward deployed lead") == 0
|
||||
assert app("prompt", "Wolf", "wolf", "Head of AI") == 0 # replaced in place
|
||||
assert app("prompt", "Wolf", "Research") == 0 # no text yet
|
||||
assert Store(db).agent(agent.id).prompts == [ # type: ignore[union-attr]
|
||||
Prompt(name="wolf", text="Head of AI"), Prompt(name="FDE", text="Forward deployed lead"),
|
||||
Prompt(name="Research")]
|
||||
assert app("prompt", "Wolf", "fde", "--remove") == 0
|
||||
assert app("prompt", "Wolf", "Nothing", "--remove") == 1
|
||||
assert app("prompt", "Nobody", "X", "y") == 1
|
||||
capsys.readouterr()
|
||||
assert app("list") == 0
|
||||
assert capsys.readouterr().out == "Wolf\n wolf: Head of AI\n Research: \n"
|
||||
|
||||
|
||||
def test_the_shipped_starter_searches_validate() -> None:
|
||||
from app import config as config_mod
|
||||
|
||||
|
||||
Reference in new issue
Block a user