ofermend commited on
Commit
0b6ee93
·
1 Parent(s): 9d16acb
Files changed (1) hide show
  1. agent.py +60 -33
agent.py CHANGED
@@ -56,6 +56,9 @@ class AgentTools:
56
  Args
57
  case_citation (str): the citation for a particular case. Citation must include the volume number, reporter, and first page. For example: 253 P.2d 136.
58
  summarize (bool): True to return just a summary of the case, False to return full case text.
 
 
 
59
  """
60
  citation_dict = extract_components_from_citation(case_citation)
61
  if not citation_dict:
@@ -82,10 +85,16 @@ class AgentTools:
82
 
83
  def get_case_document_pdf(
84
  self,
85
- case_citation = Field(description = citation_description)
86
  ) -> str:
87
  """
88
- Given a case citation, returns a valid web url to a pdf of the case record
 
 
 
 
 
 
89
  """
90
  citation_dict = extract_components_from_citation(case_citation)
91
  if not citation_dict:
@@ -102,10 +111,16 @@ class AgentTools:
102
 
103
  def get_case_document_page(
104
  self,
105
- case_citation = Field(description = citation_description)
106
  ) -> str:
107
  """
108
- Given a case citation, returns a valid web url to a page with information about the case.
 
 
 
 
 
 
109
  """
110
  citation_dict = extract_components_from_citation(case_citation)
111
  if not citation_dict:
@@ -121,10 +136,16 @@ class AgentTools:
121
 
122
  def get_case_name(
123
  self,
124
- case_citation = Field(description = citation_description)
125
  ) -> Tuple[str, str]:
126
  """
127
  Given a case citation, returns its name and name abbreviation.
 
 
 
 
 
 
128
  """
129
  citation_dict = extract_components_from_citation(case_citation)
130
  if not citation_dict:
@@ -140,11 +161,16 @@ class AgentTools:
140
 
141
  def get_cited_cases(
142
  self,
143
- case_citation = Field(description = citation_description)
144
  ) -> List[dict]:
145
  """
146
  Given a case citation, returns a list of cases that are cited by the opinion of this case.
147
- The output is a list of cases, each a dict with the citation, name and name_abbreviation of the case.
 
 
 
 
 
148
  """
149
  citation_dict = extract_components_from_citation(case_citation)
150
  if not citation_dict:
@@ -169,15 +195,20 @@ class AgentTools:
169
 
170
  def validate_url(
171
  self,
172
- url = Field(description = "A web url pointing to case-law document")
173
  ) -> str:
174
  """
175
- Given a link, returns whether or not the link is valid.
176
- If it is not valid, it should not be used in any output.
 
 
 
 
 
177
  """
178
  pdf_pattern = re.compile(r'^https://static.case.law/.*')
179
  document_pattern = re.compile(r'^https://case.law/caselaw/?reporter=.*')
180
- return "URL is valid" if bool(pdf_pattern.match(url)) | bool(document_pattern.match(url)) else "URL is bad"
181
 
182
  def get_tools(self):
183
  class QueryCaselawArgs(BaseModel):
@@ -238,34 +269,30 @@ def get_agent_config() -> OmegaConf:
238
  def initialize_agent(_cfg, agent_progress_callback=None):
239
 
240
  legal_assistant_instructions = """
241
- - You are a helpful legal assistant, with expertise in case law for the state of Alaska.
242
- - The ask_caselaw tool is your primary tool for answering user questions. Do not use your own knowledge to answer questions.
243
- - If the ask_caselaw tool responds that it does not have enough information to answer the question,
244
- try to rephrase the query or break it down into multiple sub-questions, and use the tool again.
245
- - If the ask_caselaw tool returns a response along with a list of references mentioned in its response (in [N] format),
246
- Format your response to focus on the main response, and use the metadata (such as citations, decision date, or case name)
247
- in each relevant reference to provide more context in your response.
248
- - If the ask_caselaw tool returns references with case citations, use the `get_case_document_pdf` tool to get a valid URL for the case.
249
- and then use that link in your response to provide a clickable link to the case.
250
- - Citations include 3 components: volume number, reporter, and first page.
 
251
  Here are some examples: '253 P.2d 136', '10 Alaska 11', '6 C.M.A. 3'
252
- - Never use your internal knowledge to guess citations. Only use citations information provided by a tool or the user.
253
- - If you need a valid URL of the full case PDF, call the get_case_document_pdf tool.
254
- - If you need a valid URL of the case information page, call the get_case_document_page tool.
255
- The text displayed with this URL should be the name_abbreviation of the case (DON'T just say the info can be found here).
256
- Don't call the get_case_document_page tool until after you have tried the get_case_document_pdf tool.
257
- Don't provide URLs from any other tools. Do not generate URLs yourself.
258
  - If two cases have conflicting rulings, assume that the case with the more current ruling date is correct.
259
  - If the response is based on cases that are older than 5 years, make sure to inform the user that the information may be outdated,
260
  since some case opinions may no longer apply in law.
261
- - To summarize the case, use the get_opinion_text with summarize=True.
262
- - Use get_opinion_text with summarize=False only when full text is needed. Consider summarizing the text when possible to make things run faster.
263
- - When presenting a URL in your response, use the 'validate_url' tool.
264
- - If a user wants to test their argument, use the ask_caselaw tool to gather information about cases related to their argument
265
- and the critique_as_judge tool to determine whether their argument is sound or has issues that must be corrected.
266
  - Never discuss politics, and always respond politely.
 
267
  """
268
  agent_config = AgentConfig()
 
269
  agent = Agent(
270
  tools=AgentTools(_cfg, agent_config).get_tools(),
271
  topic="Case law in Alaska",
@@ -273,5 +300,5 @@ def initialize_agent(_cfg, agent_progress_callback=None):
273
  agent_progress_callback=agent_progress_callback,
274
  agent_config=agent_config
275
  )
276
- agent.report()
277
  return agent
 
56
  Args
57
  case_citation (str): the citation for a particular case. Citation must include the volume number, reporter, and first page. For example: 253 P.2d 136.
58
  summarize (bool): True to return just a summary of the case, False to return full case text.
59
+
60
+ returns
61
+ str: the full opinion/ruling text of the case, or the summary if summarize is True.
62
  """
63
  citation_dict = extract_components_from_citation(case_citation)
64
  if not citation_dict:
 
85
 
86
  def get_case_document_pdf(
87
  self,
88
+ case_citation: str = Field(description = citation_description)
89
  ) -> str:
90
  """
91
+ Given a case citation, returns a valid web URL to a pdf of the case record
92
+
93
+ Args:
94
+ case_citation (str): the citation for a particular case. Citation must include the volume number, reporter, and first page. For example: 253 P.2d 136.
95
+
96
+ Returns:
97
+ str: a valid web URL to a pdf of the case record
98
  """
99
  citation_dict = extract_components_from_citation(case_citation)
100
  if not citation_dict:
 
111
 
112
  def get_case_document_page(
113
  self,
114
+ case_citation: str = Field(description = citation_description)
115
  ) -> str:
116
  """
117
+ Given a case citation, returns a valid web URL to a page with information about the case.
118
+
119
+ Args:
120
+ case_citation (str): the citation for a particular case. Citation must include the volume number, reporter, and first page. For example: 253 P.2d 136.
121
+
122
+ Returns:
123
+ str: a valid web URL to a page with information about the case
124
  """
125
  citation_dict = extract_components_from_citation(case_citation)
126
  if not citation_dict:
 
136
 
137
  def get_case_name(
138
  self,
139
+ case_citation: str = Field(description = citation_description)
140
  ) -> Tuple[str, str]:
141
  """
142
  Given a case citation, returns its name and name abbreviation.
143
+
144
+ Args:
145
+ case_citation (str): the citation for a particular case. Citation must include the volume number, reporter, and first page. For example: 253 P.2d 136.
146
+
147
+ Returns:
148
+ Tuple[str, str]: the name and name abbreviation of the case
149
  """
150
  citation_dict = extract_components_from_citation(case_citation)
151
  if not citation_dict:
 
161
 
162
  def get_cited_cases(
163
  self,
164
+ case_citation: str = Field(description = citation_description)
165
  ) -> List[dict]:
166
  """
167
  Given a case citation, returns a list of cases that are cited by the opinion of this case.
168
+
169
+ Args:
170
+ case_citation (str): the citation for a particular case. Citation must include the volume number, reporter, and first page. For example: 253 P.2d 136.
171
+
172
+ Returns:
173
+ A list of cases, each a dict with the citation, name and name_abbreviation of the case.
174
  """
175
  citation_dict = extract_components_from_citation(case_citation)
176
  if not citation_dict:
 
195
 
196
  def validate_url(
197
  self,
198
+ url: str = Field(description = "A web url pointing to case-law document")
199
  ) -> str:
200
  """
201
+ Given a url, returns whether or not the url is valid.
202
+
203
+ Args:
204
+ url (str): A web url pointing to case-law document
205
+
206
+ Returns:
207
+ str: "URL is valid" if the url is valid, "URL is invalid" otherwise.
208
  """
209
  pdf_pattern = re.compile(r'^https://static.case.law/.*')
210
  document_pattern = re.compile(r'^https://case.law/caselaw/?reporter=.*')
211
+ return "URL is valid" if pdf_pattern.match(url) or document_pattern.match(url) else "URL is invalid"
212
 
213
  def get_tools(self):
214
  class QueryCaselawArgs(BaseModel):
 
269
  def initialize_agent(_cfg, agent_progress_callback=None):
270
 
271
  legal_assistant_instructions = """
272
+ - You are a helpful legal assistant, with case law expertise in the state of Alaska.
273
+ - Use the 'ask_caselaw' tool as your primary tool for answering user questions. Do not use your own knowledge to answer questions.
274
+ - If the 'ask_caselaw' tool responds that it does not have enough information to answer the question,
275
+ try to rephrase the query, or break the original query down into multiple sub-questions, and use the 'ask_caselaw' tool again.
276
+ - The references returned by the 'ask_caselaw' tool include metadata relevant to its response, such as case citations, dates, or names.
277
+ - When using a case citation in your response, try to include a valid URL along with it:
278
+ * Call the 'get_case_document_pdf' for a case citation to obtain a valid web URL to a pdf of the case record.
279
+ * If this doesn't work, call the 'get_case_document_page' for a case citation to obtain a valid web URL to a page with information about the case.
280
+ - When including a URL for a citation in your response, use the citation as anchor text, and the URL as the link.
281
+ - Never use your internal knowledge to guess a case citation. Only use citation information provided by a tool or the user.
282
+ - A Case Citation includes 3 components: volume number, reporter, and first page.
283
  Here are some examples: '253 P.2d 136', '10 Alaska 11', '6 C.M.A. 3'
 
 
 
 
 
 
284
  - If two cases have conflicting rulings, assume that the case with the more current ruling date is correct.
285
  - If the response is based on cases that are older than 5 years, make sure to inform the user that the information may be outdated,
286
  since some case opinions may no longer apply in law.
287
+ - To summarize the case, use the 'get_opinion_text' with summarize=True.
288
+ - Use 'get_opinion_text' with summarize=False only when full text is needed. Consider summarizing the text when possible to make things run faster.
289
+ - If a user wants to test their argument, use the 'ask_caselaw' tool to gather information about cases related to their argument
290
+ and the 'critique_as_judge' tool to determine whether their argument is sound or has issues that must be corrected.
 
291
  - Never discuss politics, and always respond politely.
292
+ - Your response should not include markdown.
293
  """
294
  agent_config = AgentConfig()
295
+
296
  agent = Agent(
297
  tools=AgentTools(_cfg, agent_config).get_tools(),
298
  topic="Case law in Alaska",
 
300
  agent_progress_callback=agent_progress_callback,
301
  agent_config=agent_config
302
  )
303
+ agent.report(detailed=False)
304
  return agent