Skip to content

Commit 673c6d8

Browse files
authored
Merge pull request #2076 from Open-Source-Legal/improve/document-description-prompt
Improve default Document Description Updater prompt
2 parents af66f0e + 6d09bbd commit 673c6d8

3 files changed

Lines changed: 105 additions & 9 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Rewrote the default `Document Description Updater` action-template prompt (`opencontractserver/corpuses/template_seeds.py`) to lead with the document's subject matter — the goods, services, rights, or obligations it concerns, and the key parties — instead of restating its type or title, and to drop the "This document is …" lead-in. Data migration `agents/0017_update_document_description_prompt` re-syncs already-seeded databases (the seeder skips templates that already exist by name).
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Data migration: sync the seeded "Document Description Updater" template's
2+
# task instructions and description to the current values.
3+
#
4+
# The template is seeded once (agents/0010) via the idempotent
5+
# ``create_default_action_templates`` helper, which SKIPS any template that
6+
# already exists by name. So edits to ``DOCUMENT_DESCRIPTION_INSTRUCTIONS`` or
7+
# the template's ``description`` in ``corpuses/template_seeds.py`` never reach
8+
# already-seeded databases on their own — they must be propagated here.
9+
# Mirrors agents/0016 (CAML writer prompt).
10+
#
11+
# This run rewrites the prompt to lead with the document's subject matter
12+
# (goods, services, rights, obligations) instead of restating its type/title,
13+
# and to drop the "This document is …" lead-in. The UI-visible description is
14+
# updated to match the new behaviour.
15+
#
16+
# Strings are inlined here (not imported from template_seeds) so this migration
17+
# remains a self-contained frozen snapshot: a future rename or move of the
18+
# source constant cannot break ``migrate`` from a clean database.
19+
20+
from django.db import migrations
21+
22+
_TASK_INSTRUCTIONS = (
23+
"Write ONE concise sentence (about 12-25 words) capturing what this "
24+
"document is actually about: the specific subject matter -- the goods, "
25+
"services, rights, obligations, or events it concerns -- and the key "
26+
"parties involved. Lead with the substance, not the document type or title "
27+
'(e.g. "Renewal of an agreement with Acme Foods to supply potatoes to city '
28+
'facilities", not "A renewal agreement titled ..."). Do not begin with '
29+
'"This document is" or "This is", and do not simply restate the title. '
30+
"Mention the document or instrument type only as brief context, not the "
31+
"focus. Use update_document_description to save your result; rewrite any "
32+
"existing description to meet this bar."
33+
)
34+
35+
_UI_DESCRIPTION = (
36+
"Reads a newly added document and writes a one-sentence summary "
37+
"leading with its subject matter and key parties."
38+
)
39+
40+
41+
def update_document_description_prompt(apps, schema_editor): # pragma: no cover
42+
"""Set the Document Description Updater template's task instructions and description.
43+
44+
Idempotent: each field is only written when the stored value differs from
45+
the target, so re-running (or running after a fresh seed that already used
46+
the new values) is a no-op.
47+
"""
48+
CorpusActionTemplate = apps.get_model("corpuses", "CorpusActionTemplate")
49+
tmpl = CorpusActionTemplate.objects.filter(
50+
name="Document Description Updater"
51+
).first()
52+
if tmpl is None:
53+
return
54+
55+
update_fields = []
56+
if tmpl.task_instructions != _TASK_INSTRUCTIONS:
57+
tmpl.task_instructions = _TASK_INSTRUCTIONS
58+
update_fields.append("task_instructions")
59+
if tmpl.description != _UI_DESCRIPTION:
60+
tmpl.description = _UI_DESCRIPTION
61+
update_fields.append("description")
62+
if update_fields:
63+
tmpl.save(update_fields=update_fields)
64+
65+
AgentConfiguration = apps.get_model("agents", "AgentConfiguration")
66+
agent = AgentConfiguration.objects.filter(
67+
name="Document Description Updater Agent"
68+
).first()
69+
if agent is not None and agent.description != _UI_DESCRIPTION:
70+
agent.description = _UI_DESCRIPTION
71+
agent.save(update_fields=["description"])
72+
73+
74+
class Migration(migrations.Migration):
75+
76+
dependencies = [
77+
("agents", "0016_update_caml_article_writer_prompt"),
78+
]
79+
80+
operations = [
81+
migrations.RunPython(
82+
update_document_description_prompt, migrations.RunPython.noop
83+
),
84+
]

opencontractserver/corpuses/template_seeds.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,29 @@ def _build_unique_agent_slug(AgentConfiguration, name: str) -> str:
7575
"get_document_notes",
7676
]
7777

78+
# Per-task prompt for the "Document Description Updater" template. Extracted to a
79+
# named constant so the agents/0017 data migration can re-sync already-seeded
80+
# databases (the seeder skips templates that already exist by name, so editing
81+
# the literal below never reaches them on its own).
82+
DOCUMENT_DESCRIPTION_INSTRUCTIONS = (
83+
"Write ONE concise sentence (about 12-25 words) capturing what this "
84+
"document is actually about: the specific subject matter -- the goods, "
85+
"services, rights, obligations, or events it concerns -- and the key "
86+
"parties involved. Lead with the substance, not the document type or title "
87+
'(e.g. "Renewal of an agreement with Acme Foods to supply potatoes to city '
88+
'facilities", not "A renewal agreement titled ..."). Do not begin with '
89+
'"This document is" or "This is", and do not simply restate the title. '
90+
"Mention the document or instrument type only as brief context, not the "
91+
"focus. Use update_document_description to save your result; rewrite any "
92+
"existing description to meet this bar."
93+
)
94+
7895
TEMPLATES = [
7996
{
8097
"name": "Document Description Updater",
8198
"description": (
82-
"Reads a newly added document and writes a concise description "
83-
"summarising its type, purpose, and key parties."
99+
"Reads a newly added document and writes a one-sentence summary "
100+
"leading with its subject matter and key parties."
84101
),
85102
"trigger": _TRIGGER_ADD_DOCUMENT,
86103
"sort_order": 10,
@@ -94,13 +111,7 @@ def _build_unique_agent_slug(AgentConfiguration, name: str) -> str:
94111
"get_document_description",
95112
"update_document_description",
96113
],
97-
"instructions": (
98-
"Read the document text and write a concise 2-3 sentence description "
99-
"summarising what this document is about, its type (contract, memo, "
100-
"report, etc.), and the key parties or subjects involved. Use "
101-
"update_document_description to save your result. If a description "
102-
"already exists, improve it based on the actual document content."
103-
),
114+
"instructions": DOCUMENT_DESCRIPTION_INSTRUCTIONS,
104115
"badge_config": {"icon": "file-text", "color": "#059669", "label": "Desc"},
105116
},
106117
{

0 commit comments

Comments
 (0)