Spaces:
Sleeping
Sleeping
Update OpenRouter_Agent.py
Browse files- OpenRouter_Agent.py +20 -23
OpenRouter_Agent.py
CHANGED
|
@@ -25,6 +25,7 @@ if not OPENROUTER_API_KEY:
|
|
| 25 |
common = dict(
|
| 26 |
api_base="https://openrouter.ai/api/v1",
|
| 27 |
api_key=OPENROUTER_API_KEY,
|
|
|
|
| 28 |
)
|
| 29 |
|
| 30 |
|
|
@@ -39,17 +40,14 @@ class MultiAgentSystem:
|
|
| 39 |
def __init__(self):
|
| 40 |
self.deepseek_model = OpenAIServerModel(
|
| 41 |
model_id="deepseek/deepseek-r1-0528:free",
|
| 42 |
-
max_tokens=8096,
|
| 43 |
**common,
|
| 44 |
)
|
| 45 |
self.qwen_model = OpenAIServerModel(
|
| 46 |
model_id="qwen/qwen-2.5-coder-32b-instruct:free",
|
| 47 |
-
max_tokens=8096,
|
| 48 |
**common,
|
| 49 |
)
|
| 50 |
self.gemini_model = OpenAIServerModel(
|
| 51 |
model_id="google/gemini-2.0-flash-exp:free",
|
| 52 |
-
max_tokens=8096,
|
| 53 |
**common,
|
| 54 |
)
|
| 55 |
|
|
@@ -99,35 +97,34 @@ class MultiAgentSystem:
|
|
| 99 |
managed_agents=[self.web_agent, self.info_agent],
|
| 100 |
name="manager_agent",
|
| 101 |
description=(
|
| 102 |
-
"You are the manager.
|
| 103 |
-
"
|
| 104 |
-
"
|
| 105 |
-
"For each task, explicitly explain your planning steps and reasons for choosing which agent, and always prefer the most accurate and complete answer possible."
|
| 106 |
),
|
| 107 |
additional_authorized_imports=[
|
| 108 |
"json",
|
| 109 |
"pandas",
|
| 110 |
"numpy",
|
| 111 |
],
|
| 112 |
-
planning_interval=
|
| 113 |
verbosity_level=2,
|
| 114 |
-
final_answer_checks=[self.check_reasoning],
|
| 115 |
-
max_steps=
|
| 116 |
)
|
| 117 |
|
| 118 |
-
def check_reasoning(self, final_answer, agent_memory):
|
| 119 |
-
model = self.gemini_model
|
| 120 |
-
verification_prompt = (
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
"First list reasons why yes/no, then write your final decision: PASS in caps lock if it is satisfactory, FAIL if it is not."
|
| 125 |
-
)
|
| 126 |
-
output = model(verification_prompt)
|
| 127 |
-
print("Feedback: ", output)
|
| 128 |
-
if "FAIL" in output:
|
| 129 |
-
raise Exception(output)
|
| 130 |
-
return True
|
| 131 |
|
| 132 |
def __call__(self, task: str) -> str:
|
| 133 |
"""
|
|
|
|
| 25 |
common = dict(
|
| 26 |
api_base="https://openrouter.ai/api/v1",
|
| 27 |
api_key=OPENROUTER_API_KEY,
|
| 28 |
+
extra_body={"include": "usage"}
|
| 29 |
)
|
| 30 |
|
| 31 |
|
|
|
|
| 40 |
def __init__(self):
|
| 41 |
self.deepseek_model = OpenAIServerModel(
|
| 42 |
model_id="deepseek/deepseek-r1-0528:free",
|
|
|
|
| 43 |
**common,
|
| 44 |
)
|
| 45 |
self.qwen_model = OpenAIServerModel(
|
| 46 |
model_id="qwen/qwen-2.5-coder-32b-instruct:free",
|
|
|
|
| 47 |
**common,
|
| 48 |
)
|
| 49 |
self.gemini_model = OpenAIServerModel(
|
| 50 |
model_id="google/gemini-2.0-flash-exp:free",
|
|
|
|
| 51 |
**common,
|
| 52 |
)
|
| 53 |
|
|
|
|
| 97 |
managed_agents=[self.web_agent, self.info_agent],
|
| 98 |
name="manager_agent",
|
| 99 |
description=(
|
| 100 |
+
"You are the manager agent. **Respond with a single python code-block only**. "
|
| 101 |
+
"Inside that block you must call the other agents via `agent(name)(task)` "
|
| 102 |
+
"and end with `final_answer({...})`. **No natural language outside the block**"
|
|
|
|
| 103 |
),
|
| 104 |
additional_authorized_imports=[
|
| 105 |
"json",
|
| 106 |
"pandas",
|
| 107 |
"numpy",
|
| 108 |
],
|
| 109 |
+
planning_interval=6,
|
| 110 |
verbosity_level=2,
|
| 111 |
+
#final_answer_checks=[self.check_reasoning],
|
| 112 |
+
max_steps=4,
|
| 113 |
)
|
| 114 |
|
| 115 |
+
#def check_reasoning(self, final_answer, agent_memory):
|
| 116 |
+
#model = self.gemini_model
|
| 117 |
+
#verification_prompt = (
|
| 118 |
+
# f"Here is a user-given task and the agent steps: {agent_memory.get_succinct_steps()}. "
|
| 119 |
+
# f"The proposed final answer is: {final_answer}. "
|
| 120 |
+
# "Please check that the reasoning process is correct: do they correctly answer the given task? "
|
| 121 |
+
#"First list reasons why yes/no, then write your final decision: PASS in caps lock if it is satisfactory, FAIL if it is not."
|
| 122 |
+
#)
|
| 123 |
+
#output = model(verification_prompt)
|
| 124 |
+
#print("Feedback: ", output)
|
| 125 |
+
#if "FAIL" in output:
|
| 126 |
+
#raise Exception(output)
|
| 127 |
+
#return True
|
| 128 |
|
| 129 |
def __call__(self, task: str) -> str:
|
| 130 |
"""
|