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

Method execute

src/agents/agent.py:270–365  ·  view source on GitHub ↗

Agentic flow of execution

(self, prompt: str, project_name: str)

Source from the content-addressed store, hash-verified

268 self.agent_state.set_agent_completed(project_name, True)
269
270 def execute(self, prompt: str, project_name: str) -> str:
271 """
272 Agentic flow of execution
273 """
274 if project_name:
275 self.project_manager.add_message_from_user(project_name, prompt)
276
277 self.agent_state.create_state(project=project_name)
278
279 plan = self.planner.execute(prompt, project_name)
280 print("\nplan :: ", plan, '\n')
281
282 planner_response = self.planner.parse_response(plan)
283 reply = planner_response["reply"]
284 focus = planner_response["focus"]
285 plans = planner_response["plans"]
286 summary = planner_response["summary"]
287
288 self.project_manager.add_message_from_devika(project_name, reply)
289 self.project_manager.add_message_from_devika(project_name, json.dumps(plans, indent=4))
290 # self.project_manager.add_message_from_devika(project_name, f"In summary: {summary}")
291
292 self.update_contextual_keywords(focus)
293 print("\ncontext_keywords :: ", self.collected_context_keywords, '\n')
294
295 internal_monologue = self.internal_monologue.execute(current_prompt=plan, project_name=project_name)
296 print("\ninternal_monologue :: ", internal_monologue, '\n')
297
298 new_state = self.agent_state.new_state()
299 new_state["internal_monologue"] = internal_monologue
300 self.agent_state.add_to_current_state(project_name, new_state)
301
302 research = self.researcher.execute(plan, self.collected_context_keywords, project_name=project_name)
303 print("\nresearch :: ", research, '\n')
304
305 queries = research["queries"]
306 queries_combined = ", ".join(queries)
307 ask_user = research["ask_user"]
308
309 if (queries and len(queries) > 0) or ask_user != "":
310 self.project_manager.add_message_from_devika(
311 project_name,
312 f"I am browsing the web to research the following queries: {queries_combined}."
313 f"\n If I need anything, I will make sure to ask you."
314 )
315 if not queries and len(queries) == 0:
316 self.project_manager.add_message_from_devika(
317 project_name,
318 "I think I can proceed without searching the web."
319 )
320
321 ask_user_prompt = "Nothing from the user."
322
323 if ask_user != "" and ask_user is not None:
324 self.project_manager.add_message_from_devika(project_name, ask_user)
325 self.agent_state.set_agent_active(project_name, False)
326 got_user_query = False
327

Callers 4

handle_messageFunction · 0.95
search_queriesMethod · 0.45
make_decisionMethod · 0.45
subsequent_executeMethod · 0.45

Calls 14

search_queriesMethod · 0.95
add_message_from_userMethod · 0.80
create_stateMethod · 0.80
parse_responseMethod · 0.80
new_stateMethod · 0.80
add_to_current_stateMethod · 0.80
set_agent_activeMethod · 0.80
infoMethod · 0.80

Tested by

no test coverage detected