knowledge to LearningMachine enables the Learned Knowledge store. It uses AGENTIC mode by default, so the model calls save_learning when it finds a reusable correction. decision_log=True also selects AGENTIC mode and adds the log_decision and search_decisions tools. A decision is saved only when the model calls log_decision.
The loop
- The agent writes SQL and runs it.
- It errors, or returns a number a human flags as wrong.
- The agent diagnoses the cause (wrong column, stale table, a join that double-counts).
- The fix is saved according to the configured learning mode.
- On the next similar request, the agent calls
search_learningsbefore generating SQL.
AGENTIC mode, retrieval occurs when the model calls search_learnings. The instruction in this example makes that search part of the query workflow.
Choose how learning happens
Each store has its own mode. Choose explicit tool calls, background extraction, or human approval based on the correction.ALWAYS schedules background extraction after run messages are prepared and before the main model call. With the default add_history_to_context=False, this example supplies the current user message. Set add_history_to_context=True to include prior user and assistant messages in later snapshots. The extractor ignores system messages, tool calls, and tool results. It may decide there is nothing worth saving.