executeBeforeLLMCallHooks fires before_llm_call just before each model call. A terminating verdict (decision="block" / continue=false exit 2) stops the run loop — see [hooks.EventBeforeLLMCall] for the contract. Hooks that just want to contribute system messages should target turn_start instead. mo
( ctx context.Context, sess *session.Session, a *agent.Agent, modelID string, iteration int, messages []chat.Message, )
| 417 | // swap the rewrite in BEFORE the model call so the LLM never sees the |
| 418 | // original content. |
| 419 | func (r *LocalRuntime) executeBeforeLLMCallHooks( |
| 420 | ctx context.Context, |
| 421 | sess *session.Session, |
| 422 | a *agent.Agent, |
| 423 | modelID string, |
| 424 | iteration int, |
| 425 | messages []chat.Message, |
| 426 | ) (stop bool, message string, rewritten []chat.Message) { |
| 427 | exec := r.hooksExec(a) |
| 428 | if exec == nil || !exec.Has(hooks.EventBeforeLLMCall) { |
| 429 | return false, "", nil |
| 430 | } |
| 431 | // Only carry the conversation snapshot when at least one hook is |
| 432 | // actually wired — dispatchHook short-circuits before then, but the |
| 433 | // JSON-encoded copy of `messages` would still be paid here. |
| 434 | result := r.dispatchHook(ctx, a, hooks.EventBeforeLLMCall, &hooks.Input{ |
| 435 | SessionID: sess.ID, |
| 436 | AgentName: a.Name(), |
| 437 | ModelID: modelID, |
| 438 | Iteration: iteration, |
| 439 | Messages: messages, |
| 440 | }, nil) |
| 441 | if result == nil { |
| 442 | return false, "", nil |
| 443 | } |
| 444 | if !result.Allowed { |
| 445 | return true, result.Message, nil |
| 446 | } |
| 447 | return false, "", result.UpdatedMessages |
| 448 | } |
| 449 | |
| 450 | // executeAfterLLMCallHooks fires after_llm_call after a successful |
| 451 | // model call, before the response is recorded into the session and |
no test coverage detected