MCPcopy Create free account
hub / github.com/FastMAS/KVCOMM / async_execute

Method async_execute

KVCOMM/graph/node.py:167–259  ·  view source on GitHub ↗

Execute a node asynchronously with optional KV cache handling modes.

(self, input:Any, mode: str = "default", **kwargs)

Source from the content-addressed store, hash-verified

165 return self.outputs
166
167 async def async_execute(self, input:Any, mode: str = "default", **kwargs):
168 """Execute a node asynchronously with optional KV cache handling modes."""
169 if mode == "default":
170 self.outputs = []
171 spatial_info:Dict[str,Any] = self.get_spatial_info()
172 temporal_info:Dict[str,Any] = self.get_temporal_info()
173 tasks = [
174 asyncio.create_task(
175 self._async_execute(input, spatial_info, temporal_info, mode=mode, **kwargs)
176 )
177 ]
178 results = await asyncio.gather(*tasks, return_exceptions=False)
179 request_uid = input.get("_request_uid") or kwargs.get("request_uid")
180 for result in results:
181 if not isinstance(result, list):
182 result = [result]
183 for item in result:
184 if isinstance(item, GenerationResult):
185 generation = item
186 else:
187 generation = GenerationResult(
188 text=str(item),
189 mode="default",
190 ttft=0.0,
191 )
192 self.outputs.append(generation.text)
193 if request_uid:
194 metrics_recorder.record_agent_output(
195 request_uid=request_uid,
196 agent_id=self.id,
197 agent_name=self.agent_name,
198 agent_role=self.role,
199 generation=generation,
200 )
201 return self.outputs
202
203 if mode == "allow_kv_reuse":
204 self.outputs = {}
205 spatial_info:Dict[str,Any] = self.get_spatial_info(input['task'])
206 temporal_info:Dict[str,Any] = self.get_temporal_info(input['task'])
207 tasks = [
208 asyncio.create_task(
209 self._async_execute(
210 input,
211 spatial_info,
212 temporal_info,
213 mode=mode,
214 **kwargs,
215 )
216 )
217 ]
218 results = await asyncio.gather(*tasks, return_exceptions=False)
219 request_uid = input.get("_request_uid") or kwargs.get("request_uid")
220 for (message, result) in results:
221 if not isinstance(result, list):
222 result = [result]
223 if message not in self.outputs:
224 self.outputs[message] = []

Callers 1

arunMethod · 0.80

Calls 7

get_spatial_infoMethod · 0.95
get_temporal_infoMethod · 0.95
_async_executeMethod · 0.95
_process_inputsMethod · 0.95
GenerationResultClass · 0.90
record_agent_outputMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected