Update multiagents.py
Browse files- multiagents.py +20 -19
multiagents.py
CHANGED
|
@@ -101,30 +101,31 @@ class MultiAgent:
|
|
| 101 |
print("BasicAgent initialized.")
|
| 102 |
|
| 103 |
def __call__(self, question: str) -> str:
|
| 104 |
-
mylog(self.__class__.__name__, question)
|
| 105 |
|
| 106 |
try:
|
| 107 |
-
prefix =
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
full_prompt = (
|
| 116 |
-
prefix.strip()
|
| 117 |
-
+ "\n\nTHE QUESTION:\n"
|
| 118 |
-
+ question.strip()
|
| 119 |
-
+ "\n\n"
|
| 120 |
-
+ myprompts.output_format.strip()
|
| 121 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
if not isinstance(full_prompt, str):
|
| 123 |
full_prompt = str(full_prompt)
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
| 128 |
except Exception as e:
|
| 129 |
error = f"An error occurred while processing the question: {e}"
|
| 130 |
print(error)
|
|
|
|
| 101 |
print("BasicAgent initialized.")
|
| 102 |
|
| 103 |
def __call__(self, question: str) -> str:
|
| 104 |
+
mylog(self.__class__.__name__, question)
|
| 105 |
|
| 106 |
try:
|
| 107 |
+
prefix = (
|
| 108 |
+
"You are the top agent of a multi-agent system that can answer questions "
|
| 109 |
+
"by coordinating the work of other agents.\n"
|
| 110 |
+
"- Use `web_agent` to search or fetch webpage content.\n"
|
| 111 |
+
"- Use `audiovideo_agent` to process YouTube videos, images, or audio files.\n"
|
| 112 |
+
"- You can also use your own reasoning.\n\n"
|
| 113 |
+
"Find the correct answer step by step, then format your output properly."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
)
|
| 115 |
+
|
| 116 |
+
# ✅ Ensure everything is plain string
|
| 117 |
+
full_prompt = f"{prefix.strip()}\n\nTHE QUESTION:\n{question.strip()}\n\n{myprompts.output_format.strip()}"
|
| 118 |
+
|
| 119 |
+
# ✅ Hard enforcement of string format
|
| 120 |
if not isinstance(full_prompt, str):
|
| 121 |
full_prompt = str(full_prompt)
|
| 122 |
+
|
| 123 |
+
# ✅ Safe model call
|
| 124 |
+
result = manager_agent.run(full_prompt)
|
| 125 |
+
|
| 126 |
+
# Optionally truncate very long answers to avoid submission rejection
|
| 127 |
+
return result if isinstance(result, str) else str(result)
|
| 128 |
+
|
| 129 |
except Exception as e:
|
| 130 |
error = f"An error occurred while processing the question: {e}"
|
| 131 |
print(error)
|