You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: exercises/Python/07-solve-the-crime.md
+55-33Lines changed: 55 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,13 @@
1
1
# Use your AI Agents to solve the crime
2
2
3
-
The only thing missing now is your **Lead Detective Agent**. This agent will then use the information retrieved from the other two agents to solve the crime and determine the value of the stolen items.
3
+
The only thing missing now is your **Lead Detective Agent**. This agent will synthesize information from all three specialized agents to solve the crime and determine the value of the stolen items.
4
+
5
+
You now have complete intelligence gathering capabilities:
6
+
- 📊 **Financial predictions** from the Appraiser (RPT-1)
7
+
- 📄 **Internal evidence** from the Evidence Analyst (Grounding Service)
8
+
- 🌐 **External intelligence** from the Intelligence Researcher (Web Search)
9
+
10
+
The Lead Detective will combine all three sources for a comprehensive conclusion.
4
11
5
12
## Build Your Lead Detective Agent
6
13
@@ -30,8 +37,13 @@ lead_detective_agent:
30
37
```yaml
31
38
solve_crime:
32
39
description: >
33
-
Find the thief among the suspects by activating the evidence analyst agent and instructing them to look for information on each of the three suspects
34
-
using the grounding tool. They should find information on alibis and motives and return a report for you to analyze.
40
+
Find the thief among the suspects by reviewing:
41
+
1. The insurance appraisal values from the appraiser agent
42
+
2. The internal evidence analysis from the evidence analyst agent
43
+
3. The web intelligence report from the intelligence researcher agent
44
+
45
+
Synthesize all three sources to identify the culprit with high confidence.
46
+
Consider both internal evidence and external patterns/connections found online.
35
47
expected_output: >
36
48
The name of the thief and the total value of the stolen goods for the insurance.
37
49
agent: lead_detective_agent
@@ -43,7 +55,7 @@ Now you'll add the Lead Detective Agent and its task to your investigator crew.
43
55
44
56
👉 Open [`/project/Python/starter-project/investigator_crew.py`](/project/Python/starter-project/investigator_crew.py)
45
57
46
-
👉 **Inside the `InvestigatorCrew` class**, add the new agent and task methods **after** the existing `analyze_evidence_task` method and **before** the `@crew` method:
58
+
👉 **Inside the `InvestigatorCrew` class**, add the new agent and task methods **after** the existing `research_criminal_network` method and **before** the `@crew` method:
47
59
48
60
```python
49
61
@agent
@@ -57,25 +69,27 @@ Now you'll add the Lead Detective Agent and its task to your investigator crew.
57
69
def solve_crime(self) -> Task:
58
70
return Task(
59
71
config=self.tasks_config['solve_crime'],
60
-
context=[self.appraise_loss_task(), self.analyze_evidence_task()] # 👈 Lead detective uses results from other tasks
72
+
context=[self.appraise_loss_task(), self.analyze_evidence_task(), self.research_criminal_network()] # Lead detective uses all three sources
61
73
)
62
74
```
63
75
64
-
> 💡 **Where to place this code**: Add these methods inside the `InvestigatorCrew` class, after your `analyze_evidence_task()` method. The final order should be:
76
+
> 💡 **Where to place this code**: Add these methods inside the `InvestigatorCrew` class, after your `research_criminal_network()` method. The final order should be:
> - `context=[self.appraise_loss_task(), self.analyze_evidence_task()]` tells CrewAI that the `solve_crime` task depends on the other two tasks
77
-
> - The Lead Detective will receive the output from both the Loss Appraiser and Evidence Analyst
78
-
> - This enables the detective to combine financial predictions with evidence analysis to solve the crime
90
+
> - `context=[self.appraise_loss_task(), self.analyze_evidence_task(), self.research_criminal_network()]` tells CrewAI that the `solve_crime` task depends on all three prior tasks
91
+
> - The Lead Detective receives output from the Appraiser, Evidence Analyst, AND Intelligence Researcher
92
+
> - This enables comprehensive analysis using financial data, internal evidence, and web intelligence
79
93
80
94
### Step 4: Verify Crew Configuration
81
95
@@ -87,9 +101,9 @@ Your crew configuration should already be set from Exercise 04, but let's verify
87
101
@crew
88
102
def crew(self) -> Crew:
89
103
return Crew(
90
-
agents=self.agents, # Automatically collected by @agent decorator (all 3 agents)
91
-
tasks=self.tasks, # Automatically collected by @task decorator (all 3 tasks)
92
-
process=Process.sequential, # Tasks run in order: appraise → analyze → solve
104
+
agents=self.agents, # Automatically collected by @agent decorator (all 4 agents)
105
+
tasks=self.tasks, # Automatically collected by @task decorator (all 4 tasks)
106
+
process=Process.sequential, # Tasks run in order: appraise → analyze → research → solve
93
107
verbose=True # Print detailed execution logs
94
108
)
95
109
```
@@ -98,9 +112,9 @@ Your crew configuration should already be set from Exercise 04, but let's verify
98
112
99
113
### Step 5: Verify main.py (No Changes Needed)
100
114
101
-
Your `main.py` from Exercise 04 should already be correct. It doesn't need any changes for Exercise 06!
115
+
Your `main.py` from Exercise 04 should already be correct. It doesn't need any changes for Exercise 07!
102
116
103
-
> 💡 **What's happening:** The same `main.py` that ran 2 agents in Exercise 04 will now automatically run all 3 agents (including your new Lead Detective). CrewAI collects all `@agent` and `@task` decorated methods automatically.
117
+
> 💡 **What's happening:** The same `main.py` that ran 2 agents in Exercise 04 will now automatically run all 4 agents (Appraiser, Evidence Analyst, Intelligence Researcher, and Lead Detective). CrewAI collects all `@agent` and `@task` decorated methods automatically.
104
118
105
119
👉 (Optional) Double-check your [`/project/Python/starter-project/main.py`](/project/Python/starter-project/main.py) has both required inputs:
106
120
@@ -153,11 +167,12 @@ python main.py
153
167
python main.py
154
168
```
155
169
156
-
> ⏱️ **This may take 2-5 minutes** as your agents:
170
+
> ⏱️ **This may take 3-6 minutes** as your agents:
157
171
>
158
-
> 1. Search evidence documents for each suspect
159
-
> 2. Predict values of stolen items using RPT-1
160
-
> 3. Analyze findings and identify the culprit
172
+
> 1. Search evidence documents for each suspect (Evidence Analyst)
173
+
> 2. Predict values of stolen items using RPT-1 (Appraiser)
174
+
> 3. Search the web for criminal patterns (Intelligence Researcher)
175
+
> 4. Synthesize all findings and identify the culprit (Lead Detective)
161
176
162
177
👉 Review the final output—who does your Lead Detective identify as the thief?
163
178
@@ -236,11 +251,12 @@ python main.py
236
251
237
252
You created a complete multi-agent system where:
238
253
239
-
1. **The Lead Detective Agent** orchestrates the investigation by delegating tasks
240
-
2. **The Evidence Analyst Agent** retrieves and analyzes evidence from documents
241
-
3. **The Loss Appraiser Agent** predicts financial values of stolen items
242
-
4. **Agent Communication** flows through task delegation and result aggregation
243
-
5. **Reasoning Integration** combines evidence, alibis, motives, and values to solve the crime
254
+
1. **The Lead Detective Agent** orchestrates the investigation by synthesizing multiple sources
255
+
2. **The Evidence Analyst Agent** retrieves and analyzes evidence from internal documents
256
+
3. **The Intelligence Researcher Agent** gathers external intelligence via web search
257
+
4. **The Loss Appraiser Agent** predicts financial values of stolen items
258
+
5. **Agent Communication** flows through task delegation and result aggregation
259
+
6. **Multi-Source Reasoning** combines internal evidence, web intelligence, and financial data to solve the crime
244
260
245
261
### The Investigation Flow
246
262
@@ -252,10 +268,14 @@ flowchart TD
252
268
A --> E[Loss Appraisal]
253
269
E --> F[RPT-1 Predictions]
254
270
F --> G[Value Determination]
255
-
D --> H[Crime Resolution]
256
-
G --> H
257
-
H --> I[Suspect Identification]
258
-
I --> J[Final Report]
271
+
A --> H[Web Intelligence]
272
+
H --> I[Sonar-Pro Search]
273
+
I --> J[Pattern Analysis]
274
+
D --> K[Crime Resolution]
275
+
G --> K
276
+
J --> K
277
+
K --> L[Suspect Identification]
278
+
L --> M[Final Report]
259
279
```
260
280
261
281
### Why This Matters
@@ -290,14 +310,16 @@ In the following exercises, you will:
290
310
2. ✅ Add custom tools to your agents so they can access external data
291
311
3. ✅ Create a complete crew with multiple agents working together
292
312
4. ✅ Integrate the Grounding Service for better reasoning and fact-checking
293
-
5. ✅ Solve the museum art theft mystery using your fully-featured agent team (this exercise)
313
+
5. ✅ Add web search for external intelligence gathering
314
+
6. ✅ Solve the museum art theft mystery using your fully-featured agent team (this exercise)
294
315
295
316
Congratulations on completing the CodeJam! You've successfully built a sophisticated multi-agent AI system that can:
296
317
297
-
- Analyze evidence from documents
318
+
- Analyze evidence from internal documents
319
+
- Search the web for external intelligence
298
320
- Predict financial values using the SAP-RPT-1 model
299
321
- Coordinate between multiple specialized agents
300
-
- Solve complex real-world problems through collaborative reasoning
322
+
- Solve complex real-world problems through collaborative reasoning with multi-source intelligence
Copy file name to clipboardExpand all lines: project/Python/solution/config/tasks.yaml
+32-6Lines changed: 32 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -7,19 +7,45 @@ appraise_loss_task:
7
7
8
8
analyze_evidence_task:
9
9
description: >
10
-
Analyze the evidence of the theft that you can access via the grounding tool.
11
-
Provide any insights that can help in the investigation especially regarding alabies.
12
-
Check the evidence for all three suspect names 1. Sophie Dubois, 2. Marcus Chen and
10
+
Analyze the evidence of the theft that you can access via the grounding tool.
11
+
Provide any insights that can help in the investigation especially regarding alabies.
12
+
Check the evidence for all three suspect names 1. Sophie Dubois, 2. Marcus Chen and
13
13
3. Viktor Petrovand and provide an analysis for each of them.
14
14
expected_output: >
15
15
A detailed analysis of the evidence for each suspect, including any insights that can help in the investigation.
16
16
agent: evidence_analyst_agent
17
17
18
+
research_criminal_network:
19
+
description: >
20
+
Search the web for intelligence about the three suspects ({suspect_names}) and
21
+
related crimes. Use the call_sonar_pro_search tool to find:
22
+
1. Public criminal records or prior convictions for each suspect
23
+
2. Similar art theft incidents with the same modus operandi (insider job, no forced entry)
24
+
3. Connections to known art theft rings or criminal networks
25
+
4. News reports or public information about any of the suspects
26
+
5. Recent museum heists in Europe with similar patterns
27
+
28
+
Cross-reference your web findings with the internal evidence analyzed by the
29
+
evidence analyst. Focus on discovering whether this is an isolated incident or
30
+
part of a larger criminal operation.
31
+
expected_output: >
32
+
A comprehensive intelligence report containing:
33
+
- Background checks for all three suspects with web sources
34
+
- List of similar art thefts found online (dates, locations, MO)
35
+
- Evidence of criminal network connections (if any)
36
+
- Assessment: isolated incident vs. organized crime ring
37
+
- All findings MUST include web sources with URLs and dates
38
+
agent: intelligence_researcher_agent
39
+
18
40
solve_crime:
19
41
description: >
20
-
Find the thief from, the suspects by activating the evidence investigator agent and instructing him to look for the three suspects
21
-
using the grounding tool. He should find information on alibies and motives and return a report for you to analyze. And use the appraise_loss_task from
22
-
the appraiser agent to find the value of the stolen goods.
42
+
Find the thief among the suspects by reviewing:
43
+
1. The insurance appraisal values from the appraiser agent
44
+
2. The internal evidence analysis from the evidence analyst agent
45
+
3. The web intelligence report from the intelligence researcher agent
46
+
47
+
Synthesize all three sources to identify the culprit with high confidence.
48
+
Consider both internal evidence and external patterns/connections found online.
23
49
expected_output: >
24
50
The name of the thief and the total value of the stolen goods for the insurance.
"""Search the web using Perplexity's sonar-pro model for real-time information
78
+
about crimes, suspects, and criminal patterns. Use this to find similar incidents,
79
+
criminal networks, public records, or patterns that are not in internal documents.
80
+
81
+
Args:
82
+
search_query: The search query about crimes, suspects, or criminal patterns
83
+
84
+
Returns:
85
+
Search results with source citations from the web
86
+
"""
87
+
fromlitellmimportcompletion
88
+
89
+
try:
90
+
response=completion(
91
+
model="sap/sonar-pro", # Perplexity model with web search
92
+
messages=[
93
+
{
94
+
"role": "system",
95
+
"content": "You are a web search assistant specializing in criminal intelligence. Search for accurate, recent information and always provide source citations with URLs and dates."
96
+
},
97
+
{
98
+
"role": "user",
99
+
"content": search_query
100
+
}
101
+
],
102
+
temperature=0.2, # Lower temperature for factual search
103
+
)
104
+
105
+
result=response.choices[0].message.content
106
+
returnresult
107
+
108
+
exceptExceptionase:
109
+
returnf"Error calling sonar-pro web search: {str(e)}"
0 commit comments