-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent_ir_compiler.py
More file actions
57 lines (43 loc) · 1.03 KB
/
Copy pathagent_ir_compiler.py
File metadata and controls
57 lines (43 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class AgentIRCompiler:
def __init__(self, llm):
self.llm = llm
def compile(self, agent, goal, memory, input_text, role):
prompt = f"""
You are an agent compiler.
Convert reasoning into IR instructions only.
GOAL:
{goal}
ROLE:
{role}
INPUT:
{input_text}
MEMORY:
{memory}
RULES:
- Output ONLY IR instructions
- Use: LOAD, ADD, CMP, JZ, JMP, STORE, HALT
- No natural language
- Must form executable program
Example:
LOAD A 10
LOAD B 20
ADD A B C
CMP C 30
JZ success
HALT
"""
return self.parse_ir(self.llm.call(prompt))
def parse_ir(self, text):
program = []
for line in text.split("\n"):
line = line.strip()
if not line:
continue
parts = line.split()
program.append({
"opcode": parts[0],
"arg1": parts[1] if len(parts) > 1 else None,
"arg2": parts[2] if len(parts) > 2 else None,
"arg3": parts[3] if len(parts) > 3 else None,
})
return program