Conversation
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>
There was a problem hiding this comment.
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_searchandkb_as_toolstoAgentConfigand the config metadata schema. - Introduced an agent option (
WithKBAutoSearch) and gatedknowledgeBaseLookupon it. - Added KB wrapper actions (
search_knowledge_base,add_to_knowledge_base) intended for tool injection whenkb_as_toolsis 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) |
There was a problem hiding this comment.
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).
| 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...)) |
| // 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)) |
There was a problem hiding this comment.
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.
| jobFilters types.JobFilters | ||
| enableHUD, standaloneJob, showCharacter, enableKB, enableSummaryMemory, enableLongTermMemory bool | ||
| stripThinkingTags bool | ||
| kbAutoSearch bool |
There was a problem hiding this comment.
The new kbAutoSearch field alignment looks off (extra spacing before bool). Running gofmt on this file will normalize formatting and avoid noisy diffs later.
| kbAutoSearch bool | |
| kbAutoSearch bool |
| if !a.options.kbAutoSearch { | ||
| xlog.Debug("[Knowledge Base Lookup] Auto search disabled, skipping", "agent", a.Character.Name) | ||
| return conv | ||
| } |
There was a problem hiding this comment.
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).
This allows to configure specifically how the Knowledge base should be accessible to the agent.