madDegen commited on
Commit
69fc3dd
·
verified ·
1 Parent(s): 216bfa1

consolidate: HQ TandemCore — Gemma4 reasons, Qwen3.5 implements

Browse files
Files changed (1) hide show
  1. hq/tandem_core.py +43 -0
hq/tandem_core.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Agent Q3 [HQ] — TandemCore
3
+ Gemma4-E4B (Reasoner) → Qwen3.5-4B (Coder) chained pipeline.
4
+ Step 1: Reasoner produces a structured plan.
5
+ Step 2: Coder implements the plan.
6
+ """
7
+ import httpx, os
8
+
9
+ OLLAMA_URL = os.getenv("OLLAMA_URL", "http://localhost:11434/v1/chat/completions")
10
+ REASONER = os.getenv("REASONER_MODEL", "gemma4:e4b-instruct-q4_K_M")
11
+ CODER = os.getenv("CODER_MODEL", "qwen3.5:4b-instruct-q4_K_M")
12
+
13
+ REASON_SYSTEM = (
14
+ "You are a senior architect and researcher. Given the user request, "
15
+ "produce a concise, structured plan (steps, constraints, edge cases) "
16
+ "that a coder can implement directly. Be precise. No code yet."
17
+ )
18
+ CODE_SYSTEM = (
19
+ "You are an expert software engineer. Implement the plan provided exactly. "
20
+ "Output production-quality code with inline comments. No explanation outside code blocks."
21
+ )
22
+
23
+ class TandemCore:
24
+ async def _call(self, model: str, system: str, messages: list) -> str:
25
+ payload = {
26
+ "model": model,
27
+ "messages": [{"role": "system", "content": system}] + messages,
28
+ }
29
+ async with httpx.AsyncClient(timeout=120) as client:
30
+ r = await client.post(OLLAMA_URL, json=payload)
31
+ r.raise_for_status()
32
+ return r.json()["choices"][0]["message"]["content"]
33
+
34
+ async def run(self, messages: list) -> dict:
35
+ plan = await self._call(REASONER, REASON_SYSTEM, messages)
36
+ plan_msg = {"role": "assistant", "content": f"[PLAN]\n{plan}"}
37
+ impl = await self._call(CODER, CODE_SYSTEM, messages + [plan_msg])
38
+ return {
39
+ "tandem": True,
40
+ "plan": plan,
41
+ "implementation": impl,
42
+ "choices": [{"message": {"role": "assistant", "content": impl}}]
43
+ }