MCPcopy Create free account
hub / github.com/Ishabdullah/Codey-v2 / _execute_task

Method _execute_task

core/task_executor.py:74–131  ·  view source on GitHub ↗

Execute a single task using the full run_agent() pipeline. Installs a daemon shell guard and disables interactive confirmations for the duration of the call, then unconditionally restores the previous AGENT_CONFIG values so interactive sessions are unaffected.

(self, prompt: str)

Source from the content-addressed store, hash-verified

72 # ------------------------------------------------------------------
73
74 async def _execute_task(self, prompt: str) -> str:
75 """
76 Execute a single task using the full run_agent() pipeline.
77
78 Installs a daemon shell guard and disables interactive confirmations
79 for the duration of the call, then unconditionally restores the
80 previous AGENT_CONFIG values so interactive sessions are unaffected.
81
82 The prompt should already be the enriched step string produced by
83 daemon._handle_command (includes original task + step number).
84 """
85 start_inference()
86 try:
87 from core.agent import run_agent
88 from prompts.layered_prompt import invalidate_prompt_cache
89
90 # Fresh file context for every step — previous steps may have
91 # written files that must appear in this step's system prompt.
92 invalidate_prompt_cache()
93
94 # Clear working memory between daemon steps — previous step's
95 # files and turn counter bleed into this step causing stale
96 # context and premature LRU eviction of files we haven't seen yet.
97 from core.memory import memory as _mem
98 _mem.clear()
99
100 # Save and override AGENT_CONFIG for daemon execution.
101 _saved = {
102 "_shell_fn": AGENT_CONFIG.get("_shell_fn"),
103 "confirm_shell": AGENT_CONFIG.get("confirm_shell"),
104 "confirm_write": AGENT_CONFIG.get("confirm_write"),
105 }
106 AGENT_CONFIG["_shell_fn"] = self._daemon_shell
107 AGENT_CONFIG["confirm_shell"] = False # guard is in _daemon_shell
108 AGENT_CONFIG["confirm_write"] = False # daemon writes without prompting
109
110 try:
111 loop = asyncio.get_event_loop()
112 response, _ = await loop.run_in_executor(
113 None,
114 lambda: run_agent(
115 prompt,
116 history=[],
117 yolo=True,
118 no_plan=True, # each daemon step is already planned
119 _in_subtask=True, # suppress git prompts; scale max_steps
120 ),
121 )
122 return response
123 finally:
124 AGENT_CONFIG.update(_saved)
125
126 except Exception as e:
127 import traceback
128 error(f"Task execution error: {e}\n{traceback.format_exc()}")
129 raise # re-raise original exception; already logged above
130 finally:
131 end_inference()

Callers 1

Calls 7

start_inferenceFunction · 0.90
invalidate_prompt_cacheFunction · 0.90
run_agentFunction · 0.90
errorFunction · 0.90
end_inferenceFunction · 0.90
clearMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected