Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Hooks: Steer Your Agent Before the LLM Call

Описание и применение

Использование хуков before_llm_call в Dapr Agents позволяет надежно добавлять живой контекст, проверять токены и удалять PII, сохраняя состояние при сбоях.

Задача

Integrating dynamic context and safety checks into an LLM agent loop without losing state on failures.

Результат

Using before_llm_call hooks in Dapr Agents enables reliable injection of live web context, token‑budget enforcement, and PII redaction while maintaining durable state across failures.

Рабочий процесс

  • Define hook function (e.g., add_live_context) that appends fresh data to context.
  • Instantiate DurableAgent with name and hooks mapping before_llm_call to the hook.
  • Hook executes before each LLM call, ensuring fresh context or validation.
  • If crash occurs after hook but before LLM call, durable workflow replays hook, preserving context.
  • Ensure hook is replay‑safe and declare determinism to control replay behavior.

Доказательства

Dapr Agents lets you register hooks around the agent loop where the before_llm_call being the one I use the most.

Источник

Everything the hook does, lives inside the durable workflow, so a crash after the hook but before the call replays cleanly with no lost context.

Источник

For live context, this is great and probably what we want. For validating user tokens, this is equally great - otherwise we'd just roll an approval on a potentially expired token!

Источник

  • Дата записи: 2026-10-09T08:55:56.960Z