wu981526092 commited on
Commit
c0f7273
ยท
1 Parent(s): 09d46fc
Files changed (2) hide show
  1. debug_relations.py +0 -67
  2. test_improved_relations.py +0 -174
debug_relations.py DELETED
@@ -1,67 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Debug script to check why some relations aren't being detected as using specialized logic.
4
- """
5
-
6
- import json
7
- import sys
8
- sys.path.append('/Users/zekunwu/Desktop/agent_monitoring/huggingface/AgentGraph')
9
-
10
- from agentgraph.reconstruction import PromptReconstructor
11
-
12
- def debug_relation_detection():
13
- """Debug relation type detection."""
14
- print("๐Ÿ” Debugging Relation Type Detection")
15
- print("=" * 60)
16
-
17
- # Load sample data
18
- kg_path = '/Users/zekunwu/Desktop/agent_monitoring/huggingface/AgentGraph/backend/database/samples/knowledge_graphs/kg_algorithm_sample_16.json'
19
-
20
- with open(kg_path, 'r') as f:
21
- kg_data = json.load(f)
22
-
23
- kg = kg_data['graph_data']
24
- reconstructor = PromptReconstructor(kg)
25
-
26
- # Test each relation type
27
- relation_types = ["DELIVERS_TO", "PRODUCES", "REQUIRED_BY", "USES"]
28
-
29
- for rel_type in relation_types:
30
- print(f"\n๐Ÿงช Testing {rel_type}:")
31
-
32
- type_relations = [r for r in kg['relations'] if r['type'] == rel_type]
33
-
34
- if not type_relations:
35
- print(f" โš ๏ธ No {rel_type} relations found")
36
- continue
37
-
38
- relation = type_relations[0]
39
- print(f" ๐Ÿ“‹ Relation: {relation['id']}")
40
- print(f" Source: {relation['source']} โ†’ Target: {relation['target']}")
41
-
42
- # Get entity types
43
- source_entity = next(e for e in kg['entities'] if e['id'] == relation['source'])
44
- target_entity = next(e for e in kg['entities'] if e['id'] == relation['target'])
45
-
46
- print(f" Source type: {source_entity['type']}")
47
- print(f" Target type: {target_entity['type']}")
48
-
49
- # Test reconstruction
50
- result = reconstructor.reconstruct_relation_prompt(relation['id'])
51
-
52
- if "error" in result:
53
- print(f" โŒ Error: {result['error']}")
54
- continue
55
-
56
- prompt = result.get('reconstructed_prompt', '')
57
- print(f" ๐Ÿ“ Prompt length: {len(prompt)} chars")
58
- print(f" ๐Ÿ“ First 200 chars: {prompt[:200]}...")
59
-
60
- # Check for specialized logic indicators
61
- indicators = ["TASK COMPLETION", "FINAL DELIVERY", "DEPENDENCY CHECK", "SYSTEM ROUTING"]
62
- specialized = any(indicator in prompt for indicator in indicators)
63
-
64
- print(f" ๐ŸŽฏ Specialized logic detected: {'โœ… Yes' if specialized else 'โŒ No'}")
65
-
66
- if __name__ == "__main__":
67
- debug_relation_detection()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test_improved_relations.py DELETED
@@ -1,174 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Test the improved relation handling in prompt reconstruction.
4
- Focus on CONSUMED_BY and other newly added relation types.
5
- """
6
-
7
- import json
8
- import sys
9
- sys.path.append('/Users/zekunwu/Desktop/agent_monitoring/huggingface/AgentGraph')
10
-
11
- from agentgraph.reconstruction import PromptReconstructor
12
-
13
- def test_consumed_by_relation():
14
- """Test the specific CONSUMED_BY relation that was problematic."""
15
- print("๐Ÿงช Testing CONSUMED_BY Relation Handling")
16
- print("=" * 60)
17
-
18
- # Load the sample with CONSUMED_BY relation
19
- kg_path = '/Users/zekunwu/Desktop/agent_monitoring/huggingface/AgentGraph/backend/database/samples/knowledge_graphs/kg_algorithm_sample_16.json'
20
-
21
- with open(kg_path, 'r') as f:
22
- kg_data = json.load(f)
23
-
24
- kg = kg_data['graph_data']
25
-
26
- # Initialize reconstructor
27
- reconstructor = PromptReconstructor(kg)
28
-
29
- # Find the CONSUMED_BY relation
30
- consumed_by_relations = [r for r in kg['relations'] if r['type'] == 'CONSUMED_BY']
31
-
32
- if not consumed_by_relations:
33
- print("โŒ No CONSUMED_BY relations found in sample")
34
- return
35
-
36
- print(f"Found {len(consumed_by_relations)} CONSUMED_BY relation(s)")
37
-
38
- for relation in consumed_by_relations:
39
- print(f"\n๐Ÿ” Testing relation: {relation['id']}")
40
- print(f" Source: {relation['source']} โ†’ Target: {relation['target']}")
41
- print(f" Interaction prompt: {relation.get('interaction_prompt', 'None')}")
42
-
43
- # Test the reconstruction
44
- result = reconstructor.reconstruct_relation_prompt(relation['id'])
45
-
46
- if "error" in result:
47
- print(f"โŒ Error: {result['error']}")
48
- continue
49
-
50
- print(f"\nโœ… Reconstruction successful!")
51
- print(f"๐Ÿ“ Generated prompt preview:")
52
- print("-" * 40)
53
- prompt = result.get('reconstructed_prompt', '')
54
- # Show first 300 characters
55
- print(prompt[:300] + "..." if len(prompt) > 300 else prompt)
56
- print("-" * 40)
57
-
58
- # Check if it's no longer the generic fallback
59
- if "SYSTEM ROUTING" in prompt:
60
- print("โœ… Using specialized CONSUMED_BY logic (not generic fallback)")
61
- else:
62
- print("โš ๏ธ May still be using generic fallback")
63
-
64
- def test_all_relation_types():
65
- """Test all supported relation types."""
66
- print("\n\n๐Ÿงช Testing All Relation Types")
67
- print("=" * 60)
68
-
69
- # Load a sample that has multiple relation types
70
- kg_path = '/Users/zekunwu/Desktop/agent_monitoring/huggingface/AgentGraph/backend/database/samples/knowledge_graphs/kg_algorithm_sample_16.json'
71
-
72
- with open(kg_path, 'r') as f:
73
- kg_data = json.load(f)
74
-
75
- kg = kg_data['graph_data']
76
-
77
- # Initialize reconstructor
78
- reconstructor = PromptReconstructor(kg)
79
-
80
- # Get all relation types in this sample
81
- relation_types = set(r['type'] for r in kg['relations'])
82
-
83
- print(f"Relation types found in sample: {sorted(relation_types)}")
84
-
85
- # Test each relation type
86
- results = {}
87
- for rel_type in sorted(relation_types):
88
- print(f"\n๐Ÿ” Testing {rel_type} relations:")
89
-
90
- type_relations = [r for r in kg['relations'] if r['type'] == rel_type]
91
-
92
- for relation in type_relations[:1]: # Test first one of each type
93
- result = reconstructor.reconstruct_relation_prompt(relation['id'])
94
-
95
- if "error" in result:
96
- results[rel_type] = "โŒ Error"
97
- print(f" โŒ Error: {result['error']}")
98
- else:
99
- prompt = result.get('reconstructed_prompt', '')
100
-
101
- # Check prompt quality indicators
102
- if len(prompt) < 50:
103
- results[rel_type] = "โš ๏ธ Too short"
104
- print(f" โš ๏ธ Prompt too short ({len(prompt)} chars)")
105
- elif rel_type in prompt or "METADATA:" in prompt or "SYSTEM ROUTING:" in prompt:
106
- results[rel_type] = "โœ… Specialized"
107
- print(f" โœ… Using specialized logic ({len(prompt)} chars)")
108
- else:
109
- results[rel_type] = "โš ๏ธ Generic"
110
- print(f" โš ๏ธ May be using generic fallback ({len(prompt)} chars)")
111
-
112
- # Summary
113
- print(f"\n๐Ÿ“Š RELATION TYPE COVERAGE SUMMARY:")
114
- print("-" * 40)
115
- for rel_type, status in results.items():
116
- print(f" {rel_type:15} โ†’ {status}")
117
-
118
- def demonstrate_improved_consumed_by():
119
- """Show the improvement in CONSUMED_BY relation handling."""
120
- print("\n\n๐ŸŽฏ CONSUMED_BY Improvement Demonstration")
121
- print("=" * 60)
122
-
123
- # Load sample data
124
- kg_path = '/Users/zekunwu/Desktop/agent_monitoring/huggingface/AgentGraph/backend/database/samples/knowledge_graphs/kg_algorithm_sample_16.json'
125
-
126
- with open(kg_path, 'r') as f:
127
- kg_data = json.load(f)
128
-
129
- kg = kg_data['graph_data']
130
- reconstructor = PromptReconstructor(kg)
131
-
132
- # Find the specific CONSUMED_BY relation we were asked about
133
- consumed_by_relations = [r for r in kg['relations'] if r['type'] == 'CONSUMED_BY']
134
-
135
- if consumed_by_relations:
136
- relation = consumed_by_relations[0] # Take the first one
137
-
138
- print(f"๐Ÿ“‹ Original relation:")
139
- print(f" ID: {relation['id']}")
140
- print(f" Type: {relation['type']}")
141
- print(f" Source: {relation['source']} (Input)")
142
- print(f" Target: {relation['target']} (Agent)")
143
- print(f" Interaction: {relation.get('interaction_prompt', 'None')}")
144
-
145
- # Get source and target entities
146
- source_entity = next(e for e in kg['entities'] if e['id'] == relation['source'])
147
- target_entity = next(e for e in kg['entities'] if e['id'] == relation['target'])
148
-
149
- print(f"\n๐Ÿ“‹ Entity details:")
150
- print(f" Input: {source_entity['name']}")
151
- print(f" Agent: {target_entity['name']} - {target_entity.get('description', 'No description')}")
152
-
153
- # Reconstruct the prompt
154
- result = reconstructor.reconstruct_relation_prompt(relation['id'])
155
-
156
- if "error" not in result:
157
- print(f"\nโœ… NEW IMPROVED PROMPT:")
158
- print("=" * 50)
159
- print(result['reconstructed_prompt'])
160
- print("=" * 50)
161
-
162
- print(f"\n๐ŸŽฏ Key improvements:")
163
- print(" โœ… Clear system routing semantics")
164
- print(" โœ… Proper input โ†’ agent relationship")
165
- print(" โœ… Explains the dispatch logic")
166
- print(" โœ… Shows agent specialization")
167
- print(" โœ… Indicates next workflow step")
168
-
169
- if __name__ == "__main__":
170
- test_consumed_by_relation()
171
- test_all_relation_types()
172
- demonstrate_improved_consumed_by()
173
-
174
- print(f"\n๐ŸŽ‰ Testing completed! CONSUMED_BY relation handling has been significantly improved.")