Skip to main content
Use the Learning Machine to save diagnosed query corrections and retrieve them for related requests.
Passing 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

  1. The agent writes SQL and runs it.
  2. It errors, or returns a number a human flags as wrong.
  3. The agent diagnoses the cause (wrong column, stale table, a join that double-counts).
  4. The fix is saved according to the configured learning mode.
  5. On the next similar request, the agent calls search_learnings before generating SQL.
In 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.

Audit what it learned

Inspect the Learned Knowledge store for saved corrections and the Decision Log for recorded query-shape decisions.

Next steps

Developer Resources