Skip to content

feat: allow to adjust knowledgebase usage#406

Merged
mudler merged 1 commit intomainfrom
feat/kb_as_tools
Feb 6, 2026
Merged

feat: allow to adjust knowledgebase usage#406
mudler merged 1 commit intomainfrom
feat/kb_as_tools

Conversation

@mudler
Copy link
Owner

@mudler mudler commented Feb 6, 2026

This allows to configure specifically how the Knowledge base should be accessible to the agent.

  • Auto search: When enabled, every message will trigger a search to the knowledge base. This is useful mostly if you mean to give immediate context to the agent. Particularly suited for search agents.
  • As tools: it will inject search and add tools to the knowledge base so the agent can handle these autonomously.

This allows to configure specifically how the Knowledge base should be
accessible to the agent.

- Auto search: When enabled, every message will trigger a search to the
  knowledge base. This is useful mostly if you mean to give immediate
  context to the agent. Particularly suited for search agents.
- As tools: it will inject search and add tools to the knowledge base so
  the agent can handle these autonomously.

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Copilot AI review requested due to automatic review settings February 6, 2026 20:32
@mudler mudler merged commit 1d57406 into main Feb 6, 2026
6 checks passed
@mudler mudler deleted the feat/kb_as_tools branch February 6, 2026 20:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds configuration knobs to control how an agent uses the Knowledge Base (KB): either automatically searching on each user message, and/or exposing KB operations as callable tools.

Changes:

  • Added kb_auto_search and kb_as_tools to AgentConfig and the config metadata schema.
  • Introduced an agent option (WithKBAutoSearch) and gated knowledgeBaseLookup on it.
  • Added KB wrapper actions (search_knowledge_base, add_to_knowledge_base) intended for tool injection when kb_as_tools is enabled.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
core/state/pool.go Wires new KB config flags into agent startup; attempts to inject KB tools when enabled.
core/state/config.go Extends agent config struct + UI metadata with KB auto-search/tools toggles.
core/agent/options.go Adds kbAutoSearch option storage + WithKBAutoSearch option.
core/agent/knowledgebase.go Skips KB recall when auto-search disabled; adds KB tool action implementations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

kbResults = 5 // Default
}
searchAction, addAction := NewKBWrapperActions(ragClient, kbResults)
actions = append(actions, searchAction, addAction)
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KB wrapper actions are appended to the local actions slice after WithActions(actions...) has already been added to opts (and opts is never updated). Because WithActions captures the slice header at that moment, the later append(actions, ...) will not reliably propagate into the agent's configured actions, so kb_as_tools may have no effect. Move the KB action injection before building opts/calling WithActions, or re-apply WithActions after mutating actions (or build a finalActions slice and pass that once).

Suggested change
actions = append(actions, searchAction, addAction)
actions = append(actions, searchAction, addAction)
// Re-apply actions option so the updated slice (with KB tools) is used
opts = append(opts, WithActions(actions...))

Copilot uses AI. Check for mistakes.
Comment on lines +568 to +576
// Set KB auto search option (defaults to true for backward compatibility)
// For backward compatibility: if both new KB fields are false (zero values),
// assume this is an old config and default KBAutoSearch to true
kbAutoSearch := config.KBAutoSearch
if !config.KBAutoSearch && !config.KBAsTools {
// Both new fields are false, likely an old config - default to true for backward compatibility
kbAutoSearch = true
}
opts = append(opts, WithKBAutoSearch(kbAutoSearch))
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backward-compatibility fallback (if !config.KBAutoSearch && !config.KBAsTools { kbAutoSearch = true }) makes it impossible to explicitly configure both kb_auto_search=false and kb_as_tools=false (it will always be forced back to true). If disabling KB access modes is a valid configuration, consider detecting field presence during JSON unmarshal (e.g., use *bool or json.RawMessage presence checks in AgentConfig.UnmarshalJSON) so you can default to true only when the field is absent, not when it is explicitly set to false.

Copilot uses AI. Check for mistakes.
jobFilters types.JobFilters
enableHUD, standaloneJob, showCharacter, enableKB, enableSummaryMemory, enableLongTermMemory bool
stripThinkingTags bool
kbAutoSearch bool
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new kbAutoSearch field alignment looks off (extra spacing before bool). Running gofmt on this file will normalize formatting and avoid noisy diffs later.

Suggested change
kbAutoSearch bool
kbAutoSearch bool

Copilot uses AI. Check for mistakes.
Comment on lines +24 to +27
if !a.options.kbAutoSearch {
xlog.Debug("[Knowledge Base Lookup] Auto search disabled, skipping", "agent", a.Character.Name)
return conv
}
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kbAutoSearch changes the observable behavior of the agent (KB recall is now skipped when disabled), but there are no tests covering this new branch. Since core/agent already has a test suite, please add unit tests asserting that knowledgeBaseLookup does not call into ragdb.Search when kbAutoSearch is false (and does when true).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant