Spaces:
Sleeping
Sleeping
Commit ·
5c344c8
1
Parent(s): 525b8d9
Create basic thought action observation loop agent
Browse files
app.py
CHANGED
|
@@ -12,6 +12,33 @@ class BasicAgent:
|
|
| 12 |
def __init__(self, metadata_path="metadata.jsonl"):
|
| 13 |
self.metadata = self._load_metadata(metadata_path)
|
| 14 |
print("BasicAgent initialized with metadata")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
def think(self, question, context):
|
| 17 |
|
|
@@ -54,6 +81,24 @@ class BasicAgent:
|
|
| 54 |
return "No action executed"
|
| 55 |
|
| 56 |
def __call__(self, question: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
print(f"Agent received question: {question}")
|
| 59 |
|
|
|
|
| 12 |
def __init__(self, metadata_path="metadata.jsonl"):
|
| 13 |
self.metadata = self._load_metadata(metadata_path)
|
| 14 |
print("BasicAgent initialized with metadata")
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def _load_metadata(self, file_path):
|
| 18 |
+
"""Load metadata from a JSONL file, parsing each line as a JSON object."""
|
| 19 |
+
data = []
|
| 20 |
+
try:
|
| 21 |
+
with open(file_path, 'r', encoding='utf-8') as f:
|
| 22 |
+
for line_number, line in enumerate(f, 1):
|
| 23 |
+
line = line.strip()
|
| 24 |
+
if not line:
|
| 25 |
+
continue
|
| 26 |
+
try:
|
| 27 |
+
obj = json.loads(line)
|
| 28 |
+
if isinstance(obj, dict):
|
| 29 |
+
data.append(obj)
|
| 30 |
+
else:
|
| 31 |
+
print(f"Skipping line {line_number}: not a dictionary")
|
| 32 |
+
except json.JSONDecodeError as e:
|
| 33 |
+
print(f"Error parsing line {line_number}: {e}")
|
| 34 |
+
print(f"Loaded metadata from '{file_path}' with {len(data)} entries")
|
| 35 |
+
return data
|
| 36 |
+
except FileNotFoundError:
|
| 37 |
+
print(f"Metadata file '{file_path}' not found. Proceeding without metadata.")
|
| 38 |
+
return []
|
| 39 |
+
except Exception as e:
|
| 40 |
+
print(f"Unexpected error loading metadata from '{file_path}': {e}")
|
| 41 |
+
return []
|
| 42 |
|
| 43 |
def think(self, question, context):
|
| 44 |
|
|
|
|
| 81 |
return "No action executed"
|
| 82 |
|
| 83 |
def __call__(self, question: str) -> str:
|
| 84 |
+
"""
|
| 85 |
+
User Question
|
| 86 |
+
↓
|
| 87 |
+
Planner
|
| 88 |
+
↓
|
| 89 |
+
Reasoning Loop
|
| 90 |
+
↓
|
| 91 |
+
Tool Selection
|
| 92 |
+
↓
|
| 93 |
+
Tool Execution
|
| 94 |
+
↓
|
| 95 |
+
Observation
|
| 96 |
+
↓
|
| 97 |
+
Repeat until solved
|
| 98 |
+
↓
|
| 99 |
+
Final Answer
|
| 100 |
+
"""
|
| 101 |
+
|
| 102 |
|
| 103 |
print(f"Agent received question: {question}")
|
| 104 |
|