Upload 7 files
Browse files- .gitattributes +1 -0
- Qwen3-4B-Instruct-2507-Q3_K_S.gguf +3 -0
- README.md +3 -7
- main.py +2 -2
- sophos.py +22 -8
- sophos_models.py +22 -18
.gitattributes
CHANGED
|
@@ -34,3 +34,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
sophos.png filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
sophos.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
Qwen3-4B-Instruct-2507-Q3_K_S.gguf filter=lfs diff=lfs merge=lfs -text
|
Qwen3-4B-Instruct-2507-Q3_K_S.gguf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0ce20058cc0ed6b6c9213bb383589327e458c12ffce0842fc96867042d669c75
|
| 3 |
+
size 1886997600
|
README.md
CHANGED
|
@@ -1,14 +1,10 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: mit
|
| 3 |
-
language:
|
| 4 |
-
- en
|
| 5 |
-
---
|
| 6 |
<img src="sophos.png" alt="Sophos Logo" width="500"/>
|
| 7 |
|
| 8 |
# Sophos
|
|
|
|
| 9 |
## -- Wisdom --
|
| 10 |
### Artificial General Intelligence Agent Framework
|
| 11 |
|
| 12 |
-
Sophos is a near-AGI level
|
| 13 |
|
| 14 |
-
Sophos intelligence is limited only by the language model it uses. It is designed to be a flexible and powerful AI agent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
<img src="sophos.png" alt="Sophos Logo" width="500"/>
|
| 2 |
|
| 3 |
# Sophos
|
| 4 |
+
|
| 5 |
## -- Wisdom --
|
| 6 |
### Artificial General Intelligence Agent Framework
|
| 7 |
|
| 8 |
+
Sophos is a near-AGI level Agent designed for tool usage and autonomous task completion. It uses `qwen-3` as a default language model, but can be configured to use any model by changing the `sophos_models.py` file.
|
| 9 |
|
| 10 |
+
Sophos intelligence is limited only by the language model it uses. It is designed to be a flexible and powerful AI agent that can be used for a wide variety of tasks.
|
main.py
CHANGED
|
@@ -9,9 +9,9 @@ def favourite_color() -> str:
|
|
| 9 |
agent = Agent(
|
| 10 |
name="Sophos Agent",
|
| 11 |
instructions="You are an AI Agent.",
|
| 12 |
-
model="
|
| 13 |
tools=[get_weather, get_time, favourite_color],
|
| 14 |
)
|
| 15 |
|
| 16 |
-
response = agent.run("What
|
| 17 |
print(response)
|
|
|
|
| 9 |
agent = Agent(
|
| 10 |
name="Sophos Agent",
|
| 11 |
instructions="You are an AI Agent.",
|
| 12 |
+
model="Qwen3-4B-Instruct-2507-Q3_K_S.gguf",
|
| 13 |
tools=[get_weather, get_time, favourite_color],
|
| 14 |
)
|
| 15 |
|
| 16 |
+
response = agent.run("What is my favorite color? and what is the weather in New York?")
|
| 17 |
print(response)
|
sophos.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from sophos_models import
|
| 2 |
from sophos_tools import *
|
| 3 |
|
| 4 |
class Agent:
|
|
@@ -7,6 +7,7 @@ class Agent:
|
|
| 7 |
self.instructions = instructions
|
| 8 |
self.model = model
|
| 9 |
self.tools = {tool.__name__: tool for tool in tools if hasattr(tool, "_is_tool")}
|
|
|
|
| 10 |
|
| 11 |
def process_tool_calls(self, response_content: str):
|
| 12 |
"""Process tool calls from response content and return results"""
|
|
@@ -69,11 +70,13 @@ CRITICAL:
|
|
| 69 |
```tool
|
| 70 |
<tool_name>(<arg>)
|
| 71 |
```
|
|
|
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
| 77 |
|
| 78 |
user prompt: {prompt}
|
| 79 |
"""
|
|
@@ -86,12 +89,13 @@ user prompt: {prompt}
|
|
| 86 |
|
| 87 |
max_iterations = 99
|
| 88 |
iteration = 0
|
|
|
|
| 89 |
|
| 90 |
while iteration < max_iterations:
|
| 91 |
iteration += 1
|
| 92 |
print(f"\n--- Iteration {iteration} ---")
|
| 93 |
|
| 94 |
-
response = ask(str(messages))
|
| 95 |
|
| 96 |
current_response = response
|
| 97 |
print(f"AI Response: {current_response}")
|
|
@@ -103,8 +107,18 @@ user prompt: {prompt}
|
|
| 103 |
return current_response
|
| 104 |
|
| 105 |
all_results = "\n".join(tool_results)
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
print(f"⚠️ Reached maximum iterations ({max_iterations})")
|
| 110 |
return current_response
|
|
|
|
| 1 |
+
from sophos_models import Sophos
|
| 2 |
from sophos_tools import *
|
| 3 |
|
| 4 |
class Agent:
|
|
|
|
| 7 |
self.instructions = instructions
|
| 8 |
self.model = model
|
| 9 |
self.tools = {tool.__name__: tool for tool in tools if hasattr(tool, "_is_tool")}
|
| 10 |
+
self.sophos = Sophos(model_path=model)
|
| 11 |
|
| 12 |
def process_tool_calls(self, response_content: str):
|
| 13 |
"""Process tool calls from response content and return results"""
|
|
|
|
| 70 |
```tool
|
| 71 |
<tool_name>(<arg>)
|
| 72 |
```
|
| 73 |
+
REMEMBER ALL TOOLS MUST BE INSIDE THE SAME BLOCK
|
| 74 |
|
| 75 |
+
IMPORTANT WORKFLOW:
|
| 76 |
+
1. If you need live information, use the appropriate tool(s) first
|
| 77 |
+
2. Once you have the information you need, provide your final response WITHOUT any tool calls
|
| 78 |
+
3. Do NOT call the same tool repeatedly unless the user asks for updated information
|
| 79 |
+
4. After calling a tool once and getting results, provide your answer to the user
|
| 80 |
|
| 81 |
user prompt: {prompt}
|
| 82 |
"""
|
|
|
|
| 89 |
|
| 90 |
max_iterations = 99
|
| 91 |
iteration = 0
|
| 92 |
+
last_tool_calls = []
|
| 93 |
|
| 94 |
while iteration < max_iterations:
|
| 95 |
iteration += 1
|
| 96 |
print(f"\n--- Iteration {iteration} ---")
|
| 97 |
|
| 98 |
+
response = self.sophos.ask(str(messages))
|
| 99 |
|
| 100 |
current_response = response
|
| 101 |
print(f"AI Response: {current_response}")
|
|
|
|
| 107 |
return current_response
|
| 108 |
|
| 109 |
all_results = "\n".join(tool_results)
|
| 110 |
+
|
| 111 |
+
# Check if we're repeating the same tool calls
|
| 112 |
+
current_tool_calls = [result.split(":")[0] for result in tool_results]
|
| 113 |
+
if current_tool_calls == last_tool_calls and iteration > 1:
|
| 114 |
+
print("⚠️ Detected repeated tool calls - forcing final response")
|
| 115 |
+
messages.append({"role": "assistant", "content": current_response})
|
| 116 |
+
messages.append({"role": "user", "content": f"Tool results:\n{all_results}\n\nYou have already called these tools. Now provide your final answer to the user without calling any more tools."})
|
| 117 |
+
else:
|
| 118 |
+
messages.append({"role": "assistant", "content": current_response})
|
| 119 |
+
messages.append({"role": "user", "content": f"Tool results:\n{all_results}\n\nNow provide your final response to the user. Do NOT call any more tools unless absolutely necessary."})
|
| 120 |
+
|
| 121 |
+
last_tool_calls = current_tool_calls
|
| 122 |
|
| 123 |
print(f"⚠️ Reached maximum iterations ({max_iterations})")
|
| 124 |
return current_response
|
sophos_models.py
CHANGED
|
@@ -1,22 +1,26 @@
|
|
| 1 |
-
import
|
| 2 |
-
import urllib.parse
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
resp = requests.get(url)
|
| 9 |
-
resp.raise_for_status()
|
| 10 |
-
return resp.text
|
| 11 |
-
except requests.HTTPError as e:
|
| 12 |
-
return f"HTTP error: {e} (status {resp.status_code})"
|
| 13 |
-
except Exception as e:
|
| 14 |
-
return f"Request failed: {e}"
|
| 15 |
|
| 16 |
-
def ask(
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
if __name__ == "__main__":
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from llama_cpp import Llama
|
|
|
|
| 2 |
|
| 3 |
+
class Sophos:
|
| 4 |
+
def __init__(self, model_path="Qwen3-4B-Instruct-2507-Q3_K_S.gguf"):
|
| 5 |
+
self.model_path = model_path
|
| 6 |
+
self.model = Llama(model_path=model_path, n_ctx=2048, n_gpu_layers=35)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
def ask(self, prompt):
|
| 9 |
+
"""Ask Sophos a question and return the answer."""
|
| 10 |
+
messages = [
|
| 11 |
+
{"role": "user", "content": prompt}
|
| 12 |
+
]
|
| 13 |
+
|
| 14 |
+
output = self.model.create_chat_completion(messages, max_tokens=1050, temperature=0.7)
|
| 15 |
+
return output["choices"][0]["message"]["content"]
|
| 16 |
|
| 17 |
if __name__ == "__main__":
|
| 18 |
+
sophos = Sophos()
|
| 19 |
+
|
| 20 |
+
while True:
|
| 21 |
+
prompt = input("\nEnter your prompt: ")
|
| 22 |
+
if prompt.lower() in ['exit', 'quit', 'q']:
|
| 23 |
+
break
|
| 24 |
+
|
| 25 |
+
response = sophos.ask(prompt)
|
| 26 |
+
print(response)
|