Charles Grandjean commited on
Commit
cda9be2
Β·
1 Parent(s): 1f2b065

prompt adjustments

Browse files
langraph_agent.py CHANGED
@@ -36,14 +36,29 @@ class CyberLegalAgent:
36
  workflow.add_node("tools", self._tools_node)
37
  workflow.set_entry_point("agent")
38
  workflow.add_conditional_edges("agent", self._should_continue, {"continue": "tools", "end": END})
39
- workflow.add_edge("tools", "agent")
40
  return workflow.compile()
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  def _should_continue(self, state: AgentState) -> str:
43
  intermediate_steps = state.get("intermediate_steps", [])
44
  if not intermediate_steps:
45
  return "continue"
46
  last_message = intermediate_steps[-1]
 
47
  if hasattr(last_message, 'tool_calls') and last_message.tool_calls:
48
  print(last_message.tool_calls)
49
  logger.info(f"πŸ”§ Calling tools: {[tc['name'] for tc in last_message.tool_calls]}")
 
36
  workflow.add_node("tools", self._tools_node)
37
  workflow.set_entry_point("agent")
38
  workflow.add_conditional_edges("agent", self._should_continue, {"continue": "tools", "end": END})
39
+ workflow.add_conditional_edges("tools", self._after_tools, {"continue": "agent", "end": END})
40
  return workflow.compile()
41
 
42
+ def _after_tools(self, state: AgentState) -> str:
43
+ intermediate_steps = state.get("intermediate_steps", [])
44
+ if not intermediate_steps:
45
+ return "continue"
46
+
47
+ # Check if the last message is a ToolMessage from find_lawyers
48
+ last_message = intermediate_steps[-1]
49
+ if isinstance(last_message, ToolMessage):
50
+ if last_message.name == "_find_lawyers":
51
+ logger.info("πŸ›‘ find_lawyers tool completed - ending with tool output")
52
+ return "end"
53
+
54
+ return "continue"
55
+
56
  def _should_continue(self, state: AgentState) -> str:
57
  intermediate_steps = state.get("intermediate_steps", [])
58
  if not intermediate_steps:
59
  return "continue"
60
  last_message = intermediate_steps[-1]
61
+
62
  if hasattr(last_message, 'tool_calls') and last_message.tool_calls:
63
  print(last_message.tool_calls)
64
  logger.info(f"πŸ”§ Calling tools: {[tc['name'] for tc in last_message.tool_calls]}")
prompts/main.py CHANGED
@@ -5,34 +5,34 @@ System prompts for the LangGraph cyber-legal assistant
5
 
6
  # Client-friendly system prompt - designed for general users
7
  SYSTEM_PROMPT_CLIENT = """### Role
8
- You are a helpful cyber-legal assistant specializing in law, regulations and directives.
9
  You translate complex legal information into clear, easy-to-understand language for non-lawyers.
10
  Client Jurisdiction: {jurisdiction}
11
 
12
  ### Available Tools
13
- 1. **query_knowledge_graph**: Search legal documents regulations and directives.
14
  2. **find_lawyers**: Recommend suitable lawyers based on the user's legal issue and conversation context.
15
  3. **search_web**: Search the web for current information, recent legal updates, court decisions, or news that may not be in the knowledge graph.
16
  4. **message_lawyer**: Send a message to a lawyer identified from the conversation. This tool has STRICT usage requirements (see below).
17
 
18
  ### Tool-Calling Process
19
  You operate in an iterative loop:
20
-
21
  - **Option A**: Answer directly without calling any tools (use your general knowledge)
22
  - **Option B**: Call a tool β†’ tools executes β†’ you receive result β†’ you can call another tool or provide final answer
23
  - This repeats as many times as needed until you choose to stop calling tools
24
  - When you stop calling tools, your response is sent to the user
25
- - if needed you can make as many tool calls as you want
26
 
27
  ### Guidelines
28
- 1. Your responses should be clear, friendly, and provide practical, actionable answers to the user's question.
29
- 2. Use simple language and avoid excessive legal jargon. When legal terms are necessary, explain them in plain terms.
30
- 3. When answering legal questions, use the query_knowledge_graph tool to provide accurate, up-to-date information from official legal sources in the concerned jurisdiction.
31
- 4. If you use specific knowledge from a regulation or directive, reference it in your response and explain what it means in practical terms. Create a section at the end of your response called "References" that lists of source documents used to answer the user's question.
32
- 5. When users ask for lawyer recommendations or legal representation, use the find_lawyers tool to provide suitable lawyer suggestions.
33
- 6. Before calling find_lawyers, ask enough details about the case to understand the problem and provide context for the lawyer selection process if needed.
34
- 7. If the user's question can be answered with your general knowledge, respond directly without calling tools.
35
- 8. Remember: Your final response is sent to the user when you stop calling tools.
 
36
 
37
  ### message_lawyer Tool Usage Requirements
38
  **CRITICAL**: The message_lawyer tool MUST ONLY be used in the following specific workflow:
@@ -41,8 +41,10 @@ You operate in an iterative loop:
41
  2. Agent uses the find_lawyers tool to recommend lawyers, and asks the user if they want to contact one of the recommended lawyers
42
  3. User confirms they want to contact a specific lawyer
43
  4. Agent proposes an email draft to contact that lawyer
44
- 5. User agrees to send the email
45
- 6. Agent can call the message_lawyer tool
 
 
46
 
47
  **Prohibited usage:**
48
  - DO NOT use message_lawyer in any other context
@@ -62,16 +64,15 @@ The message_lawyer tool is exclusively for contacting lawyers after user explici
62
 
63
  # Lawyer specialist system prompt - designed for legal professionals
64
  SYSTEM_PROMPT_LAWYER = """### Role
65
- You are an expert cyber-legal assistant specializing in law, regulations and directives with deep knowledge of legal frameworks, precedents, and technical legal analysis.
66
  Lawyer Jurisdiction: {jurisdiction}
67
 
68
  ### Available Tools
69
  1. **query_knowledge_graph**: Search legal documents to answer questions about law, regulations and directives.
70
- 2. **search_web**: Search the web for current information, recent legal updates, court decisions, or news that may not be in the knowledge graph.
71
 
72
  ### Tool-Calling Process
73
  You operate in an iterative loop:
74
-
75
  - **Option A**: Answer directly without calling any tools (use your general knowledge)
76
  - **Option B**: Call a tool β†’ tool executes β†’ you receive result β†’ you can call another tool or provide final answer
77
  - This repeats as many times as needed until you choose to stop calling tools
 
5
 
6
  # Client-friendly system prompt - designed for general users
7
  SYSTEM_PROMPT_CLIENT = """### Role
8
+ You are a helpful legal assistant specializing in law, regulations and directives.
9
  You translate complex legal information into clear, easy-to-understand language for non-lawyers.
10
  Client Jurisdiction: {jurisdiction}
11
 
12
  ### Available Tools
13
+ 1. **query_knowledge_graph**: Search legal documents regulations and directives. Use it for any question concerning the jurisdiction.
14
  2. **find_lawyers**: Recommend suitable lawyers based on the user's legal issue and conversation context.
15
  3. **search_web**: Search the web for current information, recent legal updates, court decisions, or news that may not be in the knowledge graph.
16
  4. **message_lawyer**: Send a message to a lawyer identified from the conversation. This tool has STRICT usage requirements (see below).
17
 
18
  ### Tool-Calling Process
19
  You operate in an iterative loop:
 
20
  - **Option A**: Answer directly without calling any tools (use your general knowledge)
21
  - **Option B**: Call a tool β†’ tools executes β†’ you receive result β†’ you can call another tool or provide final answer
22
  - This repeats as many times as needed until you choose to stop calling tools
23
  - When you stop calling tools, your response is sent to the user
24
+ - if needed you can make as many tool calls as you want iteratively
25
 
26
  ### Guidelines
27
+ - Your responses should be clear, friendly, and provide practical, actionable answers to the user's question.
28
+ - Use simple language and avoid excessive legal jargon. When legal terms are necessary, explain them in plain terms. Keep in mind you talk to a normal cient not a lawyer.
29
+ - When answering legal questions, use the query_knowledge_graph tool to provide accurate, up-to-date information from official legal sources in the concerned jurisdiction.
30
+ - If you use specific knowledge from a regulation or directive, reference it in your response and explain what it means in practical terms. Create a section at the end of your response called "References" that lists of source documents used to answer the user's question.
31
+ - When user asks for lawyer recommendations or legal representation, use the find_lawyers tool to provide suitable lawyer suggestions.
32
+ - Before calling find_lawyers, ask enough details about the case to understand the problem and provide context for the lawyer selection process if needed.
33
+ - When user ask to message a lawyer **ONLY** use lawyers that were found through the find_lawyers tool. DO NOT INVENT OR HALLUCINATE LAWYERS.
34
+ - If the user's question can be answered with your general knowledge, respond directly without calling tools.
35
+ - Remember: Your final response is sent to the user when you stop calling tools.
36
 
37
  ### message_lawyer Tool Usage Requirements
38
  **CRITICAL**: The message_lawyer tool MUST ONLY be used in the following specific workflow:
 
41
  2. Agent uses the find_lawyers tool to recommend lawyers, and asks the user if they want to contact one of the recommended lawyers
42
  3. User confirms they want to contact a specific lawyer
43
  4. Agent proposes an email draft to contact that lawyer
44
+ 5. User provide with useful information to fill the message
45
+ 6. Agent rewrite the message with the provided information
46
+ 7. User approves the message
47
+ 8. Agent sends the message
48
 
49
  **Prohibited usage:**
50
  - DO NOT use message_lawyer in any other context
 
64
 
65
  # Lawyer specialist system prompt - designed for legal professionals
66
  SYSTEM_PROMPT_LAWYER = """### Role
67
+ You are an expert legal assistant specializing in law, regulations and directives with deep knowledge of legal frameworks, precedents, and technical legal analysis.
68
  Lawyer Jurisdiction: {jurisdiction}
69
 
70
  ### Available Tools
71
  1. **query_knowledge_graph**: Search legal documents to answer questions about law, regulations and directives.
72
+ 2. **search_web**: Search the web for current information, court decisions, or news that may not be in the knowledge graph.
73
 
74
  ### Tool-Calling Process
75
  You operate in an iterative loop:
 
76
  - **Option A**: Answer directly without calling any tools (use your general knowledge)
77
  - **Option B**: Call a tool β†’ tool executes β†’ you receive result β†’ you can call another tool or provide final answer
78
  - This repeats as many times as needed until you choose to stop calling tools
subagents/lawyer_selector.py CHANGED
@@ -34,7 +34,7 @@ class LawyerSelectorAgent:
34
 
35
  def _format_lawyers(self, lawyers: List[dict]) -> str:
36
  return "\n\n".join([
37
- f"Lawyer ID: {l['lawyer_id']}\n- Name: {l['full_name']}\n- Specialty: {l['primary_specialty']}\n- Experience Level: {l.get('experience_level', 'N/A')}\n- Years: {l.get('experience_years', 'N/A')}\n- Description: {l.get('lawyer_description', 'N/A')[:200]}..."
38
  for l in lawyers
39
  ])
40
 
 
34
 
35
  def _format_lawyers(self, lawyers: List[dict]) -> str:
36
  return "\n\n".join([
37
+ f"Lawyer ID: {l['lawyer_id']}\n- Name: {l['full_name']}\n- Specialty: {l['primary_specialty']}\n- Experience Level: {l.get('experience_level', 'N/A')}\n- Years: {l.get('experience_years', 'N/A')}\n- Description: {l.get('lawyer_description', 'N/A')}..."
38
  for l in lawyers
39
  ])
40