wu981526092 commited on
Commit
5d07fc9
·
1 Parent(s): fd965f0
agentgraph/methods/production/openai_structured_extractor.py CHANGED
@@ -61,9 +61,153 @@ Your task is to extract structured knowledge graphs from agent execution traces.
61
 
62
  You always return a complete knowledge graph with meaningful entities, logical relationships, and accurate metadata."""
63
 
64
- # User prompt - specific instructions and data
65
  user_prompt = f"""Analyze this agent system trace and extract a knowledge graph with the following specifications:
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  ENTITY TYPES:
68
  - Agent: AI agents with specific roles
69
  - Task: Specific tasks or objectives
 
61
 
62
  You always return a complete knowledge graph with meaningful entities, logical relationships, and accurate metadata."""
63
 
64
+ # User prompt - specific instructions with few-shot example and data
65
  user_prompt = f"""Analyze this agent system trace and extract a knowledge graph with the following specifications:
66
 
67
+ COMPLETE EXAMPLE:
68
+ Here's a complete example showing how to extract a knowledge graph from a multi-agent collaboration trace:
69
+
70
+ Expected output structure:
71
+ {{
72
+ "system_name": "California Great America Ticket Analysis System",
73
+ "system_summary": "This system helps analyze the cost-saving potential of purchasing season passes versus individual daily tickets at California's Great America in San Jose. The process starts with an inquiry regarding savings from the Inquiry about Savings from Season Pass vs Daily Tickets (input_001), which is consumed by the Verification Expert (agent_002), who performs the Verify Cost of Daily Ticket and Season Pass in 2024 (task_001).",
74
+ "entities": [
75
+ {{
76
+ "id": "agent_001",
77
+ "type": "Agent",
78
+ "name": "Problem Solving Expert",
79
+ "importance": "HIGH",
80
+ "raw_prompt": "You are given: (1) a task and advises from your manager with a specific plan and (2) a general task. Collect information from the general task, follow the suggestions from manager to solve the task.",
81
+ "raw_prompt_ref": [{{"line_start": 17, "line_end": 17}}, {{"line_start": 34, "line_end": 34}}, {{"line_start": 45, "line_end": 45}}]
82
+ }},
83
+ {{
84
+ "id": "agent_002",
85
+ "type": "Agent",
86
+ "name": "Verification Expert",
87
+ "importance": "HIGH",
88
+ "raw_prompt": "To solve the task and verify the provided costs for a daily ticket and a season pass for California's Great America in San Jose for the summer of 2024, I will follow the steps mentioned in the plan.",
89
+ "raw_prompt_ref": [{{"line_start": 66, "line_end": 66}}, {{"line_start": 112, "line_end": 112}}, {{"line_start": 149, "line_end": 149}}, {{"line_start": 164, "line_end": 164}}]
90
+ }},
91
+ {{
92
+ "id": "agent_003",
93
+ "type": "Agent",
94
+ "name": "Arithmetic Progressions Expert",
95
+ "importance": "MEDIUM",
96
+ "raw_prompt": "Thank you for the thorough verification, Verification_Expert. Given the verified costs and calculation of savings.",
97
+ "raw_prompt_ref": [{{"line_start": 172, "line_end": 172}}, {{"line_start": 181, "line_end": 181}}]
98
+ }},
99
+ {{
100
+ "id": "agent_004",
101
+ "type": "Tool",
102
+ "name": "Computer Terminal",
103
+ "importance": "LOW",
104
+ "raw_prompt": "Code execution environment and computational terminal for running calculations, scripts, and data processing tasks. Provides computational support to other agents when code execution is required.",
105
+ "raw_prompt_ref": [{{"line_start": 21, "line_end": 21}}, {{"line_start": 32, "line_end": 32}}]
106
+ }},
107
+ {{
108
+ "id": "task_001",
109
+ "type": "Task",
110
+ "name": "Verify Cost of Daily Ticket and Season Pass in 2024",
111
+ "importance": "HIGH",
112
+ "raw_prompt": "Verify the accuracy of the provided costs for a daily ticket and a season pass for California's Great America in San Jose for the summer of 2024.",
113
+ "raw_prompt_ref": [{{"line_start": 8, "line_end": 8}}, {{"line_start": 10, "line_end": 10}}, {{"line_start": 11, "line_end": 12}}]
114
+ }},
115
+ {{
116
+ "id": "input_001",
117
+ "type": "Input",
118
+ "name": "Inquiry about Savings from Season Pass vs Daily Tickets",
119
+ "importance": "HIGH",
120
+ "raw_prompt": "How much did I save by purchasing a season pass instead of daily tickets for California's Great America in San Jose, if I planned to visit once a month in June, July, August, and September during the summer of 2024?",
121
+ "raw_prompt_ref": [{{"line_start": 6, "line_end": 6}}]
122
+ }},
123
+ {{
124
+ "id": "output_001",
125
+ "type": "Output",
126
+ "name": "Saved Amount from Season Pass Purchase",
127
+ "importance": "HIGH",
128
+ "raw_prompt": "Amount saved = Total cost of daily tickets - Cost of season pass. Amount saved = $240 - $120 = $120. So, you saved $120 by purchasing a season pass instead of daily tickets.",
129
+ "raw_prompt_ref": [{{"line_start": 119, "line_end": 119}}, {{"line_start": 126, "line_end": 126}}]
130
+ }},
131
+ {{
132
+ "id": "human_001",
133
+ "type": "Human",
134
+ "name": "Park Visitor",
135
+ "importance": "HIGH",
136
+ "raw_prompt": "Person inquiring about ticket cost savings for California's Great America visits",
137
+ "raw_prompt_ref": [{{"line_start": 1, "line_end": 1}}]
138
+ }}
139
+ ],
140
+ "relations": [
141
+ {{
142
+ "id": "relation_001",
143
+ "source": "input_001",
144
+ "target": "agent_002",
145
+ "type": "CONSUMED_BY",
146
+ "importance": "HIGH",
147
+ "interaction_prompt": "Input inquiry is consumed by the Verification Expert for processing and analysis",
148
+ "interaction_prompt_ref": [{{"line_start": 6, "line_end": 6}}]
149
+ }},
150
+ {{
151
+ "id": "relation_002",
152
+ "source": "agent_002",
153
+ "target": "task_001",
154
+ "type": "PERFORMS",
155
+ "importance": "HIGH",
156
+ "interaction_prompt": "Verification Expert performs the task of verifying ticket costs and calculating savings",
157
+ "interaction_prompt_ref": [{{"line_start": 112, "line_end": 112}}, {{"line_start": 164, "line_end": 164}}]
158
+ }},
159
+ {{
160
+ "id": "relation_003",
161
+ "source": "task_001",
162
+ "target": "agent_002",
163
+ "type": "ASSIGNED_TO",
164
+ "importance": "HIGH",
165
+ "interaction_prompt": "Task is assigned to Verification Expert for execution",
166
+ "interaction_prompt_ref": [{{"line_start": 8, "line_end": 8}}]
167
+ }},
168
+ {{
169
+ "id": "relation_004",
170
+ "source": "task_001",
171
+ "target": "output_001",
172
+ "type": "PRODUCES",
173
+ "importance": "HIGH",
174
+ "interaction_prompt": "Task produces the final output showing the amount saved from season pass purchase",
175
+ "interaction_prompt_ref": [{{"line_start": 119, "line_end": 119}}]
176
+ }},
177
+ {{
178
+ "id": "relation_005",
179
+ "source": "output_001",
180
+ "target": "human_001",
181
+ "type": "DELIVERS_TO",
182
+ "importance": "HIGH",
183
+ "interaction_prompt": "Final calculation results are delivered to the park visitor",
184
+ "interaction_prompt_ref": [{{"line_start": 126, "line_end": 126}}]
185
+ }},
186
+ {{
187
+ "id": "relation_006",
188
+ "source": "agent_002",
189
+ "target": "task_001",
190
+ "type": "INTERVENES",
191
+ "importance": "HIGH",
192
+ "interaction_prompt": "Agent intervenes in the task process to provide verification and validation",
193
+ "interaction_prompt_ref": [{{"line_start": 164, "line_end": 164}}]
194
+ }},
195
+ {{
196
+ "id": "relation_007",
197
+ "source": "agent_001",
198
+ "target": "agent_004",
199
+ "type": "USES",
200
+ "importance": "MEDIUM",
201
+ "interaction_prompt": "Agent uses Computer Terminal for computational tasks",
202
+ "interaction_prompt_ref": [{{"line_start": 50, "line_end": 55}}]
203
+ }}
204
+ ],
205
+ "failures": [],
206
+ "optimizations": []
207
+ }}
208
+
209
+ Now analyze the following trace data:
210
+
211
  ENTITY TYPES:
212
  - Agent: AI agents with specific roles
213
  - Task: Specific tasks or objectives