AGofficial commited on
Commit
0f6fdc4
·
verified ·
1 Parent(s): 68d0082

Upload 8 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip 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
 
 
 
 
 
33
  *.zip 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
+ AGI.png filter=lfs diff=lfs merge=lfs -text
37
+ ArtificialGeneralIntelligence.pdf filter=lfs diff=lfs merge=lfs -text
38
+ Qwen3-4B-Instruct-2507-Q3_K_S.gguf filter=lfs diff=lfs merge=lfs -text
39
+ sophos.png filter=lfs diff=lfs merge=lfs -text
AGI.png ADDED

Git LFS Details

  • SHA256: 4ec20d80d488743f729d04b5a30221a6d4892475ba9236ebec56fff172401257
  • Pointer size: 132 Bytes
  • Size of remote file: 6.45 MB
ArtificialGeneralIntelligence.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7fb9e7d571936ff4cf2f36929eceedbfbfc0c88b601d50406a7e527472568549
3
+ size 785625
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
main.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sophos import Agent
2
+ from sophos_tools import get_weather, get_time, function_tool
3
+
4
+ @function_tool
5
+ def favourite_color() -> str:
6
+ '''fetches the user's favorite color.'''
7
+ return "My favorite color is crimson red."
8
+
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.png ADDED

Git LFS Details

  • SHA256: 1709651f85da9b749053485351114e90803ab50d657d4606666091902ef708ce
  • Pointer size: 132 Bytes
  • Size of remote file: 2.72 MB
sophos.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sophos_models import Sophos
2
+ from sophos_tools import *
3
+
4
+ class Agent:
5
+ def __init__(self, name: str, instructions: str, model: str, tools: list):
6
+ self.name = name
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"""
14
+ if "```tool" not in response_content:
15
+ return None
16
+
17
+ print("🔧 TOOL DETECTED - Processing...")
18
+ try:
19
+ tool_block = response_content.split("```tool")[1].split("```")[0].strip()
20
+ print(f"🔧 Tool block found: {tool_block}")
21
+
22
+ tool_results = []
23
+ tool_lines = [line.strip() for line in tool_block.split('\n') if line.strip()]
24
+
25
+ for tool_line in tool_lines:
26
+ if "(" in tool_line and ")" in tool_line:
27
+ tool_name = tool_line.split("(")[0].strip()
28
+ arg_part = tool_line.split("(", 1)[1].rsplit(")", 1)[0].strip()
29
+ arg = arg_part.strip('"').strip("'")
30
+
31
+ if tool_name in self.tools:
32
+ print(f"🔧 CALLING TOOL: {tool_name}({arg})")
33
+ if arg:
34
+ tool_result = self.tools[tool_name](arg)
35
+ else:
36
+ tool_result = self.tools[tool_name]()
37
+ print(f"🔧 TOOL RESULT: {tool_result}")
38
+ tool_results.append(f"{tool_name}: {tool_result}")
39
+ else:
40
+ print(f"🔧 ERROR: Tool {tool_name} not found")
41
+ tool_results.append(f"Error: Tool {tool_name} not found")
42
+
43
+ return tool_results if tool_results else None
44
+
45
+ except Exception as e:
46
+ print(f"Error parsing tool: {e}")
47
+ return None
48
+
49
+ def get_tools_names_and_descriptions(self):
50
+ return {name: func.__doc__ for name, func in self.tools.items()}
51
+
52
+ def run(self, prompt: str):
53
+ system_prompt = f"""You are {self.name}. {self.instructions}
54
+
55
+ Available tools: {self.get_tools_names_and_descriptions()}
56
+
57
+ CRITICAL: To use a tool, respond with exactly this format:
58
+ ```tool
59
+ get_weather(Tokyo)
60
+ ```
61
+
62
+ You can use multiple tools:
63
+ ```tool
64
+ get_weather(Tokyo)
65
+ get_time()
66
+ ```
67
+
68
+ YOU MUST USE A BLOCK FOR TOOLS, or the system will not understand you are calling a tool.
69
+ CRITICAL:
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
+ """
83
+ print(f"--- System Prompt ---\n{system_prompt}\n---------------------")
84
+
85
+ messages = [
86
+ {"role": "system", "content": system_prompt},
87
+ {"role": "user", "content": prompt}
88
+ ]
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}")
102
+
103
+ tool_results = self.process_tool_calls(current_response)
104
+
105
+ if tool_results is None:
106
+ print("🏁 No tool calls detected - Agent finished!")
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 ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)
sophos_tools.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datetime
2
+
3
+ def function_tool(func):
4
+ func._is_tool = True
5
+ return func
6
+
7
+ @function_tool
8
+ def get_weather(city: str) -> str:
9
+ '''fetches weather information for a given city.'''
10
+ return f"The weather in {city} is sunny with 75°F"
11
+
12
+ @function_tool
13
+ def get_time() -> str:
14
+ '''fetches the current time.'''
15
+ return f"The current time is {datetime.datetime.now().strftime('%H:%M:%S')}"