applyCacheDefault appends the cache_response stop hook to cfg when a has a configured response cache, mirroring the role of [builtins.ApplyAgentDefaults] for the runtime-private cache builtin. The helper accepts (and may return) a nil cfg so callers can chain it after [builtins.ApplyAgentDefaults]
(cfg *hooks.Config, a *agent.Agent)
| 27 | // The helper accepts (and may return) a nil cfg so callers can chain |
| 28 | // it after [builtins.ApplyAgentDefaults] without an extra branch. |
| 29 | func applyCacheDefault(cfg *hooks.Config, a *agent.Agent) *hooks.Config { |
| 30 | if a.Cache() == nil { |
| 31 | return cfg |
| 32 | } |
| 33 | if cfg == nil { |
| 34 | cfg = &hooks.Config{} |
| 35 | } |
| 36 | cfg.Stop = append(cfg.Stop, hooks.Hook{ |
| 37 | Type: hooks.HookTypeBuiltin, |
| 38 | Command: BuiltinCacheResponse, |
| 39 | }) |
| 40 | return cfg |
| 41 | } |
| 42 | |
| 43 | // tryReplayCachedResponse looks up the latest user message in the agent's |
| 44 | // response cache. On a hit it replays the cached answer as the assistant |
no test coverage detected