InfoBotKnowledge
InfoBotKnowledge adds a search_knowledge tool that answers from a corpus through a
search you supply. It hands the model one grounded block of results, and your hooks
decide which results count and how they rank. With contact=, a second tool records
the caller’s details for a human follow-up.
It installs on any AgentBase, in the main step by default, before or
after Operations; the step keeps every layer’s text and tools.
FrontDeskAgent and PersonalAssistantAgent take one as knowledge=.
Parameters
search
search(query) returns the raw results, each a dict with at least a content string
and a score. May be async. Or call use_search_service().
tool
Keyword-only, as are all the parameters below. The search tool’s name.
description
What the search tool does, as the model reads it.
result_limit
The most results handed to the model.
grounding
The line that goes with the results unless rules are added. Defaults to an instruction to answer only from the results and to say so when they don’t cover the question.
contact
contact(fields) receives the details the contact tool collects. Without it there’s
no contact tool.
contact_tool
The contact tool’s name.
contact_fields
The contact tool’s fields, in place of CONTACT_FIELDS (name, email,
and topic, with only email required).
contact_any_of
Sets of fields, any one of which is enough, such as [["email"], ["phone"]].
Defaults to all the required fields. A field not in contact_fields raises
ValueError.
wording
Replacements keyed like KNOWLEDGE_WORDING. See wording.
context
The context of the step its tools go in.
step
The step its tools go in. Created if it doesn’t exist, added to if it does.
Properties
tools
The tools it adds: the search tool, and the contact tool when there’s contact.
Methods
install
install(agent) adds the tools and the step that offers them, and returns the agent.
Raises ValueError when there’s no search backend.
use_search_service
use_search_service(url, *, user="", password="", index_name="default", count=10, timeout=10.0)
uses a SignalWire search service at url as the backend, in place
of search.
Hooks
Each hook returns the InfoBotKnowledge, so they chain.
set_exclude(fn): drop a result whenfn(result, query)is true.set_demote(fn): rank a result after the rest whenfn(result)is true.set_authority(fn):fn(result)returns a ranking tier, orNone; higher ranks first among results that aren’t demoted.set_result_context(fn):fn(result)returns a label line shown above the result’s passage, orNone.set_query_transform(fn):fn(query)rewrites the search query before it runs; the grounding still uses the caller’s words.set_fallback(fn):fn(query)is called when no result clears the cut; its text, if any, replaces the not-covered line.set_expander(fn):fn(results)transforms the kept results before they’re shown, such as widening each to its full section.add_rule(text, *, when="results"): a grounding line, added when there are results ("results"), when there are none ("empty"), or"always". Added rules replacegrounding.add_result_rule(predicate, text): a line added after the passages whenpredicate(query, results)is true.add_query_type(kind, qualifier): adds aquery_typeargument to the search tool; when the model pickskind,qualifieris appended to the search query.set_query_type_help(text): thequery_typeargument’s description.