MCPcopy
hub / github.com/cft0808/edict / cmd_delegate_result

Function cmd_delegate_result

scripts/kanban_update.py:894–938  ·  view source on GitHub ↗

提交委派子任务结果,回写到父任务的 task_memory。

(sub_task_id, result_json)

Source from the content-addressed store, hash-verified

892
893
894def cmd_delegate_result(sub_task_id, result_json):
895 """提交委派子任务结果,回写到父任务的 task_memory。"""
896 tasks = atomic_json_read(TASKS_FILE, [])
897 sub = next((t for t in tasks if t.get('id') == sub_task_id), None)
898 if not sub:
899 log.error(f'子任务 {sub_task_id} 不存在')
900 return
901 parent_id = sub.get('parent_task', '')
902 delegation = sub.get('delegation', {})
903 from_agent = delegation.get('from', '')
904 to_agent = delegation.get('to', '')
905
906 # 标记子任务完成
907 def modifier(tasks):
908 t = find_task(tasks, sub_task_id)
909 if t:
910 t['state'] = 'Done'
911 t['now'] = f'委派结果已提交'
912 t['updatedAt'] = now_iso()
913 t['delegation_result'] = result_json
914 return tasks
915 atomic_json_update(TASKS_FILE, modifier, [])
916
917 # 写入父任务的 task_memory
918 if parent_id:
919 TASK_MEMORY_DIR.mkdir(parents=True, exist_ok=True)
920 memo_file = TASK_MEMORY_DIR / f'{parent_id}.json'
921 chain_entry = {
922 'agent': to_agent,
923 'phase': 'delegation_result',
924 'key_decisions': [f'委派结果: {result_json[:200]}'],
925 'warnings': [],
926 'at': now_iso(),
927 'delegation_from': sub_task_id,
928 }
929 def memo_modifier(data):
930 if not data:
931 data = {'task_id': parent_id, 'context_chain': []}
932 data.setdefault('context_chain', []).append(chain_entry)
933 return data
934 atomic_json_update(memo_file, memo_modifier, {})
935
936 _trigger_refresh()
937 log.info(f'✅ 委派结果 {sub_task_id} → 父任务 {parent_id}')
938 _append_audit(parent_id, to_agent, 'delegate_result', sub_task_id, None, result_json[:100])
939
940_CMD_MIN_ARGS = {
941 'create': 6, 'state': 3, 'flow': 5, 'done': 2, 'block': 3, 'confirm': 3,

Callers 1

kanban_update.pyFile · 0.85

Calls 5

atomic_json_readFunction · 0.90
atomic_json_updateFunction · 0.90
now_isoFunction · 0.90
_append_auditFunction · 0.85
_trigger_refreshFunction · 0.70

Tested by

no test coverage detected