MCPcopy Create free account
hub / github.com/Xyntopia/taskyon / generateFollowUpTasksFromResult

Function generateFollowUpTasksFromResult

src/modules/taskWorker.ts:253–314  ·  view source on GitHub ↗
(
  finishedTask: LLMTask,
  chatState: ChatStateType
)

Source from the content-addressed store, hash-verified

251}
252
253async function generateFollowUpTasksFromResult(
254 finishedTask: LLMTask,
255 chatState: ChatStateType
256) {
257 console.log('generate follow up task');
258 if (finishedTask.result) {
259 const taskDraftList: partialTaskDraft[] = [];
260 let execute = false;
261 if (finishedTask.result.type === 'ChatAnswer') {
262 const choice = finishedTask.result.chatResponse?.choices[0];
263 if (choice) {
264 taskDraftList.push({
265 state: 'Completed',
266 role: choice.message.role,
267 content: choice.message.content,
268 });
269 }
270 } else if (finishedTask.result.type === 'AssistantAnswer') {
271 const newTaskDraftList = createNewAssistantResponseTask(finishedTask);
272 for (const td of newTaskDraftList) {
273 taskDraftList.push({
274 state: 'Completed',
275 ...td,
276 });
277 }
278 } else if (finishedTask.result.type === 'ToolChatResult') {
279 const choice = finishedTask.result.chatResponse?.choices[0];
280 let taskDraft = undefined;
281 ({ taskDraft, execute } = await parseChatResponse(
282 choice?.message.content || '',
283 choice?.message.role
284 ));
285 if (taskDraft) {
286 taskDraftList.push(taskDraft);
287 }
288 } else if (finishedTask.result.type === 'ToolCall') {
289 const choice = finishedTask.result.chatResponse?.choices[0];
290 if (choice) {
291 const functionCall = extractOpenAIFunctions(choice);
292 if (functionCall) {
293 taskDraftList.push({
294 role: 'function',
295 content: null,
296 context: { function: functionCall[0] },
297 });
298 execute = true;
299 }
300 }
301 }
302 let parentTask = finishedTask;
303 const childCosts = {
304 promptTokens: finishedTask.debugging.resultTokens,
305 taskTokens: finishedTask.debugging.taskTokens,
306 taskCosts: finishedTask.debugging.taskCosts,
307 };
308 for (const taskDraft of taskDraftList) {
309 taskDraft.debugging = { ...taskDraft.debugging, ...childCosts };
310 const newId = addTask2Tree(taskDraft, parentTask, chatState, execute);

Callers 1

taskWorkerFunction · 0.85

Calls 5

addTask2TreeFunction · 0.90
parseChatResponseFunction · 0.85
extractOpenAIFunctionsFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected