MCPcopy
hub / github.com/stitionai/devika / Planner

Class Planner

src/agents/planner/planner.py:7–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5PROMPT = open("src/agents/planner/prompt.jinja2").read().strip()
6
7class Planner:
8 def __init__(self, base_model: str):
9 self.llm = LLM(model_id=base_model)
10
11 def render(self, prompt: str) -> str:
12 env = Environment(loader=BaseLoader())
13 template = env.from_string(PROMPT)
14 return template.render(prompt=prompt)
15
16 def validate_response(self, response: str) -> bool:
17 return True
18
19 def parse_response(self, response: str):
20 result = {
21 "project": "",
22 "reply": "",
23 "focus": "",
24 "plans": {},
25 "summary": ""
26 }
27
28 current_section = None
29 current_step = None
30
31 for line in response.split("\n"):
32 line = line.strip()
33
34 if line.startswith("Project Name:"):
35 current_section = "project"
36 result["project"] = line.split(":", 1)[1].strip()
37 elif line.startswith("Your Reply to the Human Prompter:"):
38 current_section = "reply"
39 result["reply"] = line.split(":", 1)[1].strip()
40 elif line.startswith("Current Focus:"):
41 current_section = "focus"
42 result["focus"] = line.split(":", 1)[1].strip()
43 elif line.startswith("Plan:"):
44 current_section = "plans"
45 elif line.startswith("Summary:"):
46 current_section = "summary"
47 result["summary"] = line.split(":", 1)[1].strip()
48 elif current_section == "reply":
49 result["reply"] += " " + line
50 elif current_section == "focus":
51 result["focus"] += " " + line
52 elif current_section == "plans":
53 if line.startswith("- [ ] Step"):
54 current_step = line.split(":")[0].strip().split(" ")[-1]
55 result["plans"][int(current_step)] = line.split(":", 1)[1].strip()
56 elif current_step:
57 result["plans"][int(current_step)] += " " + line
58 elif current_section == "summary":
59 result["summary"] += " " + line.replace("```", "")
60
61 result["project"] = result["project"].strip()
62 result["reply"] = result["reply"].strip()
63 result["focus"] = result["focus"].strip()
64 result["summary"] = result["summary"].strip()

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected