MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / executeLoopStep

Function executeLoopStep

packages/agent-core/src/loop/turn-step.ts:48–227  ·  view source on GitHub ↗
(deps: ExecuteLoopStepDeps)

Source from the content-addressed store, hash-verified

46}
47
48export async function executeLoopStep(deps: ExecuteLoopStepDeps): Promise<{
49 readonly usage: TokenUsage;
50 readonly stopReason: LoopStepStopReason;
51}> {
52 const {
53 turnId,
54 signal,
55 buildMessages,
56 buildMessagesStrict,
57 dispatchEvent,
58 llm,
59 tools,
60 hooks,
61 log,
62 currentStep,
63 maxRetryAttempts,
64 recordUsage,
65 } = deps;
66
67 if (hooks?.beforeStep !== undefined) {
68 const beforeStep = await hooks.beforeStep({
69 turnId,
70 stepNumber: currentStep,
71 signal,
72 llm,
73 });
74 if (beforeStep?.block === true) {
75 throw new Error(beforeStep.reason ?? `Step ${String(currentStep)} was blocked`);
76 }
77 }
78
79 signal.throwIfAborted();
80
81 const messages = await buildMessages();
82 signal.throwIfAborted();
83
84 const stepUuid = randomUUID();
85
86 const step: ToolCallStepContext = {
87 tools,
88 hooks,
89 log,
90 dispatchEvent,
91 llm,
92 signal,
93 turnId,
94 currentStep,
95 stepUuid,
96 };
97
98 await dispatchEvent({
99 type: 'step.begin',
100 uuid: stepUuid,
101 turnId,
102 step: currentStep,
103 });
104
105 const chatParams: LLMChatParams = {

Callers 1

runTurnFunction · 0.90

Calls 15

chatWithRetryFunction · 0.90
errorMessageFunction · 0.90
runToolCallBatchFunction · 0.90
dispatchEventFunction · 0.85
buildMessagesStrictFunction · 0.85
deriveStepStopReasonFunction · 0.85
logStepTimingFunction · 0.85
beforeStepMethod · 0.80
throwIfAbortedMethod · 0.80

Tested by

no test coverage detected