Spaces:
Sleeping
Sleeping
Create src/macg/agents/coder.py
Browse files- src/macg/agents/coder.py +34 -0
src/macg/agents/coder.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
from macg.llm import LLMClient
|
| 3 |
+
from macg.protocol import Artifact
|
| 4 |
+
|
| 5 |
+
CODER_SYSTEM = """You are CoderAgent.
|
| 6 |
+
Write correct, minimal Python code for the requested task.
|
| 7 |
+
Rules:
|
| 8 |
+
- Output ONLY python code.
|
| 9 |
+
- Include type hints.
|
| 10 |
+
- Include a docstring for the main function/class.
|
| 11 |
+
- No extra text.
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
class CoderAgent:
|
| 15 |
+
def __init__(self, llm: LLMClient) -> None:
|
| 16 |
+
self.llm = llm
|
| 17 |
+
|
| 18 |
+
def run(self, art: Artifact) -> Artifact:
|
| 19 |
+
prompt = f"""
|
| 20 |
+
Task:
|
| 21 |
+
{art.task}
|
| 22 |
+
|
| 23 |
+
Write a Python module named {art.module_name}.py implementing the solution.
|
| 24 |
+
If you need to revise code based on review notes, use them:
|
| 25 |
+
|
| 26 |
+
Review notes (if any):
|
| 27 |
+
{art.review_notes}
|
| 28 |
+
|
| 29 |
+
Tests (if any):
|
| 30 |
+
{art.tests}
|
| 31 |
+
""".strip()
|
| 32 |
+
|
| 33 |
+
art.code = self.llm.complete(CODER_SYSTEM, prompt).strip()
|
| 34 |
+
return art
|