Преглед изворни кода

docs(core): state loop initiator precondition

Tianyi Cui пре 2 месеци
родитељ
комит
7a9c2ef473
2 измењених фајлова са 7 додато и 2 уклоњено
  1. 4 1
      packages/core/agent-loop/src/loop.ts
  2. 3 1
      packages/core/agent-loop/src/tool-calls.ts

+ 4 - 1
packages/core/agent-loop/src/loop.ts

@@ -94,11 +94,14 @@ export interface LoopHandle {
 
 /**
  * Drive queued batches as durable turns until disposal. Plugin failures end the
- * current turn without terminating the driver.
+ * current turn without terminating the driver. The caller establishes the
+ * `ctx.agents.withInitiator()` boundary before entry; package-private helpers
+ * recover that exact Agent from the inherited store.
  * @param ctx - the plugin context the loop reaches its initiating Agent,
  * events (agent/…, session/flush), and services (systemPrompt, llm, tools)
  * through.
  * @param handle - the bridge to the agent's mutable state: status/abort setters plus the disposal and cancel-marker reads.
+ * @throws when no initiating Agent is active.
  */
 export async function runLoop(ctx: Context, handle: LoopHandle): Promise<void> {
   const agent = ctx.agents.requireInitiator()

+ 3 - 1
packages/core/agent-loop/src/tool-calls.ts

@@ -32,8 +32,10 @@ interface Slot {
  * Schedule one assistant step's tool calls by their live concurrency mode.
  * Started calls receive ordered results. Abort drains them and rethrows after
  * accepting their context into the batch FIFO owned by the caller.
+ * The committed step's AgentLoop driver boundary supplies the initiating Agent
+ * that becomes each explicit {@link ToolExecutionInput.agent}.
  *
- * @param ctx - loop context that owns the tool registry.
+ * @param ctx - loop context that owns the tool registry and carries the initiating Agent.
  * @param turn - current turn number.
  * @param step - current step number.
  * @param toolCalls - assistant calls in model order.